use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class BlockWorkerTest method createBlock.
/**
* Tests the {@link BlockWorker#createBlock(long, long, String, long)} method.
*/
@Test
public void createBlock() throws Exception {
long blockId = mRandom.nextLong();
long initialBytes = mRandom.nextLong();
long sessionId = mRandom.nextLong();
String tierAlias = "MEM";
BlockStoreLocation location = BlockStoreLocation.anyDirInTier(tierAlias);
StorageDir storageDir = Mockito.mock(StorageDir.class);
TempBlockMeta meta = new TempBlockMeta(sessionId, blockId, initialBytes, storageDir);
when(mBlockStore.createBlock(sessionId, blockId, location, initialBytes)).thenReturn(meta);
when(storageDir.getDirPath()).thenReturn("/tmp");
assertEquals(PathUtils.concatPath("/tmp", ".tmp_blocks", sessionId % 1024, String.format("%x-%x", sessionId, blockId)), mBlockWorker.createBlock(sessionId, blockId, tierAlias, initialBytes));
}
use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class TieredBlockStoreTest method createBlockMetaWithoutEviction.
/**
* Tests the {@link TieredBlockStore#createBlock(long, long, BlockStoreLocation, long)} method
* to work without eviction.
*/
@Test
public void createBlockMetaWithoutEviction() throws Exception {
TempBlockMeta tempBlockMeta = mBlockStore.createBlock(SESSION_ID1, TEMP_BLOCK_ID, mTestDir1.toBlockStoreLocation(), 1);
Assert.assertEquals(1, tempBlockMeta.getBlockSize());
Assert.assertEquals(mTestDir1, tempBlockMeta.getParentDir());
}
use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class TieredBlockStoreTestUtils method cache.
/**
* Caches bytes into {@link BlockStore} at specific location.
*
* @param sessionId session who caches the data
* @param blockId id of the cached block
* @param bytes size of the block in bytes
* @param blockStore block store that the block is written into
* @param location the location where the block resides
* @throws Exception when fail to cache
*/
public static void cache(long sessionId, long blockId, long bytes, BlockStore blockStore, BlockStoreLocation location) throws Exception {
TempBlockMeta tempBlockMeta = blockStore.createBlock(sessionId, blockId, location, bytes);
// write data
FileUtils.createFile(tempBlockMeta.getPath());
BlockWriter writer = new LocalFileBlockWriter(tempBlockMeta.getPath());
writer.append(BufferUtils.getIncreasingByteBuffer(Ints.checkedCast(bytes)));
writer.close();
// commit block
blockStore.commitBlock(sessionId, blockId);
}
use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class TieredBlockStoreTestUtils method cache.
/**
* Caches bytes into {@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
* @param meta the metadata manager to update meta of the block
* @param evictor the evictor to be informed of the new block
* @throws Exception when fail to cache
*/
public static void cache(long sessionId, long blockId, long bytes, StorageDir dir, BlockMetadataManager meta, Evictor evictor) throws Exception {
TempBlockMeta tempBlockMeta = createTempBlock(sessionId, blockId, bytes, dir);
// commit block
FileUtils.move(tempBlockMeta.getPath(), tempBlockMeta.getCommitPath());
meta.commitTempBlockMeta(tempBlockMeta);
// update evictor
if (evictor instanceof BlockStoreEventListener) {
((BlockStoreEventListener) evictor).onCommitBlock(sessionId, blockId, dir.toBlockStoreLocation());
}
}
use of alluxio.worker.block.meta.TempBlockMeta 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;
}
Aggregations