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());
}
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());
}
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());
}
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));
}
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));
}
Aggregations