Search in sources :

Example 21 with InMemoryMetadataStore

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);
}
Also used : lombok.val(lombok.val) ByteArrayInputStream(java.io.ByteArrayInputStream) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 22 with InMemoryMetadataStore

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);
    }
}
Also used : MockStorageMetadata(io.pravega.segmentstore.storage.mocks.MockStorageMetadata) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with InMemoryMetadataStore

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);
    }
}
Also used : lombok.val(lombok.val) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 24 with InMemoryMetadataStore

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);
    }
}
Also used : lombok.val(lombok.val) MockStorageMetadata(io.pravega.segmentstore.storage.mocks.MockStorageMetadata) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) Test(org.junit.Test)

Example 25 with InMemoryMetadataStore

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);
        }
    }
}
Also used : SneakyThrows(lombok.SneakyThrows) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) MockStorageMetadata(io.pravega.segmentstore.storage.mocks.MockStorageMetadata) AssertExtensions(io.pravega.test.common.AssertExtensions) Exceptions(io.pravega.common.Exceptions) IntentionalException(io.pravega.test.common.IntentionalException) lombok.val(lombok.val) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) ChunkedSegmentStorageConfig(io.pravega.segmentstore.storage.chunklayer.ChunkedSegmentStorageConfig) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Rule(org.junit.Rule) Ignore(org.junit.Ignore) ThreadPooledTestSuite(io.pravega.test.common.ThreadPooledTestSuite) After(org.junit.After) Timeout(org.junit.rules.Timeout) Assert(org.junit.Assert) Futures(io.pravega.common.concurrent.Futures) Before(org.junit.Before) CompletableFuture(java.util.concurrent.CompletableFuture) MockStorageMetadata(io.pravega.segmentstore.storage.mocks.MockStorageMetadata) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) Test(org.junit.Test)

Aggregations

InMemoryMetadataStore (io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore)33 lombok.val (lombok.val)30 Test (org.junit.Test)25 Cleanup (lombok.Cleanup)20 BaseMetadataStore (io.pravega.segmentstore.storage.metadata.BaseMetadataStore)11 NoOpChunkStorage (io.pravega.segmentstore.storage.noop.NoOpChunkStorage)11 IntentionalException (io.pravega.test.common.IntentionalException)11 ByteArrayInputStream (java.io.ByteArrayInputStream)11 InMemoryTaskQueueManager (io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager)10 StorageFullException (io.pravega.segmentstore.storage.StorageFullException)9 StorageNotPrimaryException (io.pravega.segmentstore.storage.StorageNotPrimaryException)9 MockStorageMetadata (io.pravega.segmentstore.storage.mocks.MockStorageMetadata)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 CompletionException (java.util.concurrent.CompletionException)8 SegmentRollingPolicy (io.pravega.segmentstore.storage.SegmentRollingPolicy)6 StorageMetadataException (io.pravega.segmentstore.storage.metadata.StorageMetadataException)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 StorageMetadataVersionMismatchException (io.pravega.segmentstore.storage.metadata.StorageMetadataVersionMismatchException)5 StorageMetadataWritesFencedOutException (io.pravega.segmentstore.storage.metadata.StorageMetadataWritesFencedOutException)5 IOException (java.io.IOException)5