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"));
}
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;
}
}
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;
}
Aggregations