Search in sources :

Example 6 with RPCResponse

use of alluxio.network.protocol.RPCResponse in project alluxio by Alluxio.

the class NettyDataServerTest method readBlock.

@Test
public void readBlock() throws Exception {
    long sessionId = 0;
    long blockId = 1;
    long offset = 2;
    long length = 3;
    long lockId = 4;
    when(mBlockWorker.readBlockRemote(sessionId, blockId, lockId)).thenReturn(new MockBlockReader("abcdefg".getBytes(Charsets.UTF_8)));
    RPCResponse response = request(new RPCBlockReadRequest(blockId, offset, length, lockId, sessionId));
    // Verify that the 3 bytes were read at offset 2.
    assertEquals("cde", Charsets.UTF_8.decode(response.getPayloadDataBuffer().getReadOnlyByteBuffer()).toString());
}
Also used : RPCBlockReadRequest(alluxio.network.protocol.RPCBlockReadRequest) RPCResponse(alluxio.network.protocol.RPCResponse) MockBlockReader(alluxio.worker.block.io.MockBlockReader) Test(org.junit.Test)

Example 7 with RPCResponse

use of alluxio.network.protocol.RPCResponse in project alluxio by Alluxio.

the class NettyDataServerTest method blockWorkerBlockDoesNotExistExceptionCausesFileDneStatus.

@Test
public void blockWorkerBlockDoesNotExistExceptionCausesFileDneStatus() throws Exception {
    when(mBlockWorker.readBlockRemote(anyLong(), anyLong(), anyLong())).thenThrow(new BlockDoesNotExistException(""));
    RPCResponse response = request(new RPCBlockReadRequest(1, 2, 3, 4, 0));
    // Verify that the read request failed with a FILE_DNE status.
    assertEquals(RPCResponse.Status.FILE_DNE, response.getStatus());
}
Also used : RPCBlockReadRequest(alluxio.network.protocol.RPCBlockReadRequest) RPCResponse(alluxio.network.protocol.RPCResponse) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) Test(org.junit.Test)

Example 8 with RPCResponse

use of alluxio.network.protocol.RPCResponse in project alluxio by Alluxio.

the class NettyDataServerTest method blockWorkerExceptionCausesFailStatusOnWrite.

@Test
public void blockWorkerExceptionCausesFailStatusOnWrite() throws Exception {
    long sessionId = 0;
    long blockId = 1;
    long offset = 0;
    long length = 2;
    when(mBlockWorker.getTempBlockWriterRemote(sessionId, blockId)).thenThrow(new RuntimeException());
    DataByteArrayChannel data = new DataByteArrayChannel("abc".getBytes(Charsets.UTF_8), 0, 3);
    RPCResponse response = request(new RPCBlockWriteRequest(sessionId, blockId, offset, length, data));
    // Verify that the write request failed.
    assertEquals(RPCResponse.Status.WRITE_ERROR, response.getStatus());
}
Also used : DataByteArrayChannel(alluxio.network.protocol.databuffer.DataByteArrayChannel) RPCBlockWriteRequest(alluxio.network.protocol.RPCBlockWriteRequest) RPCResponse(alluxio.network.protocol.RPCResponse) Test(org.junit.Test)

Example 9 with RPCResponse

use of alluxio.network.protocol.RPCResponse in project alluxio by Alluxio.

the class NettyDataServerTest method writeFile.

@Test
public void writeFile() throws Exception {
    long tempUfsFileId = 1;
    long offset = 0;
    long length = 3;
    DataByteArrayChannel data = new DataByteArrayChannel("abc".getBytes(Charsets.UTF_8), 0, 3);
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    when(mFileSystemWorker.getUfsOutputStream(tempUfsFileId)).thenReturn(outStream);
    RPCResponse response = request(new RPCFileWriteRequest(tempUfsFileId, offset, length, data));
    // Verify that the write request writes to the OutputStream returned by the worker.
    assertEquals(RPCResponse.Status.SUCCESS, response.getStatus());
    assertEquals("abc", new String(outStream.toByteArray(), Charsets.UTF_8));
}
Also used : DataByteArrayChannel(alluxio.network.protocol.databuffer.DataByteArrayChannel) RPCFileWriteRequest(alluxio.network.protocol.RPCFileWriteRequest) RPCResponse(alluxio.network.protocol.RPCResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 10 with RPCResponse

use of alluxio.network.protocol.RPCResponse in project alluxio by Alluxio.

the class NettyDataServerTest method writeExistingBlock.

@Test
public void writeExistingBlock() throws Exception {
    long sessionId = 0;
    long blockId = 1;
    // Offset is set to 1 so that the write is directed to an existing block
    long offset = 1;
    long length = 2;
    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 requests space on an existing block and then writes the
    // specified data.
    assertEquals(RPCResponse.Status.SUCCESS, response.getStatus());
    verify(mBlockWorker).requestSpace(sessionId, blockId, 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)

Aggregations

RPCResponse (alluxio.network.protocol.RPCResponse)16 Test (org.junit.Test)12 DataByteArrayChannel (alluxio.network.protocol.databuffer.DataByteArrayChannel)7 RPCBlockReadRequest (alluxio.network.protocol.RPCBlockReadRequest)5 RPCBlockWriteRequest (alluxio.network.protocol.RPCBlockWriteRequest)4 RPCErrorResponse (alluxio.network.protocol.RPCErrorResponse)4 Channel (io.netty.channel.Channel)4 ChannelFuture (io.netty.channel.ChannelFuture)4 IOException (java.io.IOException)4 RPCBlockReadResponse (alluxio.network.protocol.RPCBlockReadResponse)3 RPCFileWriteRequest (alluxio.network.protocol.RPCFileWriteRequest)3 RPCFileReadRequest (alluxio.network.protocol.RPCFileReadRequest)2 MockBlockWriter (alluxio.worker.block.io.MockBlockWriter)2 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)1 RPCBlockWriteResponse (alluxio.network.protocol.RPCBlockWriteResponse)1 RPCFileWriteResponse (alluxio.network.protocol.RPCFileWriteResponse)1 RPCUnderFileSystemBlockReadRequest (alluxio.network.protocol.RPCUnderFileSystemBlockReadRequest)1 DataBuffer (alluxio.network.protocol.databuffer.DataBuffer)1 MockBlockReader (alluxio.worker.block.io.MockBlockReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1