AsyncDispatcher extends AbstractService implements Dispatcher { public void setDrainEventsOnStop() { drainEventsOnStop = true; } AsyncDispatcher();  AsyncDispatcher(BlockingQueue<Event> eventQueue);  AsyncDispatcher(String dispatcherName); @VisibleForTesting void disableExitOnDispatchException(); void setDrainEventsOnStop(); @SuppressWarnings("unchecked") @Override void register(Class<? extends Enum> eventType,
      EventHandler handler); @Override EventHandler<Event> getEventHandler();  }
@Test(timeout=10000) public void testDispatchStopOnTimeout() throws Exception { BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<Event>(); eventQueue = spy(eventQueue); when(eventQueue.isEmpty()).thenReturn(false); YarnConfiguration conf = new YarnConfiguration(); conf.setInt(YarnConfiguration.DISPATCHER_DRAIN_EVENTS_TIMEOUT, 2000); DrainDispatcher disp = new DrainDispatcher(eventQueue); disp.init(conf); disp.setDrainEventsOnStop(); disp.start(); disp.waitForEventThreadToWait(); disp.close(); }