use of alluxio.util.proto.ProtoMessage in project alluxio by Alluxio.
the class DataServerReadHandlerTest method checkReadResponse.
/**
* Checks the read response message given the expected error code.
*
* @param readResponse the read response
* @param codeExpected the expected error code
* @return the data buffer extracted from the read response
*/
protected DataBuffer checkReadResponse(Object readResponse, Protocol.Status.Code codeExpected) {
Assert.assertTrue(readResponse instanceof RPCProtoMessage);
ProtoMessage response = ((RPCProtoMessage) readResponse).getMessage();
Assert.assertTrue(response.getType() == ProtoMessage.Type.RESPONSE);
Assert.assertEquals(codeExpected, response.<Protocol.Response>getMessage().getStatus().getCode());
return ((RPCProtoMessage) readResponse).getPayloadDataBuffer();
}
use of alluxio.util.proto.ProtoMessage in project alluxio by Alluxio.
the class DataServerUFSFileWriteHandlerTest method buildWriteRequest.
@Override
protected RPCProtoMessage buildWriteRequest(long offset, int len) {
Protocol.WriteRequest writeRequest = Protocol.WriteRequest.newBuilder().setId(1L).setOffset(offset).setType(Protocol.RequestType.UFS_FILE).build();
DataBuffer buffer = null;
if (len > 0) {
ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(len);
for (int i = 0; i < len; i++) {
byte value = (byte) (mRandom.nextInt() % Byte.MAX_VALUE);
buf.writeByte(value);
mChecksum += BufferUtils.byteToInt(value);
}
buffer = new DataNettyBufferV2(buf);
}
return new RPCProtoMessage(new ProtoMessage(writeRequest), buffer);
}
use of alluxio.util.proto.ProtoMessage in project alluxio by Alluxio.
the class DataServerWriteHandlerTest method checkWriteResponse.
/**
* Checks the given write response is expected and matches the given error code.
*
* @param writeResponse the write response
* @param codeExpected the expected error code
*/
protected void checkWriteResponse(Object writeResponse, Protocol.Status.Code codeExpected) {
Assert.assertTrue(writeResponse instanceof RPCProtoMessage);
ProtoMessage response = ((RPCProtoMessage) writeResponse).getMessage();
Assert.assertTrue(response.getType() == ProtoMessage.Type.RESPONSE);
Assert.assertEquals(codeExpected, response.<Protocol.Response>getMessage().getStatus().getCode());
}
use of alluxio.util.proto.ProtoMessage in project alluxio by Alluxio.
the class DataServerReadHandlerTest method cancelRequest.
/**
* Cancels the read request immediately after the read request is sent.
*/
@Test
public void cancelRequest() throws Exception {
long fileSize = PACKET_SIZE * 10 + 1;
populateInputFile(fileSize, 0, fileSize - 1);
RPCProtoMessage readRequest = buildReadRequest(0, fileSize);
Protocol.ReadRequest request = readRequest.getMessage().getMessage();
RPCProtoMessage cancelRequest = new RPCProtoMessage(new ProtoMessage(request.toBuilder().setCancel(true).build()), null);
mChannel.writeInbound(readRequest);
mChannel.writeInbound(cancelRequest);
// Make sure we can still get EOF after cancelling though the read request is not necessarily
// fulfilled.
boolean eof = false;
long maxIterations = 100;
while (maxIterations > 0) {
Object response = waitForOneResponse(mChannel);
DataBuffer buffer = checkReadResponse(response, Protocol.Status.Code.OK);
if (buffer == null) {
eof = true;
break;
}
buffer.release();
maxIterations--;
Assert.assertTrue(mChannel.isOpen());
}
Assert.assertTrue(eof);
}
Aggregations