use of alluxio.network.protocol.databuffer.DataFileChannel in project alluxio by Alluxio.
the class RPCMessageIntegrationTest method RPCBlockReadResponseFileChannel.
@Test
public void RPCBlockReadResponseFileChannel() throws IOException {
try (FileInputStream inputStream = getTempFileInputStream()) {
FileChannel payload = inputStream.getChannel();
RPCBlockReadResponse msg = new RPCBlockReadResponse(BLOCK_ID, OFFSET, LENGTH, new DataFileChannel(payload, OFFSET, LENGTH), RPCResponse.Status.SUCCESS);
RPCBlockReadResponse decoded = (RPCBlockReadResponse) encodeThenDecode(msg);
assertValid(msg, decoded);
}
}
use of alluxio.network.protocol.databuffer.DataFileChannel in project alluxio by Alluxio.
the class DataServerBlockReadHandler method getDataBuffer.
@Override
protected DataBuffer getDataBuffer(Channel channel, long offset, int len) throws IOException {
BlockReader blockReader = ((BlockReadRequestInternal) mRequest).mBlockReader;
Preconditions.checkArgument(blockReader.getChannel() instanceof FileChannel, "Only FileChannel is supported!");
switch(mTransferType) {
case MAPPED:
ByteBuf buf = channel.alloc().buffer(len, len);
try {
FileChannel fileChannel = (FileChannel) blockReader.getChannel();
Preconditions.checkState(fileChannel.position() == offset);
while (buf.writableBytes() > 0 && buf.writeBytes(fileChannel, buf.writableBytes()) != -1) {
}
return new DataNettyBufferV2(buf);
} catch (Throwable e) {
buf.release();
throw e;
}
// intend to fall through as TRANSFER is the default type.
case TRANSFER:
default:
return new DataFileChannel((FileChannel) blockReader.getChannel(), offset, len);
}
}
use of alluxio.network.protocol.databuffer.DataFileChannel in project alluxio by Alluxio.
the class DataServerReadHandlerTest method checkAllReadResponses.
/**
* Checks all the read responses.
*/
protected void checkAllReadResponses(EmbeddedChannel channel, long checksumExpected) {
boolean eof = false;
long checksumActual = 0;
while (!eof) {
Object readResponse = waitForOneResponse(channel);
if (readResponse == null) {
Assert.fail();
break;
}
DataBuffer buffer = checkReadResponse(readResponse, Protocol.Status.Code.OK);
eof = buffer == null;
if (buffer != null) {
if (buffer instanceof DataNettyBufferV2) {
ByteBuf buf = (ByteBuf) buffer.getNettyOutput();
while (buf.readableBytes() > 0) {
checksumActual += BufferUtils.byteToInt(buf.readByte());
}
buf.release();
} else {
Assert.assertTrue(buffer instanceof DataFileChannel);
ByteBuffer buf = buffer.getReadOnlyByteBuffer();
byte[] array = new byte[buf.remaining()];
buf.get(array);
for (int i = 0; i < array.length; i++) {
checksumActual += BufferUtils.byteToInt(array[i]);
}
}
}
}
Assert.assertEquals(checksumExpected, checksumActual);
Assert.assertTrue(eof);
}
Aggregations