Search in sources :

Example 16 with InMemoryMetadataStore

use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.

the class StorageFactoryTests method testExtendedS3StorageFactoryCreator.

@Test
public void testExtendedS3StorageFactoryCreator() {
    StorageFactoryCreator factoryCreator = new ExtendedS3StorageFactoryCreator();
    val expected = new StorageFactoryInfo[] { StorageFactoryInfo.builder().name("EXTENDEDS3").storageLayoutType(StorageLayoutType.CHUNKED_STORAGE).build(), StorageFactoryInfo.builder().name("EXTENDEDS3").storageLayoutType(StorageLayoutType.ROLLING_STORAGE).build() };
    val factoryInfoList = factoryCreator.getStorageFactories();
    Assert.assertEquals(2, factoryInfoList.length);
    Assert.assertArrayEquals(expected, factoryInfoList);
    // Simple Storage
    ConfigSetup configSetup1 = mock(ConfigSetup.class);
    val config = ExtendedS3StorageConfig.builder().with(ExtendedS3StorageConfig.CONFIGURI, "http://127.0.0.1?identity=x&secretKey=x").with(ExtendedS3StorageConfig.BUCKET, "bucket").with(ExtendedS3StorageConfig.PREFIX, "samplePrefix").build();
    when(configSetup1.getConfig(any())).thenReturn(ChunkedSegmentStorageConfig.DEFAULT_CONFIG, config);
    val factory1 = factoryCreator.createFactory(expected[0], configSetup1, executorService());
    Assert.assertTrue(factory1 instanceof ExtendedS3SimpleStorageFactory);
    @Cleanup Storage storage1 = ((ExtendedS3SimpleStorageFactory) factory1).createStorageAdapter(42, new InMemoryMetadataStore(ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService()));
    Assert.assertTrue(storage1 instanceof ChunkedSegmentStorage);
    Assert.assertTrue(((ChunkedSegmentStorage) storage1).getChunkStorage() instanceof ExtendedS3ChunkStorage);
    // Legacy Storage
    ConfigSetup configSetup2 = mock(ConfigSetup.class);
    when(configSetup2.getConfig(any())).thenReturn(config);
    val factory2 = factoryCreator.createFactory(expected[1], configSetup2, executorService());
    Assert.assertTrue(factory2 instanceof ExtendedS3StorageFactory);
    @Cleanup Storage storage2 = factory2.createStorageAdapter();
    Assert.assertTrue(storage2 instanceof AsyncStorageWrapper);
    @Cleanup SyncStorage syncStorage = factory2.createSyncStorage();
    Assert.assertNotNull(syncStorage);
    AssertExtensions.assertThrows("createStorageAdapter should throw UnsupportedOperationException.", () -> factory1.createStorageAdapter(), ex -> ex instanceof UnsupportedOperationException);
}
Also used : lombok.val(lombok.val) SyncStorage(io.pravega.segmentstore.storage.SyncStorage) ExtendedS3ChunkStorage(io.pravega.storage.extendeds3.ExtendedS3ChunkStorage) StorageFactoryInfo(io.pravega.segmentstore.storage.StorageFactoryInfo) ChunkedSegmentStorage(io.pravega.segmentstore.storage.chunklayer.ChunkedSegmentStorage) Cleanup(lombok.Cleanup) Storage(io.pravega.segmentstore.storage.Storage) ChunkedSegmentStorage(io.pravega.segmentstore.storage.chunklayer.ChunkedSegmentStorage) ExtendedS3ChunkStorage(io.pravega.storage.extendeds3.ExtendedS3ChunkStorage) HDFSChunkStorage(io.pravega.storage.hdfs.HDFSChunkStorage) S3ChunkStorage(io.pravega.storage.s3.S3ChunkStorage) SyncStorage(io.pravega.segmentstore.storage.SyncStorage) FileSystemChunkStorage(io.pravega.storage.filesystem.FileSystemChunkStorage) ExtendedS3StorageFactory(io.pravega.storage.extendeds3.ExtendedS3StorageFactory) AsyncStorageWrapper(io.pravega.segmentstore.storage.AsyncStorageWrapper) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) S3StorageFactoryCreator(io.pravega.storage.s3.S3StorageFactoryCreator) HDFSStorageFactoryCreator(io.pravega.storage.hdfs.HDFSStorageFactoryCreator) StorageFactoryCreator(io.pravega.segmentstore.storage.StorageFactoryCreator) ExtendedS3StorageFactoryCreator(io.pravega.storage.extendeds3.ExtendedS3StorageFactoryCreator) FileSystemStorageFactoryCreator(io.pravega.storage.filesystem.FileSystemStorageFactoryCreator) ExtendedS3StorageFactoryCreator(io.pravega.storage.extendeds3.ExtendedS3StorageFactoryCreator) ExtendedS3SimpleStorageFactory(io.pravega.storage.extendeds3.ExtendedS3SimpleStorageFactory) ConfigSetup(io.pravega.segmentstore.storage.ConfigSetup) Test(org.junit.Test)

