Search in sources :

Example 1 with TestEventHandler

use of org.apache.hadoop.hbase.executor.TestExecutorService.TestEventHandler in project hbase by apache.

the class TestExecutorStatusChore method testMetricsCollect.

@Test
public void testMetricsCollect() throws Exception {
    int maxThreads = 5;
    int maxTries = 10;
    int sleepInterval = 1000;
    Server mockedServer = mock(Server.class);
    when(mockedServer.getConfiguration()).thenReturn(HBaseConfiguration.create());
    // Start an executor service pool with max 5 threads
    ExecutorService executorService = new ExecutorService("unit_test");
    executorService.startExecutorService(executorService.new ExecutorConfig().setExecutorType(ExecutorType.RS_PARALLEL_SEEK).setCorePoolSize(maxThreads));
    MetricsRegionServerSource serverSource = CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class).createServer(null);
    assertTrue(serverSource instanceof MetricsRegionServerSourceImpl);
    ExecutorStatusChore statusChore = new ExecutorStatusChore(60000, mockedServer, executorService, serverSource);
    AtomicBoolean lock = new AtomicBoolean(true);
    AtomicInteger counter = new AtomicInteger(0);
    for (int i = 0; i < maxThreads + 1; i++) {
        executorService.submit(new TestEventHandler(mockedServer, EventType.RS_PARALLEL_SEEK, lock, counter));
    }
    // The TestEventHandler will increment counter when it starts.
    int tries = 0;
    while (counter.get() < maxThreads && tries < maxTries) {
        LOG.info("Waiting for all event handlers to start...");
        Thread.sleep(sleepInterval);
        tries++;
    }
    // Assert that pool is at max threads.
    assertEquals(maxThreads, counter.get());
    statusChore.chore();
    Pair<Long, Long> executorStatus = statusChore.getExecutorStatus("RS_PARALLEL_SEEK");
    // running
    assertEquals(maxThreads, executorStatus.getFirst().intValue());
    // pending
    assertEquals(1, executorStatus.getSecond().intValue());
    // Now interrupt the running Executor
    synchronized (lock) {
        lock.set(false);
        lock.notifyAll();
    }
    executorService.shutdown();
}
Also used : MetricsRegionServerSource(org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource) MetricsRegionServerSourceFactory(org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceFactory) TestEventHandler(org.apache.hadoop.hbase.executor.TestExecutorService.TestEventHandler) ExecutorConfig(org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MetricsRegionServerSourceImpl(org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(org.apache.hadoop.hbase.executor.ExecutorService) Test(org.junit.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ExecutorService (org.apache.hadoop.hbase.executor.ExecutorService)1 ExecutorConfig (org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig)1 TestEventHandler (org.apache.hadoop.hbase.executor.TestExecutorService.TestEventHandler)1 MetricsRegionServerSource (org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource)1 MetricsRegionServerSourceFactory (org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceFactory)1 MetricsRegionServerSourceImpl (org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceImpl)1 Test (org.junit.Test)1