Search in sources :

Example 1 with MockBlockWriter

use of alluxio.worker.block.io.MockBlockWriter 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)

Example 2 with MockBlockWriter

use of alluxio.worker.block.io.MockBlockWriter 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)

Aggregations

RPCBlockWriteRequest (alluxio.network.protocol.RPCBlockWriteRequest)2 RPCResponse (alluxio.network.protocol.RPCResponse)2 DataByteArrayChannel (alluxio.network.protocol.databuffer.DataByteArrayChannel)2 MockBlockWriter (alluxio.worker.block.io.MockBlockWriter)2 Test (org.junit.Test)2