use of io.pravega.segmentstore.storage.chunklayer.ChunkHandle in project pravega by pravega.
the class FileSystemChunkStorageMockTest method doReadTest.
private void doReadTest(int index, int bufferSize) throws Exception {
String chunkName = "test";
// Set up mocks.
FileChannel channel = mock(FileChannel.class);
fixChannelMock(channel);
FileSystemWrapper fileSystemWrapper = mock(FileSystemWrapper.class);
when(fileSystemWrapper.getFileChannel(any(), any())).thenReturn(channel);
when(fileSystemWrapper.getFileSize(any())).thenReturn(2L * bufferSize);
@Cleanup FileSystemChunkStorage testStorage = new FileSystemChunkStorage(storageConfig, fileSystemWrapper, executorService());
ChunkHandle handle = ChunkHandle.readHandle(chunkName);
// Force two reads.
ArgumentCaptor<Long> expectedArgs = ArgumentCaptor.forClass(Long.class);
when(channel.read(any(), anyLong())).thenReturn(index, bufferSize - index);
// Call method.
byte[] buffer = new byte[bufferSize];
testStorage.doRead(handle, 0, bufferSize, buffer, 0);
// Verify.
verify(channel, times(2)).read(any(), expectedArgs.capture());
List<Long> actualArgs = expectedArgs.getAllValues();
assertEquals(2, actualArgs.size());
assertEquals(0, actualArgs.get(0).longValue());
assertEquals(index, actualArgs.get(1).longValue());
}
use of io.pravega.segmentstore.storage.chunklayer.ChunkHandle in project pravega by pravega.
the class InMemoryChunkStorage method doCreateWithContent.
@Override
protected ChunkHandle doCreateWithContent(String chunkName, int length, InputStream data) throws ChunkStorageException {
Preconditions.checkNotNull(chunkName);
if (null != chunks.putIfAbsent(chunkName, new InMemoryChunk(chunkName))) {
throw new ChunkAlreadyExistsException(chunkName, "InMemoryChunkStorage::doCreate");
}
ChunkHandle handle = new ChunkHandle(chunkName, false);
int bytesWritten = doWriteInternal(handle, 0, length, data);
if (bytesWritten < length) {
doDelete(ChunkHandle.writeHandle(chunkName));
throw new ChunkStorageException(chunkName, "doCreateWithContent - invalid length returned");
}
return handle;
}
Aggregations