use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testDelete.
/**
* Test delete
*
* @throws Exception Exception if any.
*/
@Test
public void testDelete() throws Exception {
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEYS)) {
assertNull(txn.get(KEY0));
txn.create(new MockStorageMetadata(KEY0, VALUE0));
Assert.assertNotNull(txn.get(KEY0));
txn.delete(KEY0);
assertNull(txn.get(KEY0));
txn.commit().join();
}
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEYS)) {
assertNull(txn.get(KEY0));
// Should be able to recreate
txn.create(new MockStorageMetadata(KEY0, VALUE0));
assertEquals(txn.get(KEY0), KEY0, VALUE0);
txn.commit().join();
}
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEYS)) {
assertEquals(txn.get(KEY0), KEY0, VALUE0);
}
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testLazyCommitWithNormalCommitWithNoBuffer.
/**
* Tests simple scenario with lazy commit.
*
* @throws Exception
*/
@Test
public void testLazyCommitWithNormalCommitWithNoBuffer() throws Exception {
metadataStore.setMaxEntriesInTxnBuffer(0);
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEYS)) {
// NO value should be found.
assertNull(txn.get(KEY0));
assertNull(txn.get(KEY1));
assertNull(txn.get(KEY2));
// Create data
txn.create(new MockStorageMetadata(KEY0, VALUE0));
txn.create(new MockStorageMetadata(KEY1, VALUE1));
txn.create(new MockStorageMetadata(KEY2, VALUE2));
assertEquals(txn.get(KEY0), KEY0, VALUE0);
assertEquals(txn.get(KEY1), KEY1, VALUE1);
assertEquals(txn.get(KEY2), KEY2, VALUE2);
// This is normal commit.
txn.commit().join();
} catch (Exception e) {
throw e;
}
// make sure they are stored correctly
assertEquals((MockStorageMetadata) metadataStore.read(KEY0).get().getValue(), KEY0, VALUE0);
assertEquals((MockStorageMetadata) metadataStore.read(KEY1).get().getValue(), KEY1, VALUE1);
assertEquals((MockStorageMetadata) metadataStore.read(KEY2).get().getValue(), KEY2, VALUE2);
try (MetadataTransaction txn1 = metadataStore.beginTransaction(false, KEYS)) {
// Update
txn1.update(new MockStorageMetadata(KEY1, VALUE4));
assertEquals(txn1.get(KEY0), KEY0, VALUE0);
assertEquals(txn1.get(KEY1), KEY1, VALUE4);
assertEquals(txn1.get(KEY2), KEY2, VALUE2);
// delete
txn1.delete(KEY2);
assertEquals(txn1.get(KEY0), KEY0, VALUE0);
assertEquals(txn1.get(KEY1), KEY1, VALUE4);
assertNull(txn1.get(KEY2));
// Commit lazily.
txn1.commit(true).join();
assertEquals(txn1.get(KEY0), KEY0, VALUE0);
assertEquals(txn1.get(KEY1), KEY1, VALUE4);
assertNull(txn1.get(KEY2));
} catch (Exception e) {
throw e;
}
// make sure the persistent store actually has the correct value.
assertEquals((MockStorageMetadata) metadataStore.read(KEY0).get().getValue(), KEY0, VALUE0);
assertEquals((MockStorageMetadata) metadataStore.read(KEY1).get().getValue(), KEY1, VALUE4);
Assert.assertNull(metadataStore.read(KEY2).get().getValue());
// Note this transaction is aborted. So any changes made here should be totally ignored.
try (MetadataTransaction txn2 = metadataStore.beginTransaction(false, KEYS)) {
assertEquals(txn2.get(KEY0), KEY0, VALUE0);
assertEquals(txn2.get(KEY1), KEY1, VALUE4);
assertNull(txn2.get(KEY2));
txn2.update(new MockStorageMetadata(KEY0, VALUE6));
txn2.delete(KEY1);
// This is still
assertEquals(txn2.get(KEY0), KEY0, VALUE6);
assertNull(txn2.get(KEY3));
assertNull(txn2.get(KEY1));
// abort
txn2.abort().join();
} catch (Exception e) {
throw e;
}
// Should have no effect;
try (MetadataTransaction txn3 = metadataStore.beginTransaction(false, KEYS)) {
assertEquals(txn3.get(KEY0), KEY0, VALUE0);
assertEquals(txn3.get(KEY1), KEY1, VALUE4);
assertNull(txn3.get(KEY2));
} catch (Exception e) {
throw e;
}
try (MetadataTransaction txn4 = metadataStore.beginTransaction(false, KEYS)) {
// Update
txn4.update(new MockStorageMetadata(KEY0, VALUE5));
txn4.update(new MockStorageMetadata(KEY1, VALUE6));
assertEquals(txn4.get(KEY0), KEY0, VALUE5);
assertEquals(txn4.get(KEY1), KEY1, VALUE6);
assertNull(txn4.get(KEY2));
// delete
txn4.delete(KEY1);
assertEquals(txn4.get(KEY0), KEY0, VALUE5);
assertNull(txn4.get(KEY1));
assertNull(txn4.get(KEY2));
txn4.commit().join();
assertEquals(txn4.get(KEY0), KEY0, VALUE5);
assertNull(txn4.get(KEY1));
assertNull(txn4.get(KEY2));
} catch (Exception e) {
throw e;
}
// make sure the persistent store is not affected.
assertEquals((MockStorageMetadata) metadataStore.read(KEY0).get().getValue(), KEY0, VALUE5);
Assert.assertNull(metadataStore.read(KEY1).get().getValue());
Assert.assertNull(metadataStore.read(KEY2).get().getValue());
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testLazyCommitWithNormalCommit.
/**
* Tests simple scenario with lazy commit.
*
* @throws Exception
*/
@Test
public void testLazyCommitWithNormalCommit() throws Exception {
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEYS)) {
// NO value should be found.
assertNull(txn.get(KEY0));
assertNull(txn.get(KEY1));
assertNull(txn.get(KEY2));
// Create data
txn.create(new MockStorageMetadata(KEY0, VALUE0));
txn.create(new MockStorageMetadata(KEY1, VALUE1));
txn.create(new MockStorageMetadata(KEY2, VALUE2));
assertEquals(txn.get(KEY0), KEY0, VALUE0);
assertEquals(txn.get(KEY1), KEY1, VALUE1);
assertEquals(txn.get(KEY2), KEY2, VALUE2);
txn.commit().join();
} catch (Exception e) {
throw e;
}
// make sure they are stored correctly
assertEquals((MockStorageMetadata) metadataStore.read(KEY0).get().getValue(), KEY0, VALUE0);
assertEquals((MockStorageMetadata) metadataStore.read(KEY1).get().getValue(), KEY1, VALUE1);
assertEquals((MockStorageMetadata) metadataStore.read(KEY2).get().getValue(), KEY2, VALUE2);
try (MetadataTransaction txn1 = metadataStore.beginTransaction(false, KEYS)) {
// Update
txn1.update(new MockStorageMetadata(KEY1, VALUE4));
assertEquals(txn1.get(KEY0), KEY0, VALUE0);
assertEquals(txn1.get(KEY1), KEY1, VALUE4);
assertEquals(txn1.get(KEY2), KEY2, VALUE2);
// delete
txn1.delete(KEY2);
assertEquals(txn1.get(KEY0), KEY0, VALUE0);
assertEquals(txn1.get(KEY1), KEY1, VALUE4);
assertNull(txn1.get(KEY2));
// Commit lazily.
txn1.commit(true).join();
assertEquals(txn1.get(KEY0), KEY0, VALUE0);
assertEquals(txn1.get(KEY1), KEY1, VALUE4);
assertNull(txn1.get(KEY2));
} catch (Exception e) {
throw e;
}
// make sure the persistent store is not affected.
assertEquals((MockStorageMetadata) metadataStore.read(KEY0).get().getValue(), KEY0, VALUE0);
assertEquals((MockStorageMetadata) metadataStore.read(KEY1).get().getValue(), KEY1, VALUE1);
assertEquals((MockStorageMetadata) metadataStore.read(KEY2).get().getValue(), KEY2, VALUE2);
// Note this transaction is aborted. So any changes made here should be totally ignored.
try (MetadataTransaction txn2 = metadataStore.beginTransaction(false, KEYS)) {
assertEquals(txn2.get(KEY0), KEY0, VALUE0);
assertEquals(txn2.get(KEY1), KEY1, VALUE4);
assertNull(txn2.get(KEY2));
txn2.update(new MockStorageMetadata(KEY0, VALUE6));
txn2.delete(KEY1);
// This is still
assertEquals(txn2.get(KEY0), KEY0, VALUE6);
assertNull(txn2.get(KEY3));
assertNull(txn2.get(KEY1));
// abort
txn2.abort().join();
} catch (Exception e) {
throw e;
}
// Should have no effect;
try (MetadataTransaction txn3 = metadataStore.beginTransaction(false, KEYS)) {
assertEquals(txn3.get(KEY0), KEY0, VALUE0);
assertEquals(txn3.get(KEY1), KEY1, VALUE4);
assertNull(txn3.get(KEY2));
} catch (Exception e) {
throw e;
}
try (MetadataTransaction txn4 = metadataStore.beginTransaction(false, KEYS)) {
// Update
txn4.update(new MockStorageMetadata(KEY0, VALUE5));
txn4.update(new MockStorageMetadata(KEY1, VALUE6));
assertEquals(txn4.get(KEY0), KEY0, VALUE5);
assertEquals(txn4.get(KEY1), KEY1, VALUE6);
assertNull(txn4.get(KEY2));
// delete
txn4.delete(KEY1);
assertEquals(txn4.get(KEY0), KEY0, VALUE5);
assertNull(txn4.get(KEY1));
assertNull(txn4.get(KEY2));
txn4.commit().join();
assertEquals(txn4.get(KEY0), KEY0, VALUE5);
assertNull(txn4.get(KEY1));
assertNull(txn4.get(KEY2));
} catch (Exception e) {
throw e;
}
// make sure the persistent store is not affected.
assertEquals((MockStorageMetadata) metadataStore.read(KEY0).get().getValue(), KEY0, VALUE5);
Assert.assertNull(metadataStore.read(KEY1).get().getValue());
assertEquals((MockStorageMetadata) metadataStore.read(KEY2).get().getValue(), KEY2, VALUE2);
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testWithNullExternalStep.
@Test
public void testWithNullExternalStep() throws Exception {
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY0, KEY1)) {
assertNull(txn.get(KEY0));
txn.setExternalCommitStep(null);
txn.create(new MockStorageMetadata(KEY0, VALUE0));
Assert.assertNotNull(txn.get(KEY0));
txn.commit().get();
}
try (MetadataTransaction txn = metadataStore.beginTransaction(true, KEY1)) {
assertEquals(txn.get(KEY0), KEY0, VALUE0);
}
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testGetAll.
@Test
public void testGetAll() throws Exception {
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEYS)) {
// NO value should be found.
assertNull(txn.get(KEY0));
assertNull(txn.get(KEY1));
assertNull(txn.get(KEY3));
Assert.assertEquals(0, metadataStore.getAllEntries().join().count());
Assert.assertEquals(0, metadataStore.getAllKeys().join().count());
// Create data
txn.create(new MockStorageMetadata(KEY0, VALUE0));
txn.create(new MockStorageMetadata(KEY1, VALUE1));
txn.create(new MockStorageMetadata(KEY2, VALUE2));
Assert.assertEquals(0, metadataStore.getAllEntries().join().count());
Assert.assertEquals(0, metadataStore.getAllKeys().join().count());
txn.commit().join();
}
val allEntries = metadataStore.getAllEntries().join().map(e -> (MockStorageMetadata) e).collect(Collectors.toMap(StorageMetadata::getKey, s -> s));
Assert.assertEquals(3, allEntries.size());
assertEquals(allEntries.get(KEY0), KEY0, VALUE0);
assertEquals(allEntries.get(KEY1), KEY1, VALUE1);
assertEquals(allEntries.get(KEY2), KEY2, VALUE2);
val allKeys = metadataStore.getAllKeys().join().collect(Collectors.toSet());
Assert.assertTrue(allKeys.contains(KEY0));
Assert.assertTrue(allKeys.contains(KEY1));
Assert.assertTrue(allKeys.contains(KEY2));
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEYS)) {
// delete data
txn.delete(KEY0);
txn.delete(KEY1);
txn.commit().join();
}
val allEntriesSet = metadataStore.getAllEntries().join().collect(Collectors.toSet());
val allEntriesAfter = allEntriesSet.stream().map(e -> (MockStorageMetadata) e).collect(Collectors.toMap(StorageMetadata::getKey, s -> s));
Assert.assertEquals(1, allEntriesAfter.size());
assertEquals(allEntriesAfter.get(KEY2), KEY2, VALUE2);
Assert.assertFalse(allEntriesAfter.containsKey(KEY0));
Assert.assertFalse(allEntriesAfter.containsKey(KEY1));
val allKeysAfter = metadataStore.getAllKeys().join().collect(Collectors.toSet());
Assert.assertFalse(allKeysAfter.contains(KEY0));
Assert.assertFalse(allKeysAfter.contains(KEY1));
Assert.assertTrue(allKeysAfter.contains(KEY2));
}
Aggregations