Search in sources :

Example 1 with ConcatArgument

use of io.pravega.segmentstore.storage.chunklayer.ConcatArgument in project pravega by pravega.

the class FileSystemChunkStorageMockTest method testWithRandomException.

@Test
public void testWithRandomException() throws Exception {
    String chunkName = "test";
    FileSystemWrapper fileSystemWrapper = mock(FileSystemWrapper.class);
    when(fileSystemWrapper.getFileSize(any())).thenThrow(new IOException("Random"));
    when(fileSystemWrapper.getFileChannel(any(), any())).thenThrow(new IOException("Random"));
    when(fileSystemWrapper.setPermissions(any(), any())).thenThrow(new IOException("Random"));
    when(fileSystemWrapper.createDirectories(any())).thenThrow(new IOException("Random"));
    doThrow(new IOException("Random")).when(fileSystemWrapper).delete(any());
    @Cleanup FileSystemChunkStorage testStorage = new FileSystemChunkStorage(storageConfig, fileSystemWrapper, executorService());
    AssertExtensions.assertThrows(" doDelete should throw ChunkStorageException.", () -> testStorage.doDelete(ChunkHandle.writeHandle(chunkName)), ex -> ex instanceof ChunkStorageException && ex.getCause() instanceof IOException && ex.getCause().getMessage().equals("Random"));
    AssertExtensions.assertThrows(" doSetReadOnly should throw ChunkStorageException.", () -> testStorage.doSetReadOnly(ChunkHandle.writeHandle(chunkName), false), ex -> ex instanceof ChunkStorageException && ex.getCause() instanceof IOException && ex.getCause().getMessage().equals("Random"));
    AssertExtensions.assertThrows(" doGetInfo should throw ChunkStorageException.", () -> testStorage.doGetInfo(chunkName), ex -> ex instanceof ChunkStorageException && ex.getCause() instanceof IOException && ex.getCause().getMessage().equals("Random"));
    AssertExtensions.assertThrows(" create should throw ChunkStorageException.", () -> testStorage.doCreate(chunkName), ex -> ex instanceof ChunkStorageException && ex.getCause() instanceof IOException && ex.getCause().getMessage().equals("Random"));
    AssertExtensions.assertFutureThrows(" write should throw exception.", testStorage.write(ChunkHandle.writeHandle(chunkName), 0, 1, new ByteArrayInputStream(new byte[1])), ex -> ex instanceof ChunkStorageException && ex.getCause() instanceof IOException && ex.getCause().getMessage().equals("Random"));
    AssertExtensions.assertFutureThrows(" read should throw exception.", testStorage.read(ChunkHandle.writeHandle(chunkName), 0, 1, new byte[1], 0), ex -> ex instanceof ChunkStorageException && ex.getCause() instanceof IOException && ex.getCause().getMessage().equals("Random"));
    AssertExtensions.assertFutureThrows(" concat should throw exception.", testStorage.concat(new ConcatArgument[] { ConcatArgument.builder().name("A").length(0).build(), ConcatArgument.builder().name("B").length(1).build() }), ex -> ex instanceof ChunkStorageException && ex.getCause() instanceof IOException && ex.getCause().getMessage().equals("Random"));
}
Also used : ConcatArgument(io.pravega.segmentstore.storage.chunklayer.ConcatArgument) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Cleanup(lombok.Cleanup) ChunkStorageException(io.pravega.segmentstore.storage.chunklayer.ChunkStorageException) Test(org.junit.Test)

Example 2 with ConcatArgument

use of io.pravega.segmentstore.storage.chunklayer.ConcatArgument in project pravega by pravega.

the class InMemoryChunkStorage method concatAtExactLengths.

private int concatAtExactLengths(ConcatArgument[] chunks) throws ChunkStorageException {
    int total = Math.toIntExact(chunks[0].getLength());
    final InMemoryChunk targetChunk = getInMemoryChunk(chunks[0].getName());
    synchronized (targetChunk) {
        targetChunk.truncate(chunks[0].getLength());
        for (int i = 1; i < chunks.length; i++) {
            ConcatArgument source = chunks[i];
            InMemoryChunk chunk = getInMemoryChunk(source.getName());
            chunk.truncate(chunks[i].getLength());
            for (InMemoryChunkData inMemoryChunkData : chunk.getInMemoryChunkDataList()) {
                targetChunk.append(inMemoryChunkData.getData());
            }
            total += chunks[i].getLength();
        }
        return total;
    }
}
Also used : ConcatArgument(io.pravega.segmentstore.storage.chunklayer.ConcatArgument)

Example 3 with ConcatArgument

use of io.pravega.segmentstore.storage.chunklayer.ConcatArgument in project pravega by pravega.

the class NoOpChunkStorage method doConcat.

@Override
protected int doConcat(ConcatArgument[] chunks) throws ChunkStorageException {
    int total = 0;
    for (ConcatArgument chunk : chunks) {
        val chunkData = chunkMetadata.get(chunk.getName());
        if (null == chunkData) {
            throw new ChunkNotFoundException(chunk.getName(), "NoOpChunkStorage::doConcat");
        }
        Preconditions.checkState(chunkData.length >= chunk.getLength());
        total += chunk.getLength();
    }
    val targetChunkData = chunkMetadata.get(chunks[0].getName());
    targetChunkData.length = total;
    return total;
}
Also used : ConcatArgument(io.pravega.segmentstore.storage.chunklayer.ConcatArgument) lombok.val(lombok.val) ChunkNotFoundException(io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException)

Aggregations

ConcatArgument (io.pravega.segmentstore.storage.chunklayer.ConcatArgument)3 ChunkNotFoundException (io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException)1 ChunkStorageException (io.pravega.segmentstore.storage.chunklayer.ChunkStorageException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Cleanup (lombok.Cleanup)1 lombok.val (lombok.val)1 Test (org.junit.Test)1