Example 17 with InMemoryMetadataStore

use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.

the class StorageFactoryTests method testFileSystemStorageFactoryCreator.

@Test
public void testFileSystemStorageFactoryCreator() {
    StorageFactoryCreator factoryCreator = new FileSystemStorageFactoryCreator();
    val expected = new StorageFactoryInfo[] { StorageFactoryInfo.builder().name("FILESYSTEM").storageLayoutType(StorageLayoutType.CHUNKED_STORAGE).build(), StorageFactoryInfo.builder().name("FILESYSTEM").storageLayoutType(StorageLayoutType.ROLLING_STORAGE).build() };
    val factoryInfoList = factoryCreator.getStorageFactories();
    Assert.assertEquals(2, factoryInfoList.length);
    Assert.assertArrayEquals(expected, factoryInfoList);
    // Simple Storage
    ConfigSetup configSetup1 = mock(ConfigSetup.class);
    when(configSetup1.getConfig(any())).thenReturn(ChunkedSegmentStorageConfig.DEFAULT_CONFIG, FileSystemStorageConfig.builder().build());
    val factory1 = factoryCreator.createFactory(expected[0], configSetup1, executorService());
    Assert.assertTrue(factory1 instanceof FileSystemSimpleStorageFactory);
    @Cleanup Storage storage1 = ((FileSystemSimpleStorageFactory) factory1).createStorageAdapter(42, new InMemoryMetadataStore(ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService()));
    Assert.assertTrue(storage1 instanceof ChunkedSegmentStorage);
    Assert.assertTrue(((ChunkedSegmentStorage) storage1).getChunkStorage() instanceof FileSystemChunkStorage);
    // Legacy Storage
    ConfigSetup configSetup2 = mock(ConfigSetup.class);
    when(configSetup2.getConfig(any())).thenReturn(FileSystemStorageConfig.builder().build());
    val factory2 = factoryCreator.createFactory(expected[1], configSetup2, executorService());
    Assert.assertTrue(factory2 instanceof FileSystemStorageFactory);
    Storage storage2 = factory2.createStorageAdapter();
    Assert.assertTrue(storage2 instanceof AsyncStorageWrapper);
    @Cleanup SyncStorage syncStorage = factory2.createSyncStorage();
    Assert.assertNotNull(syncStorage);
    AssertExtensions.assertThrows("createStorageAdapter should throw UnsupportedOperationException.", () -> factory1.createStorageAdapter(), ex -> ex instanceof UnsupportedOperationException);
}
Also used : lombok.val(lombok.val) SyncStorage(io.pravega.segmentstore.storage.SyncStorage) FileSystemStorageFactoryCreator(io.pravega.storage.filesystem.FileSystemStorageFactoryCreator) FileSystemStorageFactory(io.pravega.storage.filesystem.FileSystemStorageFactory) StorageFactoryInfo(io.pravega.segmentstore.storage.StorageFactoryInfo) ChunkedSegmentStorage(io.pravega.segmentstore.storage.chunklayer.ChunkedSegmentStorage) FileSystemSimpleStorageFactory(io.pravega.storage.filesystem.FileSystemSimpleStorageFactory) Cleanup(lombok.Cleanup) Storage(io.pravega.segmentstore.storage.Storage) ChunkedSegmentStorage(io.pravega.segmentstore.storage.chunklayer.ChunkedSegmentStorage) ExtendedS3ChunkStorage(io.pravega.storage.extendeds3.ExtendedS3ChunkStorage) HDFSChunkStorage(io.pravega.storage.hdfs.HDFSChunkStorage) S3ChunkStorage(io.pravega.storage.s3.S3ChunkStorage) SyncStorage(io.pravega.segmentstore.storage.SyncStorage) FileSystemChunkStorage(io.pravega.storage.filesystem.FileSystemChunkStorage) AsyncStorageWrapper(io.pravega.segmentstore.storage.AsyncStorageWrapper) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) S3StorageFactoryCreator(io.pravega.storage.s3.S3StorageFactoryCreator) HDFSStorageFactoryCreator(io.pravega.storage.hdfs.HDFSStorageFactoryCreator) StorageFactoryCreator(io.pravega.segmentstore.storage.StorageFactoryCreator) ExtendedS3StorageFactoryCreator(io.pravega.storage.extendeds3.ExtendedS3StorageFactoryCreator) FileSystemStorageFactoryCreator(io.pravega.storage.filesystem.FileSystemStorageFactoryCreator) ConfigSetup(io.pravega.segmentstore.storage.ConfigSetup) FileSystemChunkStorage(io.pravega.storage.filesystem.FileSystemChunkStorage) Test(org.junit.Test)

