use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testTransactionCommitIllegalStateException.
@Test
public void testTransactionCommitIllegalStateException() throws Exception {
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY0, KEY1)) {
assertNull(txn.get(KEY0));
txn.create(new MockStorageMetadata(KEY0, VALUE0));
Assert.assertNotNull(txn.get(KEY0));
txn.commit().join();
AssertExtensions.assertThrows("commit should throw an exception", () -> txn.commit(), ex -> ex instanceof IllegalStateException);
AssertExtensions.assertThrows("commit should throw an exception", () -> txn.commit(true), ex -> ex instanceof IllegalStateException);
AssertExtensions.assertThrows("commit should throw an exception", () -> txn.commit(true, true), ex -> ex instanceof IllegalStateException);
AssertExtensions.assertThrows("abort should throw an exception", () -> txn.abort(), ex -> ex instanceof IllegalStateException);
}
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY0, KEY1)) {
txn.update(new MockStorageMetadata(KEY0, VALUE0));
Assert.assertNotNull(txn.get(KEY0));
txn.abort().join();
AssertExtensions.assertThrows("create should throw an exception", () -> txn.commit(), ex -> ex instanceof IllegalStateException);
AssertExtensions.assertThrows("commit should throw an exception", () -> txn.commit(true), ex -> ex instanceof IllegalStateException);
AssertExtensions.assertThrows("commit should throw an exception", () -> txn.commit(true, true), ex -> ex instanceof IllegalStateException);
AssertExtensions.assertThrows("abort should throw an exception", () -> txn.abort(), ex -> ex instanceof IllegalStateException);
}
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method simpleScenarioForKey.
@SneakyThrows
private void simpleScenarioForKey(String key) {
// Create key.
try (MetadataTransaction txn = metadataStore.beginTransaction(false, key)) {
txn.create(new MockStorageMetadata(key, VALUE0));
assertEquals(txn.get(key), key, VALUE0);
txn.commit().get();
}
// Modify
try (MetadataTransaction txn = metadataStore.beginTransaction(false, key)) {
assertEquals(txn.get(key), key, VALUE0);
txn.update(new MockStorageMetadata(key, VALUE1));
assertEquals(txn.get(key), key, VALUE1);
txn.commit().get();
}
// Delete
try (MetadataTransaction txn = metadataStore.beginTransaction(false, key)) {
assertEquals(txn.get(key), key, VALUE1);
txn.delete(key);
assertNull(txn.get(key));
txn.commit().get();
}
try (MetadataTransaction txn = metadataStore.beginTransaction(true, key)) {
assertNull(txn.get(key));
}
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testEviction.
@Test
public void testEviction() throws Exception {
if (!(metadataStore instanceof InMemoryMetadataStore)) {
return;
}
val testMetadataStore = (InMemoryMetadataStore) metadataStore;
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY1)) {
txn.create(new MockStorageMetadata(KEY1, VALUE0));
txn.commit().get();
}
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();
// But data should be still there in Guava cache.
// It will be inserted into buffer.
assertEquals(txn.get(KEY1), KEY1, VALUE0);
// 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 testEvictionPinnedKeys.
@Test
public void testEvictionPinnedKeys() 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.markPinned(metadata);
txn.commit().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 testTransactionFailedForMultipleUpdates.
@Test
public void testTransactionFailedForMultipleUpdates() throws Exception {
// Step 1: Set up
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;
}
// Step 2: Create a test transaction
try (MetadataTransaction txn0 = metadataStore.beginTransaction(false, KEYS)) {
// Step 2 A: Make some updates, but don't commit yet.
txn0.update(new MockStorageMetadata(KEY0, VALUE5));
assertEquals(txn0.get(KEY0), KEY0, VALUE5);
assertEquals(txn0.get(KEY3), KEY3, VALUE2);
// Step 3 : Start a parallel transaction
try (MetadataTransaction txn2 = metadataStore.beginTransaction(false, KEYS)) {
// Step 3 A: Make some updates, but don't commit yet.
txn2.update(new MockStorageMetadata(KEY0, VALUE6));
assertEquals(txn2.get(KEY0), KEY0, VALUE6);
assertEquals(txn2.get(KEY3), KEY3, VALUE2);
// Step 3 B: Commit. It should succeed.
txn2.commit(false).join();
assertEquals(txn2.get(KEY0), KEY0, VALUE6);
assertEquals(txn2.get(KEY3), KEY3, VALUE2);
} catch (Exception e) {
throw e;
}
// Step 4 : Start a second parallel transaction
try (MetadataTransaction txn2 = metadataStore.beginTransaction(false, KEYS)) {
// Step 4 : Data committed by earlier transaction should be visible to other new transactions
assertEquals(txn2.get(KEY0), KEY0, VALUE6);
assertEquals(txn2.get(KEY3), KEY3, VALUE2);
} catch (Exception e) {
throw e;
}
// A committed transactions should not have any effect on this transaction.
assertEquals(txn0.get(KEY0), KEY0, VALUE5);
assertEquals(txn0.get(KEY3), KEY3, VALUE2);
try {
txn0.commit(false).join();
Assert.fail("Transaction should be aborted.");
} catch (CompletionException e) {
Assert.assertTrue(e.getCause() instanceof StorageMetadataVersionMismatchException);
}
}
}
Aggregations