@Test(timeout=10000)
public void testDispatchStopOnTimeout() throws Exception {

  BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<Event>();
  eventQueue = spy(eventQueue);
  // simulate dispatcher is not drained.
  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();
}