@ -42,7 +42,9 @@ public abstract class AbstractKeyValueStorageTest {
final KeyValueStorage store1 = createStore ( ) ;
final KeyValueStorage store2 = createStore ( ) ;
store1 . put ( BytesValue . fromHexString ( "0001" ) , BytesValue . fromHexString ( "0FFF" ) ) ;
Transaction tx = store1 . startTransaction ( ) ;
tx . put ( BytesValue . fromHexString ( "0001" ) , BytesValue . fromHexString ( "0FFF" ) ) ;
tx . commit ( ) ;
final Optional < BytesValue > result = store2 . get ( BytesValue . fromHexString ( "0001" ) ) ;
assertEquals ( Optional . empty ( ) , result ) ;
}
@ -51,11 +53,15 @@ public abstract class AbstractKeyValueStorageTest {
public void put ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
store . put ( BytesValue . fromHexString ( "0F" ) , BytesValue . fromHexString ( "0ABC" ) ) ;
Transaction tx = store . startTransaction ( ) ;
tx . put ( BytesValue . fromHexString ( "0F" ) , BytesValue . fromHexString ( "0ABC" ) ) ;
tx . commit ( ) ;
assertEquals (
Optional . of ( BytesValue . fromHexString ( "0ABC" ) ) , store . get ( BytesValue . fromHexString ( "0F" ) ) ) ;
store . put ( BytesValue . fromHexString ( "0F" ) , BytesValue . fromHexString ( "0DEF" ) ) ;
tx = store . startTransaction ( ) ;
tx . put ( BytesValue . fromHexString ( "0F" ) , BytesValue . fromHexString ( "0DEF" ) ) ;
tx . commit ( ) ;
assertEquals (
Optional . of ( BytesValue . fromHexString ( "0DEF" ) ) , store . get ( BytesValue . fromHexString ( "0F" ) ) ) ;
}
@ -63,15 +69,31 @@ public abstract class AbstractKeyValueStorageTest {
@Test
public void removeExisting ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
store . put ( BytesValue . fromHexString ( "0F" ) , BytesValue . fromHexString ( "0ABC" ) ) ;
store . remove ( BytesValue . fromHexString ( "0F" ) ) ;
Transaction tx = store . startTransaction ( ) ;
tx . put ( BytesValue . fromHexString ( "0F" ) , BytesValue . fromHexString ( "0ABC" ) ) ;
tx . commit ( ) ;
tx = store . startTransaction ( ) ;
tx . remove ( BytesValue . fromHexString ( "0F" ) ) ;
tx . commit ( ) ;
assertEquals ( Optional . empty ( ) , store . get ( BytesValue . fromHexString ( "0F" ) ) ) ;
}
@Test
public void removeExistingSameTransaction ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
Transaction tx = store . startTransaction ( ) ;
tx . put ( BytesValue . fromHexString ( "0F" ) , BytesValue . fromHexString ( "0ABC" ) ) ;
tx . remove ( BytesValue . fromHexString ( "0F" ) ) ;
tx . commit ( ) ;
assertEquals ( Optional . empty ( ) , store . get ( BytesValue . fromHexString ( "0F" ) ) ) ;
}
@Test
public void removeNonExistent ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
store . remove ( BytesValue . fromHexString ( "0F" ) ) ;
Transaction tx = store . startTransaction ( ) ;
tx . remove ( BytesValue . fromHexString ( "0F" ) ) ;
tx . commit ( ) ;
assertEquals ( Optional . empty ( ) , store . get ( BytesValue . fromHexString ( "0F" ) ) ) ;
}
@ -83,9 +105,11 @@ public abstract class AbstractKeyValueStorageTest {
Arrays . asList (
Entry . create ( BytesValue . fromHexString ( "01" ) , BytesValue . fromHexString ( "0ABC" ) ) ,
Entry . create ( BytesValue . fromHexString ( "02" ) , BytesValue . fromHexString ( "0DEF" ) ) ) ;
Transaction tx = store . startTransaction ( ) ;
for ( final Entry testEntry : testEntries ) {
store . put ( testEntry . getKey ( ) , testEntry . getValue ( ) ) ;
tx . put ( testEntry . getKey ( ) , testEntry . getValue ( ) ) ;
}
tx . commit ( ) ;
final List < Entry > actualEntries = store . entries ( ) . collect ( Collectors . toList ( ) ) ;
testEntries . sort ( Comparator . comparing ( Entry : : getKey ) ) ;
@ -106,7 +130,9 @@ public abstract class AbstractKeyValueStorageTest {
( ) - > {
try {
for ( int i = 0 ; i < keyCount ; i + + ) {
store . put ( BytesValues . toMinimalBytes ( i ) , value ) ;
Transaction tx = store . startTransaction ( ) ;
tx . put ( BytesValues . toMinimalBytes ( i ) , value ) ;
tx . commit ( ) ;
}
} finally {
finishedLatch . countDown ( ) ;
@ -134,12 +160,14 @@ public abstract class AbstractKeyValueStorageTest {
public void transactionCommit ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
// Add some values
store . put ( BytesValue . of ( 1 ) , BytesValue . of ( 1 ) ) ;
store . put ( BytesValue . of ( 2 ) , BytesValue . of ( 2 ) ) ;
store . put ( BytesValue . of ( 3 ) , BytesValue . of ( 3 ) ) ;
Transaction tx = store . startTransaction ( ) ;
tx . put ( BytesValue . of ( 1 ) , BytesValue . of ( 1 ) ) ;
tx . put ( BytesValue . of ( 2 ) , BytesValue . of ( 2 ) ) ;
tx . put ( BytesValue . of ( 3 ) , BytesValue . of ( 3 ) ) ;
tx . commit ( ) ;
// Start transaction that adds, modifies, and removes some values
final Transaction tx = store . getS tartTransaction( ) ;
tx = store . s tartTransaction( ) ;
tx . put ( BytesValue . of ( 2 ) , BytesValue . of ( 3 ) ) ;
tx . put ( BytesValue . of ( 2 ) , BytesValue . of ( 4 ) ) ;
tx . remove ( BytesValue . of ( 3 ) ) ;
@ -164,12 +192,14 @@ public abstract class AbstractKeyValueStorageTest {
public void transactionRollback ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
// Add some values
store . put ( BytesValue . of ( 1 ) , BytesValue . of ( 1 ) ) ;
store . put ( BytesValue . of ( 2 ) , BytesValue . of ( 2 ) ) ;
store . put ( BytesValue . of ( 3 ) , BytesValue . of ( 3 ) ) ;
Transaction tx = store . startTransaction ( ) ;
tx . put ( BytesValue . of ( 1 ) , BytesValue . of ( 1 ) ) ;
tx . put ( BytesValue . of ( 2 ) , BytesValue . of ( 2 ) ) ;
tx . put ( BytesValue . of ( 3 ) , BytesValue . of ( 3 ) ) ;
tx . commit ( ) ;
// Start transaction that adds, modifies, and removes some values
final Transaction tx = store . getS tartTransaction( ) ;
tx = store . s tartTransaction( ) ;
tx . put ( BytesValue . of ( 2 ) , BytesValue . of ( 3 ) ) ;
tx . put ( BytesValue . of ( 2 ) , BytesValue . of ( 4 ) ) ;
tx . remove ( BytesValue . of ( 3 ) ) ;
@ -193,21 +223,21 @@ public abstract class AbstractKeyValueStorageTest {
@Test
public void transactionCommitEmpty ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final Transaction tx = store . getS tartTransaction( ) ;
final Transaction tx = store . s tartTransaction( ) ;
tx . commit ( ) ;
}
@Test
public void transactionRollbackEmpty ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final Transaction tx = store . getS tartTransaction( ) ;
final Transaction tx = store . s tartTransaction( ) ;
tx . rollback ( ) ;
}
@Test ( expected = IllegalStateException . class )
public void transactionPutAfterCommit ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final Transaction tx = store . getS tartTransaction( ) ;
final Transaction tx = store . s tartTransaction( ) ;
tx . commit ( ) ;
tx . put ( BytesValue . of ( 1 ) , BytesValue . of ( 1 ) ) ;
}
@ -215,7 +245,7 @@ public abstract class AbstractKeyValueStorageTest {
@Test ( expected = IllegalStateException . class )
public void transactionRemoveAfterCommit ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final Transaction tx = store . getS tartTransaction( ) ;
final Transaction tx = store . s tartTransaction( ) ;
tx . commit ( ) ;
tx . remove ( BytesValue . of ( 1 ) ) ;
}
@ -223,7 +253,7 @@ public abstract class AbstractKeyValueStorageTest {
@Test ( expected = IllegalStateException . class )
public void transactionPutAfterRollback ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final Transaction tx = store . getS tartTransaction( ) ;
final Transaction tx = store . s tartTransaction( ) ;
tx . rollback ( ) ;
tx . put ( BytesValue . of ( 1 ) , BytesValue . of ( 1 ) ) ;
}
@ -231,7 +261,7 @@ public abstract class AbstractKeyValueStorageTest {
@Test ( expected = IllegalStateException . class )
public void transactionRemoveAfterRollback ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final Transaction tx = store . getS tartTransaction( ) ;
final Transaction tx = store . s tartTransaction( ) ;
tx . rollback ( ) ;
tx . remove ( BytesValue . of ( 1 ) ) ;
}
@ -239,7 +269,7 @@ public abstract class AbstractKeyValueStorageTest {
@Test ( expected = IllegalStateException . class )
public void transactionCommitAfterRollback ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final Transaction tx = store . getS tartTransaction( ) ;
final Transaction tx = store . s tartTransaction( ) ;
tx . rollback ( ) ;
tx . commit ( ) ;
}
@ -247,7 +277,7 @@ public abstract class AbstractKeyValueStorageTest {
@Test ( expected = IllegalStateException . class )
public void transactionCommitTwice ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final Transaction tx = store . getS tartTransaction( ) ;
final Transaction tx = store . s tartTransaction( ) ;
tx . commit ( ) ;
tx . commit ( ) ;
}
@ -255,7 +285,7 @@ public abstract class AbstractKeyValueStorageTest {
@Test ( expected = IllegalStateException . class )
public void transactionRollbackAfterCommit ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final Transaction tx = store . getS tartTransaction( ) ;
final Transaction tx = store . s tartTransaction( ) ;
tx . commit ( ) ;
tx . rollback ( ) ;
}
@ -263,7 +293,7 @@ public abstract class AbstractKeyValueStorageTest {
@Test ( expected = IllegalStateException . class )
public void transactionRollbackTwice ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final Transaction tx = store . getS tartTransaction( ) ;
final Transaction tx = store . s tartTransaction( ) ;
tx . rollback ( ) ;
tx . rollback ( ) ;
}
@ -272,8 +302,8 @@ public abstract class AbstractKeyValueStorageTest {
public void twoTransactions ( ) throws Exception {
final KeyValueStorage store = createStore ( ) ;
final Transaction tx1 = store . getS tartTransaction( ) ;
final Transaction tx2 = store . getS tartTransaction( ) ;
final Transaction tx1 = store . s tartTransaction( ) ;
final Transaction tx2 = store . s tartTransaction( ) ;
tx1 . put ( BytesValue . of ( 1 ) , BytesValue . of ( 1 ) ) ;
tx2 . put ( BytesValue . of ( 2 ) , BytesValue . of ( 2 ) ) ;
@ -295,7 +325,7 @@ public abstract class AbstractKeyValueStorageTest {
( value ) - >
new Thread (
( ) - > {
final Transaction tx = store . getS tartTransaction( ) ;
final Transaction tx = store . s tartTransaction( ) ;
for ( int i = 0 ; i < keyCount ; i + + ) {
tx . put ( BytesValues . toMinimalBytes ( i ) , value ) ;
}