use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockMetadataManagerTest method moveBlockMetaDeprecatedExceedCapacity.
/**
* Tests that an exception is thrown in the
* {@link BlockMetadataManager#moveBlockMeta(BlockMeta, BlockStoreLocation)} method when the
* capacity is exceeded.
*/
@Test
public void moveBlockMetaDeprecatedExceedCapacity() throws Exception {
StorageDir dir = mMetaManager.getTier(Constants.MEDIUM_HDD).getDir(0);
BlockMeta blockMeta = new DefaultBlockMeta(TEST_BLOCK_ID, 2000, dir);
dir.addBlockMeta(blockMeta);
mThrown.expect(WorkerOutOfSpaceException.class);
mThrown.expectMessage("does not have enough space");
mMetaManager.moveBlockMeta(blockMeta, new BlockStoreLocation(Constants.MEDIUM_MEM, 0));
}
use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockMetadataViewTest method getBlockMeta.
/**
* Tests the {@link BlockMetadataEvictorView#getBlockMeta(long)} method.
*/
@Test
public void getBlockMeta() throws Exception {
StorageDir dir = mMetaManager.getTiers().get(TEST_TIER_ORDINAL).getDir(TEST_DIR);
// Add one block to test dir, expect block meta found
BlockMeta blockMeta = new DefaultBlockMeta(TEST_BLOCK_ID, TEST_BLOCK_SIZE, dir);
dir.addBlockMeta(blockMeta);
assertEquals(blockMeta, mMetadataView.getBlockMeta(TEST_BLOCK_ID));
assertTrue(mMetadataView.isBlockEvictable(TEST_BLOCK_ID));
// Lock this block, expect null result
when(mMetadataView.isBlockPinned(TEST_BLOCK_ID)).thenReturn(false);
when(mMetadataView.isBlockLocked(TEST_BLOCK_ID)).thenReturn(true);
assertNull(mMetadataView.getBlockMeta(TEST_BLOCK_ID));
assertFalse(mMetadataView.isBlockEvictable(TEST_BLOCK_ID));
// Pin this block, expect null result
when(mMetadataView.isBlockPinned(TEST_BLOCK_ID)).thenReturn(true);
when(mMetadataView.isBlockLocked(TEST_BLOCK_ID)).thenReturn(false);
assertNull(mMetadataView.getBlockMeta(TEST_BLOCK_ID));
assertFalse(mMetadataView.isBlockEvictable(TEST_BLOCK_ID));
// No Pin or lock on this block, expect block meta found
when(mMetadataView.isBlockPinned(TEST_BLOCK_ID)).thenReturn(false);
when(mMetadataView.isBlockLocked(TEST_BLOCK_ID)).thenReturn(false);
assertEquals(blockMeta, mMetadataView.getBlockMeta(TEST_BLOCK_ID));
assertTrue(mMetadataView.isBlockEvictable(TEST_BLOCK_ID));
}
use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockMetadataViewTest method sameTierView.
/**
* Tests that {@code BlockMetadataEvictorView.getTierView(tierAlias)} returns the same
* TierView as {@code new StorageTierEvictorView(mMetadataManager.getTier(tierAlias), this)}.
*/
@Test
public void sameTierView() {
String tierAlias = mMetaManager.getTiers().get(TEST_TIER_ORDINAL).getTierAlias();
StorageTierView tierView1 = mMetadataView.getTierView(tierAlias);
// Do some operations on metadata
StorageDir dir = mMetaManager.getTiers().get(TEST_TIER_ORDINAL).getDir(TEST_DIR);
BlockMeta blockMeta = new DefaultBlockMeta(TEST_BLOCK_ID, TEST_BLOCK_SIZE, dir);
try {
dir.addBlockMeta(blockMeta);
} catch (Exception e) {
e.printStackTrace();
}
StorageTierEvictorView tierView2 = new StorageTierEvictorView(mMetaManager.getTier(tierAlias), mMetadataView);
assertSameTierView((StorageTierEvictorView) tierView1, tierView2);
}
use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockStoreMetaTest method getUsedBytesOnDirs.
/**
* Tests the {@link BlockStoreMeta#getUsedBytesOnDirs()} method.
*/
@Test
public void getUsedBytesOnDirs() {
Map<Pair<String, String>, Long> dirsToUsedBytes = new HashMap<>();
for (StorageTier tier : mMetadataManager.getTiers()) {
for (StorageDir dir : tier.getStorageDirs()) {
dirsToUsedBytes.put(new Pair<>(tier.getTierAlias(), dir.getDirPath()), dir.getCapacityBytes() - dir.getAvailableBytes());
}
}
Assert.assertEquals(dirsToUsedBytes, mBlockStoreMeta.getUsedBytesOnDirs());
}
use of alluxio.worker.block.meta.StorageDir 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 tierLevel tier level of the {@link StorageDir} the block resides in
* @param dirIndex index of directory in the tierLevel 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
*/
public static void cache(long sessionId, long blockId, long bytes, int tierLevel, int dirIndex, BlockMetadataManager meta, Evictor evictor) throws Exception {
StorageDir dir = meta.getTiers().get(tierLevel).getDir(dirIndex);
cache(sessionId, blockId, bytes, dir, meta, evictor);
}
Aggregations