use of alluxio.worker.block.meta.BlockMeta in project alluxio by Alluxio.
the class BlockWorkerTest method moveBlock.
/**
* Tests the {@link BlockWorker#moveBlock(long, long, String)} method.
*/
@Test
public void moveBlock() throws Exception {
long blockId = mRandom.nextLong();
long sessionId = mRandom.nextLong();
String tierAlias = "MEM";
BlockStoreLocation location = BlockStoreLocation.anyDirInTier(tierAlias);
BlockStoreLocation existingLocation = Mockito.mock(BlockStoreLocation.class);
when(existingLocation.belongsTo(location)).thenReturn(false);
BlockMeta meta = Mockito.mock(BlockMeta.class);
when(meta.getBlockLocation()).thenReturn(existingLocation);
when(mBlockStore.getBlockMeta(Mockito.eq(sessionId), Mockito.eq(blockId), Mockito.anyLong())).thenReturn(meta);
mBlockWorker.moveBlock(sessionId, blockId, tierAlias);
verify(mBlockStore).moveBlock(sessionId, blockId, location);
}
use of alluxio.worker.block.meta.BlockMeta in project alluxio by Alluxio.
the class BlockWorkerTest method readBlock.
/**
* Tests the {@link BlockWorker#readBlock(long, long, long)} method.
*/
@Test
public void readBlock() throws Exception {
long blockId = mRandom.nextLong();
long sessionId = mRandom.nextLong();
long lockId = mRandom.nextLong();
long blockSize = mRandom.nextLong();
StorageDir storageDir = Mockito.mock(StorageDir.class);
when(storageDir.getDirPath()).thenReturn("/tmp");
BlockMeta meta = new BlockMeta(blockId, blockSize, storageDir);
when(mBlockStore.getBlockMeta(sessionId, blockId, lockId)).thenReturn(meta);
mBlockWorker.readBlock(sessionId, blockId, lockId);
verify(mBlockStore).getBlockMeta(sessionId, blockId, lockId);
assertEquals(PathUtils.concatPath("/tmp", blockId), mBlockWorker.readBlock(sessionId, blockId, lockId));
}
use of alluxio.worker.block.meta.BlockMeta in project alluxio by Alluxio.
the class BlockWorkerTest method commitBlock.
/**
* Tests the {@link BlockWorker#commitBlock(long, long)} method.
*/
@Test
public void commitBlock() throws Exception {
long blockId = mRandom.nextLong();
long length = mRandom.nextLong();
long lockId = mRandom.nextLong();
long sessionId = mRandom.nextLong();
long usedBytes = mRandom.nextLong();
String tierAlias = "MEM";
HashMap<String, Long> usedBytesOnTiers = new HashMap<>();
usedBytesOnTiers.put(tierAlias, usedBytes);
BlockMeta blockMeta = PowerMockito.mock(BlockMeta.class);
BlockStoreLocation blockStoreLocation = PowerMockito.mock(BlockStoreLocation.class);
BlockStoreMeta blockStoreMeta = PowerMockito.mock(BlockStoreMeta.class);
when(mBlockStore.lockBlock(sessionId, blockId)).thenReturn(lockId);
when(mBlockStore.getBlockMeta(sessionId, blockId, lockId)).thenReturn(blockMeta);
when(mBlockStore.getBlockStoreMeta()).thenReturn(blockStoreMeta);
when(mBlockStore.getBlockStoreMetaFull()).thenReturn(blockStoreMeta);
when(blockMeta.getBlockLocation()).thenReturn(blockStoreLocation);
when(blockStoreLocation.tierAlias()).thenReturn(tierAlias);
when(blockMeta.getBlockSize()).thenReturn(length);
when(blockStoreMeta.getUsedBytesOnTiers()).thenReturn(usedBytesOnTiers);
mBlockWorker.commitBlock(sessionId, blockId);
verify(mBlockMasterClient).commitBlock(anyLong(), eq(usedBytes), eq(tierAlias), eq(blockId), eq(length));
verify(mBlockStore).unlockBlock(lockId);
}
use of alluxio.worker.block.meta.BlockMeta in project alluxio by Alluxio.
the class AllocatorTestBase method assertTempBlockMeta.
/**
* Given an allocator with the location, blockSize, tierAlias and dirIndex,
* we assert whether the block can be allocated.
*
* @param allocator the allocation manager of Alluxio managed data
* @param location the location in block store
* @param blockSize the size of block in bytes
* @param avail the block should be successfully allocated or not
* @param tierAlias the block should be allocated at this tier
* @param dirIndex the block should be allocated at this dir
*/
protected void assertTempBlockMeta(Allocator allocator, BlockStoreLocation location, int blockSize, boolean avail, String tierAlias, int dirIndex) throws Exception {
mTestBlockId++;
StorageDirView dirView = allocator.allocateBlockWithView(SESSION_ID, blockSize, location, getManagerView());
TempBlockMeta tempBlockMeta = dirView == null ? null : dirView.createTempBlockMeta(SESSION_ID, mTestBlockId, blockSize);
if (!avail) {
Assert.assertTrue(tempBlockMeta == null);
} else {
Assert.assertTrue(tempBlockMeta != null);
StorageDir pDir = tempBlockMeta.getParentDir();
StorageTier pTier = pDir.getParentTier();
Assert.assertTrue(pDir.getDirIndex() == dirIndex);
Assert.assertEquals(tierAlias, pTier.getTierAlias());
//update the dir meta info
pDir.addBlockMeta(new BlockMeta(mTestBlockId, blockSize, pDir));
}
}
Aggregations