Search in sources :

Example 1 with ManualClock

use of alluxio.clock.ManualClock in project alluxio by Alluxio.

the class BlockMasterTest method before.

/**
   * Sets up the dependencies before a test runs.
   */
@Before
public void before() throws Exception {
    JournalFactory journalFactory = new JournalFactory.ReadWrite(mTestFolder.newFolder().getAbsolutePath());
    mClock = new ManualClock();
    mExecutorService = Executors.newFixedThreadPool(2, ThreadFactoryUtils.build("TestBlockMaster-%d", true));
    mMaster = new BlockMaster(journalFactory, mClock, ExecutorServiceFactories.constantExecutorServiceFactory(mExecutorService));
    mMaster.start(true);
}
Also used : JournalFactory(alluxio.master.journal.JournalFactory) ManualClock(alluxio.clock.ManualClock) Before(org.junit.Before)

Example 2 with ManualClock

use of alluxio.clock.ManualClock in project alluxio by Alluxio.

the class AlluxioMasterRestServiceHandlerTest method before.

@Before
public void before() throws Exception {
    mMaster = mock(AlluxioMasterService.class);
    mContext = mock(ServletContext.class);
    JournalFactory journalFactory = new JournalFactory.ReadWrite(mTestFolder.newFolder().getAbsolutePath());
    mClock = new ManualClock();
    mExecutorService = Executors.newFixedThreadPool(2, ThreadFactoryUtils.build("TestBlockMaster-%d", true));
    mBlockMaster = new BlockMaster(journalFactory, mClock, ExecutorServiceFactories.constantExecutorServiceFactory(mExecutorService));
    mBlockMaster.start(true);
    when(mMaster.getBlockMaster()).thenReturn(mBlockMaster);
    when(mContext.getAttribute(MasterWebServer.ALLUXIO_MASTER_SERVLET_RESOURCE_KEY)).thenReturn(mMaster);
    registerFileSystemMock();
    mHandler = new AlluxioMasterRestServiceHandler(mContext);
    // Register two workers
    long worker1 = mBlockMaster.getWorkerId(NET_ADDRESS_1);
    long worker2 = mBlockMaster.getWorkerId(NET_ADDRESS_2);
    List<String> tiers = Arrays.asList("MEM", "SSD");
    mBlockMaster.workerRegister(worker1, tiers, WORKER1_TOTAL_BYTES_ON_TIERS, WORKER1_USED_BYTES_ON_TIERS, NO_BLOCKS_ON_TIERS);
    mBlockMaster.workerRegister(worker2, tiers, WORKER2_TOTAL_BYTES_ON_TIERS, WORKER2_USED_BYTES_ON_TIERS, NO_BLOCKS_ON_TIERS);
}
Also used : JournalFactory(alluxio.master.journal.JournalFactory) BlockMaster(alluxio.master.block.BlockMaster) ManualClock(alluxio.clock.ManualClock) ServletContext(javax.servlet.ServletContext) Matchers.anyString(org.mockito.Matchers.anyString) Before(org.junit.Before)

Example 3 with ManualClock

use of alluxio.clock.ManualClock in project alluxio by Alluxio.

the class SleepingTimerTest method before.

@Before
public void before() {
    mMockLogger = Mockito.mock(Logger.class);
    mFakeClock = new ManualClock();
    mMockSleeper = Mockito.mock(Sleeper.class);
}
Also used : ManualClock(alluxio.clock.ManualClock) Sleeper(alluxio.time.Sleeper) Logger(org.slf4j.Logger) Before(org.junit.Before)

Example 4 with ManualClock

use of alluxio.clock.ManualClock in project alluxio by Alluxio.

the class DynamicResourcePoolTest method gc.

@Test
public void gc() throws Exception {
    ManualClock manualClock = new ManualClock();
    TestPool pool = new TestPool(DynamicResourcePool.Options.defaultOptions().setGcIntervalMs(10).setInitialDelayMs(1), manualClock);
    pool.setGcThresholdInSecs(1);
    List<Resource> resourceList = new ArrayList<>();
    resourceList.add(pool.acquire());
    resourceList.add(pool.acquire());
    pool.release(resourceList.get(0));
    manualClock.addTimeMs(1001);
    // Sleep 1 second to make sure the GC has run.
    Thread.sleep(1000);
    // Resource 0 is gc-ed.
    Assert.assertEquals(2, pool.acquire().mInteger.intValue());
}
Also used : ManualClock(alluxio.clock.ManualClock) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with ManualClock

use of alluxio.clock.ManualClock in project alluxio by Alluxio.

the class DynamicResourcePoolTest method acquireRentlyUsed.

/**
   * Tests the logic that the recently used resource is preferred.
   */
@Test
public void acquireRentlyUsed() throws Exception {
    ManualClock manualClock = new ManualClock();
    TestPool pool = new TestPool(DynamicResourcePool.Options.defaultOptions(), manualClock);
    List<Resource> resourceList = new ArrayList<>();
    resourceList.add(pool.acquire());
    resourceList.add(pool.acquire());
    resourceList.add(pool.acquire());
    pool.release(resourceList.get(2));
    pool.release(resourceList.get(0));
    manualClock.addTimeMs(1500);
    pool.release(resourceList.get(1));
    for (int i = 0; i < 10; i++) {
        Resource resource = pool.acquire();
        Assert.assertEquals(1, resource.mInteger.intValue());
        pool.release(resource);
    }
}
Also used : ManualClock(alluxio.clock.ManualClock) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ManualClock (alluxio.clock.ManualClock)5 Before (org.junit.Before)3 JournalFactory (alluxio.master.journal.JournalFactory)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 BlockMaster (alluxio.master.block.BlockMaster)1 Sleeper (alluxio.time.Sleeper)1 ServletContext (javax.servlet.ServletContext)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Logger (org.slf4j.Logger)1