Search in sources :

Example 21 with DataBuffer

use of alluxio.network.protocol.databuffer.DataBuffer 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

DataBuffer (alluxio.network.protocol.databuffer.DataBuffer)21 IOException (java.io.IOException)7 RPCProtoMessage (alluxio.network.protocol.RPCProtoMessage)6 DataByteBuffer (alluxio.network.protocol.databuffer.DataByteBuffer)6 ByteBuf (io.netty.buffer.ByteBuf)6 DataNettyBufferV2 (alluxio.network.protocol.databuffer.DataNettyBufferV2)5 Protocol (alluxio.proto.dataserver.Protocol)5 ProtoMessage (alluxio.util.proto.ProtoMessage)5 ChannelFuture (io.netty.channel.ChannelFuture)5 ByteBuffer (java.nio.ByteBuffer)5 RPCBlockReadResponse (alluxio.network.protocol.RPCBlockReadResponse)4 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)3 Test (org.junit.Test)3 DataNettyBuffer (alluxio.network.protocol.databuffer.DataNettyBuffer)2 BlockReader (alluxio.worker.block.io.BlockReader)2 RPCBlockWriteResponse (alluxio.network.protocol.RPCBlockWriteResponse)1 RPCFileReadResponse (alluxio.network.protocol.RPCFileReadResponse)1 RPCFileWriteResponse (alluxio.network.protocol.RPCFileWriteResponse)1 RPCResponse (alluxio.network.protocol.RPCResponse)1 DataFileChannel (alluxio.network.protocol.databuffer.DataFileChannel)1