use of alluxio.network.protocol.RPCFileReadRequest in project alluxio by Alluxio.
the class DataServerHandler method channelRead0.
@Override
public void channelRead0(final ChannelHandlerContext ctx, final RPCMessage msg) throws IOException {
LOG.debug("Enter: {}", msg);
try {
switch(msg.getType()) {
case RPC_BLOCK_READ_REQUEST:
assert msg instanceof RPCBlockReadRequest;
mBlockHandler.handleBlockReadRequest(ctx, (RPCBlockReadRequest) msg);
break;
case RPC_BLOCK_WRITE_REQUEST:
assert msg instanceof RPCBlockWriteRequest;
mBlockHandler.handleBlockWriteRequest(ctx, (RPCBlockWriteRequest) msg);
break;
case RPC_FILE_READ_REQUEST:
assert msg instanceof RPCFileReadRequest;
mUnderFileSystemHandler.handleFileReadRequest(ctx, (RPCFileReadRequest) msg);
break;
case RPC_FILE_WRITE_REQUEST:
assert msg instanceof RPCFileWriteRequest;
mUnderFileSystemHandler.handleFileWriteRequest(ctx, (RPCFileWriteRequest) msg);
break;
case RPC_UFS_BLOCK_READ_REQUEST:
assert msg instanceof RPCUnderFileSystemBlockReadRequest;
mBlockHandler.handleUnderFileSystemBlockReadRequest(ctx, (RPCUnderFileSystemBlockReadRequest) msg);
break;
case RPC_ERROR_RESPONSE:
assert msg instanceof RPCErrorResponse;
LOG.error("Received an error response from the client: " + msg.toString());
break;
case RPC_READ_REQUEST:
case RPC_WRITE_REQUEST:
case RPC_RESPONSE:
assert msg instanceof RPCProtoMessage;
ctx.fireChannelRead(msg);
break;
default:
RPCErrorResponse resp = new RPCErrorResponse(RPCResponse.Status.UNKNOWN_MESSAGE_ERROR);
ctx.writeAndFlush(resp);
// TODO(peis): Fix this. We should not throw an exception here.
throw new IllegalArgumentException("No handler implementation for " + msg.getType());
}
} catch (IllegalArgumentException | IOException e) {
LOG.warn("{}, Error={}", msg, e.getMessage());
LOG.debug("{}", msg, e);
LOG.debug("Exit (Error): {}, Error={}", msg, e.getMessage());
// Rethrow the exception to use Netty's control flow.
throw e;
}
LOG.debug("Exit (OK): {}", msg);
}
use of alluxio.network.protocol.RPCFileReadRequest in project alluxio by Alluxio.
the class NettyDataServerTest method readFile.
@Test
public void readFile() throws Exception {
long tempUfsFileId = 1;
long offset = 0;
long length = 3;
when(mFileSystemWorker.getUfsInputStream(tempUfsFileId, offset)).thenReturn(new ByteArrayInputStream("abc".getBytes(Charsets.UTF_8)));
RPCResponse response = request(new RPCFileReadRequest(tempUfsFileId, offset, length));
// Verify that the 3 bytes were read.
assertEquals("abc", Charsets.UTF_8.decode(response.getPayloadDataBuffer().getReadOnlyByteBuffer()).toString());
}
use of alluxio.network.protocol.RPCFileReadRequest in project alluxio by Alluxio.
the class NettyDataServerTest method fileSystemWorkerExceptionCausesFailStatusOnRead.
@Test
public void fileSystemWorkerExceptionCausesFailStatusOnRead() throws Exception {
when(mFileSystemWorker.getUfsInputStream(1, 0)).thenThrow(new RuntimeException());
RPCResponse response = request(new RPCFileReadRequest(1, 0, 3));
// Verify that the write request failed.
assertEquals(RPCResponse.Status.UFS_READ_FAILED, response.getStatus());
}
Aggregations