use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.
the class UtilsWrapperTests method testInvalidParameters.
@Test
public void testInvalidParameters() throws Exception {
// Set up
@Cleanup ChunkStorage chunkStorage = new InMemoryChunkStorage(executorService());
@Cleanup val metadataStore = new InMemoryMetadataStore(ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService());
@Cleanup ChunkedSegmentStorage chunkedSegmentStorage = new ChunkedSegmentStorage(42, chunkStorage, metadataStore, executorService(), ChunkedSegmentStorageConfig.DEFAULT_CONFIG);
chunkedSegmentStorage.initialize(123);
AssertExtensions.assertThrows("Should not allow null chunkStorage", () -> new UtilsWrapper(null, 10, Duration.ZERO), ex -> ex instanceof NullPointerException);
AssertExtensions.assertThrows("Should not allow null duration", () -> new UtilsWrapper(chunkedSegmentStorage, 10, null), ex -> ex instanceof NullPointerException);
val wrapper = new UtilsWrapper(chunkedSegmentStorage, 10, Duration.ZERO);
AssertExtensions.assertThrows("Should not allow null segmentName", () -> wrapper.evictReadIndexCacheForSegment(null), ex -> ex instanceof NullPointerException);
AssertExtensions.assertThrows("Should not allow null chunkName", () -> wrapper.copyFromChunk(null, new ByteArrayOutputStream(1)), ex -> ex instanceof NullPointerException);
AssertExtensions.assertThrows("Should not allow null outputStream", () -> wrapper.copyFromChunk("test", null), ex -> ex instanceof NullPointerException);
AssertExtensions.assertThrows("Should not allow null chunkName", () -> wrapper.overwriteChunk(null, new ByteArrayInputStream(new byte[] {}), 1), ex -> ex instanceof NullPointerException);
AssertExtensions.assertThrows("Should not allow null inputStream", () -> wrapper.overwriteChunk("test", null, 1), ex -> ex instanceof NullPointerException);
AssertExtensions.assertThrows("Should not allow null segmentName", () -> wrapper.copyFromSegment(null, new ByteArrayOutputStream(1)), ex -> ex instanceof NullPointerException);
AssertExtensions.assertThrows("Should not allow null outputStream", () -> wrapper.copyFromSegment("test", null), ex -> ex instanceof NullPointerException);
AssertExtensions.assertThrows("Should not allow null outputStream", () -> wrapper.getExtendedChunkInfoList(null, false), ex -> ex instanceof NullPointerException);
}
use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore 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.InMemoryMetadataStore in project pravega by pravega.
the class ChunkMetadataStoreTests method testEvictAllInParallel.
@Test
public void testEvictAllInParallel() {
if (metadataStore instanceof InMemoryMetadataStore) {
metadataStore.setMaxEntriesInCache(10);
metadataStore.setMaxEntriesInTxnBuffer(10);
val futures = new ArrayList<CompletableFuture<Void>>();
for (int i = 0; i < 10000; i++) {
final int k = i;
futures.add(CompletableFuture.runAsync(() -> simpleScenarioForKey("Key" + k)));
futures.add(CompletableFuture.runAsync(() -> metadataStore.evictAllEligibleEntriesFromBuffer()));
}
Futures.allOf(futures);
}
}
use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore 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.InMemoryMetadataStore 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);
}
}
}
Aggregations