Search in sources :

Example 6 with BlockWriter

use of alluxio.worker.block.io.BlockWriter in project alluxio by Alluxio.

the class TieredBlockStoreTestUtils method createTempBlock.

/**
   * Makes a temp block of a given size in {@link StorageDir}.
   *
   * @param sessionId session who caches the data
   * @param blockId id of the cached block
   * @param bytes size of the block in bytes
   * @param dir the {@link StorageDir} the block resides in
   * @return the temp block meta
   * @throws Exception when fail to create this block
   */
public static TempBlockMeta createTempBlock(long sessionId, long blockId, long bytes, StorageDir dir) throws Exception {
    // prepare temp block
    TempBlockMeta tempBlockMeta = new TempBlockMeta(sessionId, blockId, bytes, dir);
    dir.addTempBlockMeta(tempBlockMeta);
    // write data
    FileUtils.createFile(tempBlockMeta.getPath());
    BlockWriter writer = new LocalFileBlockWriter(tempBlockMeta.getPath());
    writer.append(BufferUtils.getIncreasingByteBuffer(Ints.checkedCast(bytes)));
    writer.close();
    return tempBlockMeta;
}
Also used : LocalFileBlockWriter(alluxio.worker.block.io.LocalFileBlockWriter) BlockWriter(alluxio.worker.block.io.BlockWriter) LocalFileBlockWriter(alluxio.worker.block.io.LocalFileBlockWriter) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Aggregations

BlockWriter (alluxio.worker.block.io.BlockWriter)6 RestApiTest (alluxio.rest.RestApiTest)2 TestCase (alluxio.rest.TestCase)2 LocalFileBlockWriter (alluxio.worker.block.io.LocalFileBlockWriter)2 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)1 RPCBlockWriteResponse (alluxio.network.protocol.RPCBlockWriteResponse)1 DataBuffer (alluxio.network.protocol.databuffer.DataBuffer)1 DataByteBuffer (alluxio.network.protocol.databuffer.DataByteBuffer)1 ChannelFuture (io.netty.channel.ChannelFuture)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 ByteBuffer (java.nio.ByteBuffer)1 GatheringByteChannel (java.nio.channels.GatheringByteChannel)1