Search in sources :

Example 6 with ProtoMessage

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();
}
Also used : RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) ProtoMessage(alluxio.util.proto.ProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) Protocol(alluxio.proto.dataserver.Protocol)

Example 7 with ProtoMessage

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);
}
Also used : RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) ProtoMessage(alluxio.util.proto.ProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) DataNettyBufferV2(alluxio.network.protocol.databuffer.DataNettyBufferV2) Protocol(alluxio.proto.dataserver.Protocol) ByteBuf(io.netty.buffer.ByteBuf) DataBuffer(alluxio.network.protocol.databuffer.DataBuffer)

Example 8 with ProtoMessage

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());
}
Also used : RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) ProtoMessage(alluxio.util.proto.ProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) Protocol(alluxio.proto.dataserver.Protocol)

Example 9 with ProtoMessage

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);
}
Also used : RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) ProtoMessage(alluxio.util.proto.ProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) Protocol(alluxio.proto.dataserver.Protocol) DataBuffer(alluxio.network.protocol.databuffer.DataBuffer) Test(org.junit.Test)

Aggregations

Protocol (alluxio.proto.dataserver.Protocol)9 ProtoMessage (alluxio.util.proto.ProtoMessage)9 RPCProtoMessage (alluxio.network.protocol.RPCProtoMessage)8 DataBuffer (alluxio.network.protocol.databuffer.DataBuffer)5 DataNettyBufferV2 (alluxio.network.protocol.databuffer.DataNettyBufferV2)3 ByteBuf (io.netty.buffer.ByteBuf)2 IOException (java.io.IOException)2 Test (org.junit.Test)1