Search in sources :

Example 46 with StorageDir

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));
}
Also used : StorageDir(alluxio.worker.block.meta.StorageDir) DefaultTempBlockMeta(alluxio.worker.block.meta.DefaultTempBlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) DefaultTempBlockMeta(alluxio.worker.block.meta.DefaultTempBlockMeta) BlockMeta(alluxio.worker.block.meta.BlockMeta) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) DefaultTempBlockMeta(alluxio.worker.block.meta.DefaultTempBlockMeta) Test(org.junit.Test)

Example 47 with StorageDir

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));
        }
    }
}
Also used : StorageTier(alluxio.worker.block.meta.StorageTier) StorageDir(alluxio.worker.block.meta.StorageDir) Test(org.junit.Test)

Example 48 with StorageDir

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));
    }
}
Also used : StorageTierEvictorView(alluxio.worker.block.meta.StorageTierEvictorView) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) StorageTier(alluxio.worker.block.meta.StorageTier) StorageTierView(alluxio.worker.block.meta.StorageTierView) StorageDir(alluxio.worker.block.meta.StorageDir) BlockMeta(alluxio.worker.block.meta.BlockMeta) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) ExpectedException(org.junit.rules.ExpectedException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) Test(org.junit.Test)

Example 49 with StorageDir

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);
}
Also used : HashMap(java.util.HashMap) StorageTier(alluxio.worker.block.meta.StorageTier) ArrayList(java.util.ArrayList) StorageDir(alluxio.worker.block.meta.StorageDir) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 50 with StorageDir

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());
}
Also used : HashMap(java.util.HashMap) StorageTier(alluxio.worker.block.meta.StorageTier) StorageDir(alluxio.worker.block.meta.StorageDir) Pair(alluxio.collections.Pair) Test(org.junit.Test)

Aggregations

StorageDir (alluxio.worker.block.meta.StorageDir)55 Test (org.junit.Test)38 BlockMeta (alluxio.worker.block.meta.BlockMeta)18 StorageTier (alluxio.worker.block.meta.StorageTier)16 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)16 DefaultBlockMeta (alluxio.worker.block.meta.DefaultBlockMeta)15 DefaultTempBlockMeta (alluxio.worker.block.meta.DefaultTempBlockMeta)8 ArrayList (java.util.ArrayList)8 BlockStoreLocation (alluxio.worker.block.BlockStoreLocation)6 HashMap (java.util.HashMap)5 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)4 StorageTierView (alluxio.worker.block.meta.StorageTierView)4 List (java.util.List)4 Random (java.util.Random)4 ExpectedException (org.junit.rules.ExpectedException)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Pair (alluxio.collections.Pair)3 Before (org.junit.Before)3 PropertyKey (alluxio.conf.PropertyKey)2 ServerConfiguration (alluxio.conf.ServerConfiguration)2