use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testEvictionDuringCommit.
@Test
public void testEvictionDuringCommit() 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();
}
CompletableFuture commitStepFurure = new CompletableFuture();
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY1)) {
// Block commit
txn.setExternalCommitStep(() -> validateInsideCommit(testMetadataStore, txn));
txn.commit().join();
}
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testCommitFailureWithExternalSteps.
@Test
public void testCommitFailureWithExternalSteps() throws Exception {
// Add some data
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY1)) {
txn.create(new MockStorageMetadata(KEY1, VALUE0));
txn.commit().get();
}
// This txn will fail to commit.
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY1)) {
txn.setExternalCommitStep(() -> {
throw new IntentionalException("Intentional");
});
val metadata = (MockStorageMetadata) txn.get(KEY1).get();
metadata.setValue(VALUE1);
txn.update(metadata);
txn.commit().get();
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(Exceptions.unwrap(e).getCause() instanceof IntentionalException);
}
// Validate that object in buffer remains unchanged.
try (MetadataTransaction txn = metadataStore.beginTransaction(true, KEY1)) {
assertEquals(txn.get(KEY1), KEY1, VALUE0);
}
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class ChunkMetadataStoreTests method testSimpleScenarioWithLazyCommit.
/**
* Tests simple scenario with lazy commit.
*
* @throws Exception
*/
@Test
public void testSimpleScenarioWithLazyCommit() 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);
// 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(true).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;
}
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class TableBasedMetadataStoreMockTests method testBadReadMissingNoVersionDuringRead.
@Test
public void testBadReadMissingNoVersionDuringRead() {
TableStore mockTableStore = mock(TableStore.class);
@Cleanup TableBasedMetadataStore tableBasedMetadataStore = spy(new TableBasedMetadataStore("test", mockTableStore, ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService()));
when(mockTableStore.createSegment(any(), any(), any())).thenReturn(Futures.failedFuture(new CompletionException(new StreamSegmentExistsException("test"))));
when(tableBasedMetadataStore.read("test")).thenReturn(CompletableFuture.completedFuture(BaseMetadataStore.TransactionData.builder().key("test").value(new MockStorageMetadata("key", "value")).dbObject(Long.valueOf(10)).build()));
val txn = tableBasedMetadataStore.beginTransaction(true, "test");
AssertExtensions.assertFutureThrows("read should throw an exception", tableBasedMetadataStore.get(txn, "test"), ex -> ex instanceof IllegalStateException);
}
use of io.pravega.segmentstore.storage.mocks.MockStorageMetadata in project pravega by pravega.
the class TableBasedMetadataStoreMockTests method testExceptionDuringRemoveWithSpy.
@Test
public void testExceptionDuringRemoveWithSpy() throws Exception {
TableStore mockTableStore = spy(new InMemoryTableStore(executorService()));
@Cleanup TableBasedMetadataStore tableBasedMetadataStore = new TableBasedMetadataStore("test", mockTableStore, ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService());
// Step 1 - set up keys
try (val txn = tableBasedMetadataStore.beginTransaction(false, "TEST")) {
txn.create(new MockStorageMetadata("key1", "A"));
txn.create(new MockStorageMetadata("key2", "B"));
txn.create(new MockStorageMetadata("key3", "C"));
txn.commit().join();
}
// Step 2 - Throw random exception
Exception e = new ArithmeticException();
val td = BaseMetadataStore.TransactionData.builder().key("foo").version(1L).dbObject(2L).build();
CompletableFuture<Void> f = new CompletableFuture<>();
f.completeExceptionally(e);
when(mockTableStore.remove(anyString(), any(), any())).thenReturn(f);
// Step 3 - modify some keys and delete a key. This uses mock method that throws exception
try (val txn = tableBasedMetadataStore.beginTransaction(false, "TEST")) {
Assert.assertEquals("A", ((MockStorageMetadata) txn.get("key1").get()).getValue());
Assert.assertEquals("B", ((MockStorageMetadata) txn.get("key2").get()).getValue());
Assert.assertEquals("C", ((MockStorageMetadata) txn.get("key3").get()).getValue());
txn.update(new MockStorageMetadata("key1", "a"));
txn.update(new MockStorageMetadata("key2", "b"));
txn.delete("key3");
txn.commit().join();
}
// Step 4 - Validate results and then retry delete with no mocking.
try (val txn = tableBasedMetadataStore.beginTransaction(false, "TEST")) {
Assert.assertEquals("a", ((MockStorageMetadata) txn.get("key1").get()).getValue());
Assert.assertEquals("b", ((MockStorageMetadata) txn.get("key2").get()).getValue());
Assert.assertEquals(null, txn.get("key3").get());
val direct = tableBasedMetadataStore.read("key3").get();
Assert.assertNotNull(direct);
Assert.assertNotEquals(-1L, direct.getDbObject());
txn.delete("key3");
// stop mocking
when(mockTableStore.remove(anyString(), any(), any())).thenCallRealMethod();
txn.commit().join();
}
// Step 5 - Validate results.
try (val txn = tableBasedMetadataStore.beginTransaction(true, "TEST")) {
Assert.assertEquals("a", ((MockStorageMetadata) txn.get("key1").get()).getValue());
Assert.assertEquals("b", ((MockStorageMetadata) txn.get("key2").get()).getValue());
Assert.assertEquals(null, txn.get("key3").get());
val direct = tableBasedMetadataStore.read("key3").get();
Assert.assertNotNull(direct);
Assert.assertEquals(-1L, direct.getDbObject());
}
}
Aggregations