use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.
the class ChunkedSegmentStorageMockTests method testUpdateStorageStatsException.
@Test
public void testUpdateStorageStatsException() throws Exception {
@Cleanup BaseMetadataStore spyMetadataStore = spy(new InMemoryMetadataStore(ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService()));
@Cleanup val spyChunkStorage = spy(new NoOpChunkStorage(executorService()));
@Cleanup ChunkedSegmentStorage chunkedSegmentStorage = new ChunkedSegmentStorage(CONTAINER_ID, spyChunkStorage, spyMetadataStore, executorService(), ChunkedSegmentStorageConfig.DEFAULT_CONFIG);
chunkedSegmentStorage.initialize(1);
chunkedSegmentStorage.getGarbageCollector().initialize(new InMemoryTaskQueueManager()).join();
Exception exceptionToThrow = new ChunkStorageException("Intentional", "Intentional");
doReturn(CompletableFuture.failedFuture(exceptionToThrow)).when(spyChunkStorage).doGetUsedSpaceAsync(any());
// Should not throw an exception
chunkedSegmentStorage.updateStorageStats().get();
}
use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.
the class ChunkedSegmentStorageMockTests method testIOExceptionDuringWrite.
@Test
public void testIOExceptionDuringWrite() throws Exception {
String testSegmentName = "test";
// Force rollover after every 2 byte.
SegmentRollingPolicy policy = new SegmentRollingPolicy(2);
val config = ChunkedSegmentStorageConfig.DEFAULT_CONFIG.toBuilder().storageMetadataRollingPolicy(policy).build();
@Cleanup BaseMetadataStore spyMetadataStore = spy(new InMemoryMetadataStore(ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService()));
@Cleanup BaseChunkStorage spyChunkStorage = spy(new NoOpChunkStorage(executorService()));
((NoOpChunkStorage) spyChunkStorage).setShouldSupportConcat(false);
@Cleanup ChunkedSegmentStorage chunkedSegmentStorage = new ChunkedSegmentStorage(CONTAINER_ID, spyChunkStorage, spyMetadataStore, executorService(), config);
chunkedSegmentStorage.initialize(1);
chunkedSegmentStorage.getGarbageCollector().initialize(new InMemoryTaskQueueManager()).join();
// Step 1: Create segment and write some data.
val h1 = chunkedSegmentStorage.create(testSegmentName, policy, null).get();
Assert.assertEquals(h1.getSegmentName(), testSegmentName);
Assert.assertFalse(h1.isReadOnly());
chunkedSegmentStorage.write(h1, 0, new ByteArrayInputStream(new byte[10]), 10, null).get();
// Step 2: Inject fault.
Exception exceptionToThrow = new ChunkStorageException("test", "Test Exception", new IOException("Test Exception"));
val clazz = ChunkStorageException.class;
doThrow(exceptionToThrow).when(spyChunkStorage).doWrite(any(), anyLong(), anyInt(), any());
AssertExtensions.assertFutureThrows("write succeeded when exception was expected.", chunkedSegmentStorage.write(h1, 10, new ByteArrayInputStream(new byte[10]), 10, null), ex -> clazz.equals(ex.getClass()));
}
use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore 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.InMemoryMetadataStore 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.InMemoryMetadataStore 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();
}
}
Aggregations