Search in sources :

Example 1 with StealJobQueue

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());
}
Also used : StealJobQueue(org.apache.hadoop.hbase.util.StealJobQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 StealJobQueue (org.apache.hadoop.hbase.util.StealJobQueue)1 Test (org.junit.Test)1