use of org.apache.hadoop.hbase.util.StealJobQueue in project hbase by apache.
the class TestStealJobQueue method testInteractWithThreadPool.
@Test
public void testInteractWithThreadPool() throws InterruptedException {
StealJobQueue<Runnable> stealTasksQueue = new StealJobQueue<>();
final CountDownLatch stealJobCountDown = new CountDownLatch(3);
final CountDownLatch stealFromCountDown = new CountDownLatch(3);
ThreadPoolExecutor stealPool = new ThreadPoolExecutor(3, 3, 1, TimeUnit.DAYS, stealTasksQueue) {
@Override
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
stealJobCountDown.countDown();
}
};
//This is necessary otherwise no worker will be running and stealing job
stealPool.prestartAllCoreThreads();
ThreadPoolExecutor stealFromPool = new ThreadPoolExecutor(3, 3, 1, TimeUnit.DAYS, stealTasksQueue.getStealFromQueue()) {
@Override
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
stealFromCountDown.countDown();
}
};
for (int i = 0; i < 4; i++) {
TestTask task = new TestTask();
stealFromPool.execute(task);
}
for (int i = 0; i < 2; i++) {
TestTask task = new TestTask();
stealPool.execute(task);
}
stealJobCountDown.await(1, TimeUnit.SECONDS);
stealFromCountDown.await(1, TimeUnit.SECONDS);
assertEquals(0, stealFromCountDown.getCount());
assertEquals(0, stealJobCountDown.getCount());
}
Aggregations