use of io.pravega.segmentstore.storage.mocks.InMemoryTableStore 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());
}
}
use of io.pravega.segmentstore.storage.mocks.InMemoryTableStore in project pravega by pravega.
the class TableBasedMetadataStoreTests method setUp.
@Override
@Before
public void setUp() throws Exception {
val tableStore = new InMemoryTableStore(executorService());
metadataStore = new TableBasedMetadataStore("TEST", tableStore, ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService());
}
Aggregations