@Test public void testExecutorService() throws Exception { int maxThreads = 5; int maxTries = 10; int sleepInterval = 10; Server mockedServer = mock(Server.class); when(mockedServer.getConfiguration()).thenReturn(HBaseConfiguration.create()); ExecutorService executorService = new ExecutorService("unit_test"); executorService.startExecutorService( ExecutorType.MASTER_SERVER_OPERATIONS, maxThreads); Executor executor = executorService.getExecutor(ExecutorType.MASTER_SERVER_OPERATIONS); ThreadPoolExecutor pool = executor.threadPoolExecutor; assertEquals(0, pool.getPoolSize()); AtomicBoolean lock = new AtomicBoolean(true); AtomicInteger counter = new AtomicInteger(0); for (int i = 0; i < maxThreads; i++) { executorService.submit( new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter)); } int tries = 0; while (counter.get() < maxThreads && tries < maxTries) { LOG.info("Waiting for all event handlers to start..."); Thread.sleep(sleepInterval); tries++; } assertEquals(maxThreads, counter.get()); assertEquals(maxThreads, pool.getPoolSize()); ExecutorStatus status = executor.getStatus(); assertTrue(status.queuedEvents.isEmpty()); assertEquals(5, status.running.size()); checkStatusDump(status); synchronized (lock) { lock.set(false); lock.notifyAll(); } while (counter.get() < (maxThreads * 2) && tries < maxTries) { System.out.println("Waiting for all event handlers to finish..."); Thread.sleep(sleepInterval); tries++; } assertEquals(maxThreads * 2, counter.get()); assertEquals(maxThreads, pool.getPoolSize()); for (int i = 0; i < (2 * maxThreads); i++) { executorService.submit( new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter)); } synchronized (lock) { lock.set(false); lock.notifyAll(); } Thread.sleep(ExecutorService.Executor.keepAliveTimeInMillis * 2); assertEquals(maxThreads, pool.getPoolSize()); executorService.shutdown(); assertEquals(0, executorService.getAllExecutorStatuses().size()); executorService.submit( new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter)); }
public ExecutorService(final String servername) { super(); this.servername = servername; }
ExecutorService { public ExecutorService(final String servername) { super(); this.servername = servername; } }
ExecutorService { public ExecutorService(final String servername) { super(); this.servername = servername; } ExecutorService(final String servername); }
ExecutorService { public ExecutorService(final String servername) { super(); this.servername = servername; } ExecutorService(final String servername); void shutdown(); void startExecutorService(final ExecutorType type, final int maxThreads); void submit(final EventHandler eh); void registerListener(final EventType type,
      final EventHandlerListener listener); EventHandlerListener unregisterListener(final EventType type); Map<String, ExecutorStatus> getAllExecutorStatuses(); }
ExecutorService { public ExecutorService(final String servername) { super(); this.servername = servername; } ExecutorService(final String servername); void shutdown(); void startExecutorService(final ExecutorType type, final int maxThreads); void submit(final EventHandler eh); void registerListener(final EventType type,
      final EventHandlerListener listener); EventHandlerListener unregisterListener(final EventType type); Map<String, ExecutorStatus> getAllExecutorStatuses();  }