use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testEvictionFromBuffer.
@Test
@Ignore("Should be fixed or removed.")
public void testEvictionFromBuffer() throws Exception {
if (metadataStore instanceof InMemoryMetadataStore) {
metadataStore.setMaxEntriesInCache(10);
metadataStore.setMaxEntriesInTxnBuffer(10);
for (int i = 0; i < 10000; i++) {
try (MetadataTransaction txn = metadataStore.beginTransaction(false, "Txn" + i)) {
txn.create(new MockStorageMetadata("Txn" + i, "Value" + i));
txn.commit().get();
}
try (MetadataTransaction txn = metadataStore.beginTransaction(false, "Txn" + i)) {
txn.delete("Txn" + i);
txn.commit().get();
}
}
Assert.assertTrue(metadataStore.getBufferCount() < 10);
}
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testTransactionFailedForMultipleOperations.
@Test
public void testTransactionFailedForMultipleOperations() throws Exception {
// Set up the data there are 3 keys
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEYS)) {
assertNull(txn.get(KEY0));
assertNull(txn.get(KEY1));
assertNull(txn.get(KEY3));
// Create data
txn.create(new MockStorageMetadata(KEY0, VALUE0));
txn.create(new MockStorageMetadata(KEY1, VALUE1));
txn.create(new MockStorageMetadata(KEY3, VALUE2));
assertEquals(txn.get(KEY0), KEY0, VALUE0);
assertEquals(txn.get(KEY1), KEY1, VALUE1);
assertEquals(txn.get(KEY3), KEY3, VALUE2);
txn.commit(false).join();
// Same data after commit.
assertEquals(txn.get(KEY0), KEY0, VALUE0);
assertEquals(txn.get(KEY1), KEY1, VALUE1);
assertEquals(txn.get(KEY3), KEY3, VALUE2);
} catch (Exception e) {
throw e;
}
// Start a test transaction
try (MetadataTransaction txn0 = metadataStore.beginTransaction(false, KEYS)) {
// Update/delete some keys but don't commit .
// We wan to see that these changes do not affect other transactions
txn0.update(new MockStorageMetadata(KEY0, VALUE5));
txn0.delete(KEY1);
assertEquals(txn0.get(KEY0), KEY0, VALUE5);
assertEquals(txn0.get(KEY3), KEY3, VALUE2);
assertNull(txn0.get(KEY1));
// Another Transaction that must be able modify its view data and commit
try (MetadataTransaction txn2 = metadataStore.beginTransaction(false, KEYS)) {
txn2.update(new MockStorageMetadata(KEY0, VALUE6));
txn2.delete(KEY1);
assertEquals(txn2.get(KEY0), KEY0, VALUE6);
assertEquals(txn2.get(KEY3), KEY3, VALUE2);
assertNull(txn2.get(KEY1));
txn2.commit(false).join();
assertEquals(txn2.get(KEY0), KEY0, VALUE6);
assertEquals(txn2.get(KEY3), KEY3, VALUE2);
assertNull(txn2.get(KEY1));
} catch (Exception e) {
throw e;
}
// Yet another Transaction that must be able modify its view data and commit
try (MetadataTransaction txn2 = metadataStore.beginTransaction(false, KEYS)) {
assertEquals(txn2.get(KEY0), KEY0, VALUE6);
assertEquals(txn2.get(KEY3), KEY3, VALUE2);
assertNull(txn2.get(KEY1));
} catch (Exception e) {
throw e;
}
// A committed transaction should not have any effect on this transaction.
assertEquals(txn0.get(KEY0), KEY0, VALUE5);
assertEquals(txn0.get(KEY3), KEY3, VALUE2);
assertNull(txn0.get(KEY1));
// However when it tries to commit this should fail.
try {
txn0.commit(false).join();
Assert.fail("Transaction should be aborted.");
} catch (CompletionException e) {
Assert.assertTrue(e.getCause() instanceof StorageMetadataVersionMismatchException);
}
}
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testEvictionForLazyCommits.
@Test
public void testEvictionForLazyCommits() throws Exception {
if (!(metadataStore instanceof InMemoryMetadataStore)) {
return;
}
val testMetadataStore = (InMemoryMetadataStore) metadataStore;
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY1)) {
val metadata = new MockStorageMetadata(KEY1, VALUE0);
txn.create(metadata);
txn.commit(true).get();
Assert.assertNull(testMetadataStore.getBackingStore().get(KEY1));
}
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY1)) {
// Delete data from backing store , the data should be still in buffer.
testMetadataStore.evictFromCache();
testMetadataStore.getBackingStore().clear();
Assert.assertNull(testMetadataStore.getBackingStore().get(KEY1));
assertEquals(txn.get(KEY1), KEY1, VALUE0);
// Invoke eviction, this will move data from buffer to the Guava cache.
testMetadataStore.evictAllEligibleEntriesFromBuffer();
// Forcibly delete it from cache
testMetadataStore.evictFromCache();
testMetadataStore.getBackingStore().clear();
Assert.assertNull(testMetadataStore.getBackingStore().get(KEY1));
// But data should be still there in buffer.
assertEquals(txn.get(KEY1), KEY1, VALUE0);
}
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testCommitSafety.
/**
* Test that only one of the concurrent commit can proceed and others fail.
*
* @throws Exception Exception if any.
*/
@Test
public void testCommitSafety() throws Exception {
if (metadataStore instanceof InMemoryMetadataStore) {
// Set up the callback so that you can block writeAll call, to create situation where commit is in flight but not finished.
final CompletableFuture<Void> futureToBlockOn = new CompletableFuture<Void>();
((InMemoryMetadataStore) metadataStore).setWriteCallback(v -> futureToBlockOn.thenApplyAsync(v2 -> null, executorService()));
CompletableFuture<Void> commitFuture;
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEYS)) {
assertNull(txn.get(KEY0));
txn.create(new MockStorageMetadata(KEY0, VALUE0));
Assert.assertNotNull(txn.get(KEY0));
// Do not wait , this call should block
commitFuture = txn.commit();
}
try {
// Try commit on all keys
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEYS)) {
assertNull(txn.get(KEY0));
txn.create(new MockStorageMetadata(KEY0, VALUE1));
assertEquals(txn.get(KEY0), KEY0, VALUE1);
AssertExtensions.assertFutureThrows("Transaction should fail.", txn.commit(), ex -> ex instanceof StorageMetadataVersionMismatchException);
}
// Try commit only on only one key.
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY0)) {
assertNull(txn.get(KEY0));
txn.create(new MockStorageMetadata(KEY0, VALUE1));
assertEquals(txn.get(KEY0), KEY0, VALUE1);
AssertExtensions.assertFutureThrows("Transaction should fail.", txn.commit(), ex -> ex instanceof StorageMetadataVersionMismatchException);
}
} finally {
futureToBlockOn.complete(null);
}
commitFuture.join();
// make sure the valid transaction went through.
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY0)) {
assertEquals(txn.get(KEY0), KEY0, VALUE0);
}
}
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testSimpleScenarioWithPinnedRecords.
/**
* Tests simple scenario with lazy commit.
*
* @throws Exception
*/
@Test
public void testSimpleScenarioWithPinnedRecords() 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 KEY0, KEY1, KEY2
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.markPinned(txn.get(KEY0).get());
txn.markPinned(txn.get(KEY1).get());
txn.markPinned(txn.get(KEY2).get());
// Update KEY1
txn.update(new MockStorageMetadata(KEY1, VALUE4));
assertEquals(txn.get(KEY0), KEY0, VALUE0);
assertEquals(txn.get(KEY1), KEY1, VALUE4);
assertEquals(txn.get(KEY2), KEY2, VALUE2);
// create KEY3
txn.create(new MockStorageMetadata(KEY3, VALUE5));
assertEquals(txn.get(KEY0), KEY0, VALUE0);
assertEquals(txn.get(KEY1), KEY1, VALUE4);
assertEquals(txn.get(KEY2), KEY2, VALUE2);
assertEquals(txn.get(KEY3), KEY3, VALUE5);
// delete KEY2, KEY3
txn.delete(KEY2);
txn.delete(KEY3);
assertEquals(txn.get(KEY0), KEY0, VALUE0);
assertEquals(txn.get(KEY1), KEY1, VALUE4);
assertNull(txn.get(KEY2));
assertNull(txn.get(KEY3));
txn.commit().join();
assertEquals(txn.get(KEY0), KEY0, VALUE0);
assertEquals(txn.get(KEY1), KEY1, VALUE4);
assertNull(txn.get(KEY2));
assertNull(txn.get(KEY3));
// make sure they are stored correctly
Assert.assertNull(metadataStore.read(KEY0).get().getValue());
Assert.assertNull(metadataStore.read(KEY1).get().getValue());
Assert.assertNull(metadataStore.read(KEY2).get().getValue());
Assert.assertNull(metadataStore.read(KEY3).get().getValue());
} catch (Exception e) {
throw e;
}
// See the effect of transaction after words
try (MetadataTransaction txn2 = metadataStore.beginTransaction(false, KEYS)) {
assertEquals(txn2.get(KEY0), KEY0, VALUE0);
assertEquals(txn2.get(KEY1), KEY1, VALUE4);
assertNull(txn2.get(KEY3));
txn2.update(new MockStorageMetadata(KEY0, VALUE6));
txn2.delete(KEY1);
assertEquals(txn2.get(KEY0), KEY0, VALUE6);
assertNull(txn2.get(KEY3));
assertNull(txn2.get(KEY1));
// Implicitly aborted
} 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(KEY3));
} catch (Exception e) {
throw e;
}
}
Aggregations