use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockMetadataManagerTest method blockMeta.
/**
* Tests the different operations for metadata of a block, such as adding a temporary block or
* committing a block.
*/
@Test
public void blockMeta() throws Exception {
StorageDir dir = mMetaManager.getTier(Constants.MEDIUM_HDD).getDir(0);
TempBlockMeta tempBlockMeta = new DefaultTempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID, TEST_BLOCK_SIZE, dir);
// Empty storage
assertFalse(mMetaManager.hasTempBlockMeta(TEST_TEMP_BLOCK_ID));
assertFalse(mMetaManager.hasBlockMeta(TEST_TEMP_BLOCK_ID));
// Add temp block
mMetaManager.addTempBlockMeta(tempBlockMeta);
assertTrue(mMetaManager.hasTempBlockMeta(TEST_TEMP_BLOCK_ID));
assertFalse(mMetaManager.hasBlockMeta(TEST_TEMP_BLOCK_ID));
// Get temp block
assertEquals(tempBlockMeta, mMetaManager.getTempBlockMeta(TEST_TEMP_BLOCK_ID));
// Abort temp block
mMetaManager.abortTempBlockMeta(tempBlockMeta);
assertFalse(mMetaManager.hasTempBlockMeta(TEST_TEMP_BLOCK_ID));
assertFalse(mMetaManager.hasBlockMeta(TEST_TEMP_BLOCK_ID));
// Add temp block with previous block id
mMetaManager.addTempBlockMeta(tempBlockMeta);
assertTrue(mMetaManager.hasTempBlockMeta(TEST_TEMP_BLOCK_ID));
assertFalse(mMetaManager.hasBlockMeta(TEST_TEMP_BLOCK_ID));
// Commit temp block
mMetaManager.commitTempBlockMeta(tempBlockMeta);
assertFalse(mMetaManager.hasTempBlockMeta(TEST_TEMP_BLOCK_ID));
assertTrue(mMetaManager.hasBlockMeta(TEST_TEMP_BLOCK_ID));
// Get block
BlockMeta blockMeta = mMetaManager.getBlockMeta(TEST_TEMP_BLOCK_ID);
assertEquals(TEST_TEMP_BLOCK_ID, blockMeta.getBlockId());
// Remove block
mMetaManager.removeBlockMeta(blockMeta);
assertFalse(mMetaManager.hasTempBlockMeta(TEST_TEMP_BLOCK_ID));
assertFalse(mMetaManager.hasBlockMeta(TEST_TEMP_BLOCK_ID));
}
use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockMetadataViewTest method getAvailableBytes.
/**
* Tests the {@link BlockMetadataEvictorView#getAvailableBytes(BlockStoreLocation)} method.
*/
@Test
public void getAvailableBytes() {
BlockStoreLocation location;
// When location represents anyTier
location = BlockStoreLocation.anyTier();
assertEquals(mMetaManager.getAvailableBytes(location), mMetadataView.getAvailableBytes(location));
// When location represents one particular tier
for (StorageTier tier : mMetaManager.getTiers()) {
String tierAlias = tier.getTierAlias();
location = BlockStoreLocation.anyDirInTier(tierAlias);
assertEquals(mMetaManager.getAvailableBytes(location), mMetadataView.getAvailableBytes(location));
for (StorageDir dir : tier.getStorageDirs()) {
// When location represents one particular dir
location = dir.toBlockStoreLocation();
assertEquals(mMetaManager.getAvailableBytes(location), mMetadataView.getAvailableBytes(location));
}
}
}
use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockMetadataViewTest method sameTierViewsBelow.
/**
* Tests that {@link BlockMetadataEvictorView#getTierViewsBelow(String)} returns the same
* TierViews as constructing by {@link BlockMetadataManager#getTiersBelow(String)}.
*/
@Test
public void sameTierViewsBelow() {
String tierAlias = mMetaManager.getTiers().get(TEST_TIER_ORDINAL).getTierAlias();
List<StorageTierView> tierViews1 = mMetadataView.getTierViewsBelow(tierAlias);
// Do some operations on metadata
StorageDir dir = mMetaManager.getTiers().get(TEST_TIER_ORDINAL + 1).getDir(TEST_DIR);
BlockMeta blockMeta = new DefaultBlockMeta(TEST_BLOCK_ID, TEST_BLOCK_SIZE, dir);
try {
dir.addBlockMeta(blockMeta);
} catch (Exception e) {
e.printStackTrace();
}
List<StorageTier> tiers2 = mMetaManager.getTiersBelow(tierAlias);
assertEquals(tierViews1.size(), tiers2.size());
for (int i = 0; i < tierViews1.size(); i++) {
assertSameTierView((StorageTierEvictorView) tierViews1.get(i), new StorageTierEvictorView(tiers2.get(i), mMetadataView));
}
}
use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockStoreMetaTest method getBlockList.
/**
* Tests the {@link BlockStoreMeta#getBlockList()} method.
*/
@Test
public void getBlockList() {
Map<String, List<Long>> tierAliasToBlockIds = new HashMap<>();
for (StorageTier tier : mMetadataManager.getTiers()) {
List<Long> blockIdsOnTier = new ArrayList<>();
for (StorageDir dir : tier.getStorageDirs()) {
blockIdsOnTier.addAll(dir.getBlockIds());
}
tierAliasToBlockIds.put(tier.getTierAlias(), blockIdsOnTier);
}
Map<String, List<Long>> actual = mBlockStoreMetaFull.getBlockList();
Assert.assertEquals(TieredBlockStoreTestUtils.TIER_ALIAS.length, actual.keySet().size());
Assert.assertEquals(tierAliasToBlockIds, actual);
}
use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockStoreMetaTest method getCapacityBytesOnDirs.
/**
* Tests the {@link BlockStoreMeta#getCapacityBytes()} method.
*/
@Test
public void getCapacityBytesOnDirs() {
Map<Pair<String, String>, Long> dirsToCapacityBytes = new HashMap<>();
for (StorageTier tier : mMetadataManager.getTiers()) {
for (StorageDir dir : tier.getStorageDirs()) {
dirsToCapacityBytes.put(new Pair<>(tier.getTierAlias(), dir.getDirPath()), dir.getCapacityBytes());
}
}
Assert.assertEquals(dirsToCapacityBytes, mBlockStoreMeta.getCapacityBytesOnDirs());
Assert.assertEquals(TieredBlockStoreTestUtils.getDefaultDirNum(), mBlockStoreMeta.getCapacityBytesOnDirs().values().size());
}
Aggregations