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);
}
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);
}
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);
}
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());
}
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);
}
}
Aggregations