Search in sources :

Example 1 with InMemoryChunkStorage

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

the class NoAppendSimpleStorageTests method getNoAppendInMemoryChunkStorage.

protected static InMemoryChunkStorage getNoAppendInMemoryChunkStorage(Executor executor) {
    val ret = new InMemoryChunkStorage(executor);
    ret.setShouldSupportAppend(false);
    return ret;
}
Also used : lombok.val(lombok.val) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage)

Example 2 with InMemoryChunkStorage

use of io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage 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 3 with InMemoryChunkStorage

use of io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage 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 4 with InMemoryChunkStorage

use of io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage 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)

Example 5 with InMemoryChunkStorage

use of io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage 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)

Aggregations

InMemoryChunkStorage (io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage)5 lombok.val (lombok.val)5 InMemoryMetadataStore (io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore)4 Cleanup (lombok.Cleanup)4 BaseMetadataStore (io.pravega.segmentstore.storage.metadata.BaseMetadataStore)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1