Search in sources :

Example 31 with StorageDir

use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.

the class BlockWorkerTest method createBlockRemote.

/**
   * Tests the {@link BlockWorker#createBlockRemote(long, long, String, long)} method.
   */
@Test
public void createBlockRemote() 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));
}
Also used : StorageDir(alluxio.worker.block.meta.StorageDir) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 32 with StorageDir

use of alluxio.worker.block.meta.StorageDir 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));
}
Also used : StorageDir(alluxio.worker.block.meta.StorageDir) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 33 with StorageDir

use of alluxio.worker.block.meta.StorageDir 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));
}
Also used : StorageDir(alluxio.worker.block.meta.StorageDir) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 34 with StorageDir

use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.

the class EvictorContractTest method noNeedToEvictTest3.

/**
   * Tests that no eviction plan is created when all directories are filled except for one
   * directory.
   */
@Test
public void noNeedToEvictTest3() throws Exception {
    // fill in all dirs except for one directory, then request the capacity of
    // the directory with anyDirInTier
    StorageDir dirLeft = mTestDir;
    // start from BLOCK_ID
    long blockId = BLOCK_ID;
    for (StorageTier tier : mMetaManager.getTiers()) {
        for (StorageDir dir : tier.getStorageDirs()) {
            if (dir != dirLeft) {
                TieredBlockStoreTestUtils.cache(SESSION_ID, blockId, dir.getCapacityBytes(), dir, mMetaManager, mEvictor);
                blockId++;
            }
        }
    }
    Assert.assertTrue(mEvictor.freeSpaceWithView(dirLeft.getCapacityBytes(), BlockStoreLocation.anyDirInTier(dirLeft.getParentTier().getTierAlias()), mManagerView).isEmpty());
}
Also used : StorageTier(alluxio.worker.block.meta.StorageTier) StorageDir(alluxio.worker.block.meta.StorageDir) Test(org.junit.Test)

Example 35 with StorageDir

use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.

the class EvictorContractTest method requestSpaceLargerThanCapacity.

/**
   * Tests that no eviction plan is available when requesting more space than capacity available.
   */
@Test
public void requestSpaceLargerThanCapacity() throws Exception {
    // cache data in a dir
    long totalCapacity = mMetaManager.getAvailableBytes(BlockStoreLocation.anyTier());
    StorageDir dir = mTestDir;
    BlockStoreLocation dirLocation = dir.toBlockStoreLocation();
    long dirCapacity = mMetaManager.getAvailableBytes(dirLocation);
    TieredBlockStoreTestUtils.cache(SESSION_ID, BLOCK_ID, dirCapacity, dir, mMetaManager, mEvictor);
    // request space larger than total capacity, no eviction plan should be available
    Assert.assertNull(mEvictor.freeSpaceWithView(totalCapacity + 1, BlockStoreLocation.anyTier(), mManagerView));
    // request space larger than capacity for the random directory, no eviction plan should be
    // available
    Assert.assertNull(mEvictor.freeSpaceWithView(dirCapacity + 1, dirLocation, mManagerView));
}
Also used : StorageDir(alluxio.worker.block.meta.StorageDir) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) 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