Example 18 with InMemoryMetadataStore

use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.

the class UtilsWrapperTests method testEvictReadIndexCache.

@Test
public void testEvictReadIndexCache() throws Exception {
    val config = ChunkedSegmentStorageConfig.DEFAULT_CONFIG;
    // Set up
    @Cleanup ChunkStorage chunkStorage = new InMemoryChunkStorage(executorService());
    @Cleanup val metadataStore = new InMemoryMetadataStore(config, executorService());
    @Cleanup ChunkedSegmentStorage chunkedSegmentStorage = new ChunkedSegmentStorage(42, chunkStorage, metadataStore, executorService(), config);
    chunkedSegmentStorage.initialize(123);
    val chunkSizes = new long[] { 1 };
    // Insert metadata
    TestUtils.insertMetadata("a", 42, 10, chunkSizes, chunkSizes, true, true, chunkedSegmentStorage.getMetadataStore(), chunkedSegmentStorage);
    TestUtils.insertMetadata("b", 42, 10, chunkSizes, chunkSizes, true, true, chunkedSegmentStorage.getMetadataStore(), chunkedSegmentStorage);
    TestUtils.insertMetadata("c", 42, 10, chunkSizes, chunkSizes, true, true, chunkedSegmentStorage.getMetadataStore(), chunkedSegmentStorage);
    // Test
    UtilsWrapper wrapper = new UtilsWrapper(chunkedSegmentStorage, 128, Duration.ZERO);
    wrapper.evictMetadataCache().join();
    Assert.assertNotNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("a", 0));
    Assert.assertNotNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("b", 0));
    Assert.assertNotNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("c", 0));
    wrapper.evictReadIndexCacheForSegment("a").join();
    Assert.assertNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("a", 0));
    Assert.assertNotNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("b", 0));
    Assert.assertNotNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("c", 0));
    wrapper.evictReadIndexCacheForSegment("b").join();
    Assert.assertNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("a", 0));
    Assert.assertNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("b", 0));
    Assert.assertNotNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("c", 0));
    wrapper.evictReadIndexCache().join();
    Assert.assertNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("a", 0));
    Assert.assertNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("b", 0));
    Assert.assertNull(wrapper.getChunkedSegmentStorage().getReadIndexCache().findFloor("c", 0));
}
Also used : lombok.val(lombok.val) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 19 with InMemoryMetadataStore

use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.

the class UtilsWrapperTests method testCopy.

