@ -21,6 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorage ;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction ;
import java.nio.file.Path ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.List ;
@ -32,11 +33,12 @@ import java.util.stream.Stream;
import org.apache.commons.lang3.tuple.Pair ;
import org.apache.tuweni.bytes.Bytes ;
import org.junit.Ignore ;
import org.junit.Test ;
import org.assertj.core.api.Assertions ;
import org.junit.jupiter.api.Disabled ;
import org.junit.jupiter.api.Test ;
/** The Abstract key value storage test. */
@Ignore
@Disabled
public abstract class AbstractKeyValueStorageTest {
/ * *
@ -352,12 +354,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
* /
@Test ( expected = IllegalStateException . class )
@Test
public void transactionPutAfterCommit ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . commit ( ) ;
tx . put ( bytesOf ( 1 ) , bytesOf ( 1 ) ) ;
Assertions . assertThatThrownBy (
( ) - > {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . commit ( ) ;
tx . put ( bytesOf ( 1 ) , bytesOf ( 1 ) ) ;
} )
. isInstanceOf ( IllegalStateException . class ) ;
}
/ * *
@ -365,12 +371,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
* /
@Test ( expected = IllegalStateException . class )
@Test
public void transactionRemoveAfterCommit ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . commit ( ) ;
tx . remove ( bytesOf ( 1 ) ) ;
Assertions . assertThatThrownBy (
( ) - > {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . commit ( ) ;
tx . remove ( bytesOf ( 1 ) ) ;
} )
. isInstanceOf ( IllegalStateException . class ) ;
}
/ * *
@ -378,12 +388,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
* /
@Test ( expected = IllegalStateException . class )
@Test
public void transactionPutAfterRollback ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . rollback ( ) ;
tx . put ( bytesOf ( 1 ) , bytesOf ( 1 ) ) ;
Assertions . assertThatThrownBy (
( ) - > {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . rollback ( ) ;
tx . put ( bytesOf ( 1 ) , bytesOf ( 1 ) ) ;
} )
. isInstanceOf ( IllegalStateException . class ) ;
}
/ * *
@ -391,12 +405,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
* /
@Test ( expected = IllegalStateException . class )
@Test
public void transactionRemoveAfterRollback ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . rollback ( ) ;
tx . remove ( bytesOf ( 1 ) ) ;
Assertions . assertThatThrownBy (
( ) - > {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . rollback ( ) ;
tx . remove ( bytesOf ( 1 ) ) ;
} )
. isInstanceOf ( IllegalStateException . class ) ;
}
/ * *
@ -404,12 +422,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
* /
@Test ( expected = IllegalStateException . class )
@Test
public void transactionCommitAfterRollback ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . rollback ( ) ;
tx . commit ( ) ;
Assertions . assertThatThrownBy (
( ) - > {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . rollback ( ) ;
tx . commit ( ) ;
} )
. isInstanceOf ( IllegalStateException . class ) ;
}
/ * *
@ -417,12 +439,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
* /
@Test ( expected = IllegalStateException . class )
@Test
public void transactionCommitTwice ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . commit ( ) ;
tx . commit ( ) ;
Assertions . assertThatThrownBy (
( ) - > {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . commit ( ) ;
tx . commit ( ) ;
} )
. isInstanceOf ( IllegalStateException . class ) ;
}
/ * *
@ -430,12 +456,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
* /
@Test ( expected = IllegalStateException . class )
@Test
public void transactionRollbackAfterCommit ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . commit ( ) ;
tx . rollback ( ) ;
Assertions . assertThatThrownBy (
( ) - > {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . commit ( ) ;
tx . rollback ( ) ;
} )
. isInstanceOf ( IllegalStateException . class ) ;
}
/ * *
@ -443,12 +473,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
* /
@Test ( expected = IllegalStateException . class )
@Test
public void transactionRollbackTwice ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . rollback ( ) ;
tx . rollback ( ) ;
Assertions . assertThatThrownBy (
( ) - > {
final KeyValueStorage store = createStore ( ) ;
final KeyValueStorageTransaction tx = store . startTransaction ( ) ;
tx . rollback ( ) ;
tx . rollback ( ) ;
} )
. isInstanceOf ( IllegalStateException . class ) ;
}
/ * *
@ -547,4 +581,15 @@ public abstract class AbstractKeyValueStorageTest {
protected byte [ ] bytesOf ( final int . . . bytes ) {
return Bytes . of ( bytes ) . toArrayUnsafe ( ) ;
}
/ * *
* Create a sub folder from the given path , that will not conflict with other folders .
*
* @param folder the folder in which to create the sub folder
* @return the path representing the sub folder
* @throws Exception if the folder cannot be created
* /
protected Path getTempSubFolder ( final Path folder ) throws Exception {
return java . nio . file . Files . createTempDirectory ( folder , null ) ;
}
}