Search in sources :

Example 6 with DataByteArrayChannel

use of alluxio.network.protocol.databuffer.DataByteArrayChannel in project alluxio by Alluxio.

the class NettyDataServerTest method writeNewBlock.

@Test
public void writeNewBlock() throws Exception {
    long sessionId = 0;
    long blockId = 1;
    long length = 2;
    // Offset is set to 0 so that a new block will be created.
    long offset = 0;
    DataByteArrayChannel data = new DataByteArrayChannel("abc".getBytes(Charsets.UTF_8), 0, 3);
    MockBlockWriter blockWriter = new MockBlockWriter();
    when(mBlockWorker.getTempBlockWriterRemote(sessionId, blockId)).thenReturn(blockWriter);
    RPCResponse response = request(new RPCBlockWriteRequest(sessionId, blockId, offset, length, data));
    // Verify that the write request tells the worker to create a new block and write the specified
    // data to it.
    assertEquals(RPCResponse.Status.SUCCESS, response.getStatus());
    verify(mBlockWorker).createBlockRemote(sessionId, blockId, "MEM", length);
    assertEquals("ab", new String(blockWriter.getBytes(), Charsets.UTF_8));
}
Also used : DataByteArrayChannel(alluxio.network.protocol.databuffer.DataByteArrayChannel) RPCBlockWriteRequest(alluxio.network.protocol.RPCBlockWriteRequest) MockBlockWriter(alluxio.worker.block.io.MockBlockWriter) RPCResponse(alluxio.network.protocol.RPCResponse) Test(org.junit.Test)

Example 7 with DataByteArrayChannel

use of alluxio.network.protocol.databuffer.DataByteArrayChannel in project alluxio by Alluxio.

the class NettyDataServerTest method fileSystemWorkerExceptionCausesFailStatusOnWrite.

@Test
public void fileSystemWorkerExceptionCausesFailStatusOnWrite() throws Exception {
    DataByteArrayChannel data = new DataByteArrayChannel("abc".getBytes(Charsets.UTF_8), 0, 3);
    when(mFileSystemWorker.getUfsOutputStream(1)).thenThrow(new RuntimeException());
    RPCResponse response = request(new RPCFileWriteRequest(1, 0, 3, data));
    // Verify that the write request failed.
    assertEquals(RPCResponse.Status.UFS_WRITE_FAILED, response.getStatus());
}
Also used : DataByteArrayChannel(alluxio.network.protocol.databuffer.DataByteArrayChannel) RPCFileWriteRequest(alluxio.network.protocol.RPCFileWriteRequest) RPCResponse(alluxio.network.protocol.RPCResponse) Test(org.junit.Test)

Aggregations

RPCResponse (alluxio.network.protocol.RPCResponse)7 DataByteArrayChannel (alluxio.network.protocol.databuffer.DataByteArrayChannel)7 Test (org.junit.Test)5 RPCBlockWriteRequest (alluxio.network.protocol.RPCBlockWriteRequest)4 RPCFileWriteRequest (alluxio.network.protocol.RPCFileWriteRequest)3 RPCErrorResponse (alluxio.network.protocol.RPCErrorResponse)2 MockBlockWriter (alluxio.worker.block.io.MockBlockWriter)2 Channel (io.netty.channel.Channel)2 ChannelFuture (io.netty.channel.ChannelFuture)2 IOException (java.io.IOException)2 RPCBlockWriteResponse (alluxio.network.protocol.RPCBlockWriteResponse)1 RPCFileWriteResponse (alluxio.network.protocol.RPCFileWriteResponse)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1