private void testCopy(long[] chunkLengths) throws Exception {
    val config = ChunkedSegmentStorageConfig.DEFAULT_CONFIG;
    val segmentName = "test";
    // Set up
    @Cleanup ChunkStorage chunkStorage = new InMemoryChunkStorage(executorService());
    @Cleanup BaseMetadataStore metadataStore = new InMemoryMetadataStore(config, executorService());
    @Cleanup ChunkedSegmentStorage chunkedSegmentStorage = new ChunkedSegmentStorage(42, chunkStorage, metadataStore, executorService(), config);
    chunkedSegmentStorage.initialize(123);
    TestUtils.insertMetadata(segmentName, 25, 123, chunkLengths, chunkLengths, false, false, chunkedSegmentStorage.getMetadataStore(), chunkedSegmentStorage);
    val chunkMetadataList = TestUtils.getChunkList(chunkedSegmentStorage.getMetadataStore(), segmentName);
    // Test
    UtilsWrapper wrapper = new UtilsWrapper(chunkedSegmentStorage, 128, Duration.ZERO);
    byte[][] expected = new byte[chunkMetadataList.size()][];
    int sum = 0;
    for (int i = 0; i < chunkMetadataList.size(); i++) {
        val info = chunkMetadataList.get(i);
        val length = Math.toIntExact(info.getLength());
        // create random data
        expected[i] = new byte[length];
        random.nextBytes(expected[i]);
        // Overwrite chunk
        wrapper.overwriteChunk(info.getName(), new ByteArrayInputStream(expected[i]), length).join();
        val actual = new ByteArrayOutputStream(length);
        // read the same data back
        wrapper.copyFromChunk(info.getName(), actual).join();
        Assert.assertArrayEquals(expected[i], actual.toByteArray());
        sum += length;
    }
    // Read back and validate segment
    val segmentContents = new ByteArrayOutputStream(sum);
    wrapper.copyFromSegment(segmentName, segmentContents).join();
    long startOffset = 0;
    for (int i = 0; i < expected.length; i++) {
        assertContentEquals(segmentContents.toByteArray(), startOffset, expected[i]);
        startOffset += expected[i].length;
    }
}
Also used : lombok.val(lombok.val) BaseMetadataStore(io.pravega.segmentstore.storage.metadata.BaseMetadataStore) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) Cleanup(lombok.Cleanup) ByteArrayInputStream(java.io.ByteArrayInputStream) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore)

Example 20 with InMemoryMetadataStore

use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.

the class UtilsWrapperTests method testGetExtendedChunkInfoList.

private void testGetExtendedChunkInfoList(ChunkedSegmentStorageConfig config, String segmentName, boolean shouldCheckStorage, long[] lengthsInStorage, long[] lengthsInMetadata, int[] chunksToDelete) throws Exception {
    // Set up
    @Cleanup ChunkStorage chunkStorage = new InMemoryChunkStorage(executorService());
    @Cleanup BaseMetadataStore metadataStore = new InMemoryMetadataStore(config, executorService());
    @Cleanup ChunkedSegmentStorage chunkedSegmentStorage = new ChunkedSegmentStorage(42, chunkStorage, metadataStore, executorService(), config);
    chunkedSegmentStorage.initialize(123);
    // Insert metadata
    TestUtils.insertMetadata(segmentName, 25, 123, lengthsInMetadata, lengthsInStorage, false, false, metadataStore, chunkedSegmentStorage);
    val chunkMetadataList = TestUtils.getChunkList(metadataStore, segmentName);
    // Delete few chunks
    HashSet<String> deletedChunkNames = new HashSet<>();
    for (int i = 0; i < chunksToDelete.length; i++) {
        val name = chunkMetadataList.get(i).getName();
        deletedChunkNames.add(name);
        chunkStorage.delete(ChunkHandle.writeHandle(name)).join();
    }
    // Test
    UtilsWrapper wrapper = new UtilsWrapper(chunkedSegmentStorage, 128, Duration.ZERO);
    // check the output
    checkExtendedChunkInfoList(wrapper, segmentName, shouldCheckStorage, lengthsInStorage, deletedChunkNames, chunkMetadataList);
}
Also used : lombok.val(lombok.val) BaseMetadataStore(io.pravega.segmentstore.storage.metadata.BaseMetadataStore) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) Cleanup(lombok.Cleanup) HashSet(java.util.HashSet)

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