Search in sources :

Example 11 with InMemoryMetadataStore

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();
}
Also used : lombok.val(lombok.val) BaseMetadataStore(io.pravega.segmentstore.storage.metadata.BaseMetadataStore) InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) Cleanup(lombok.Cleanup) NoOpChunkStorage(io.pravega.segmentstore.storage.noop.NoOpChunkStorage) StorageNotPrimaryException(io.pravega.segmentstore.storage.StorageNotPrimaryException) StorageFullException(io.pravega.segmentstore.storage.StorageFullException) StorageMetadataWritesFencedOutException(io.pravega.segmentstore.storage.metadata.StorageMetadataWritesFencedOutException) IntentionalException(io.pravega.test.common.IntentionalException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) StorageMetadataException(io.pravega.segmentstore.storage.metadata.StorageMetadataException) StorageMetadataVersionMismatchException(io.pravega.segmentstore.storage.metadata.StorageMetadataVersionMismatchException) Test(org.junit.Test)

Example 12 with InMemoryMetadataStore

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()));
}
Also used : lombok.val(lombok.val) BaseMetadataStore(io.pravega.segmentstore.storage.metadata.BaseMetadataStore) SegmentRollingPolicy(io.pravega.segmentstore.storage.SegmentRollingPolicy) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException) Cleanup(lombok.Cleanup) NoOpChunkStorage(io.pravega.segmentstore.storage.noop.NoOpChunkStorage) StorageNotPrimaryException(io.pravega.segmentstore.storage.StorageNotPrimaryException) StorageFullException(io.pravega.segmentstore.storage.StorageFullException) StorageMetadataWritesFencedOutException(io.pravega.segmentstore.storage.metadata.StorageMetadataWritesFencedOutException) IntentionalException(io.pravega.test.common.IntentionalException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) StorageMetadataException(io.pravega.segmentstore.storage.metadata.StorageMetadataException) StorageMetadataVersionMismatchException(io.pravega.segmentstore.storage.metadata.StorageMetadataVersionMismatchException) InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) ByteArrayInputStream(java.io.ByteArrayInputStream) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) Test(org.junit.Test)

Example 13 with InMemoryMetadataStore

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);
    }
}
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 14 with InMemoryMetadataStore

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);
    }
}
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 15 with InMemoryMetadataStore

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();
    }
}
Also used : lombok.val(lombok.val) 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