@Test
  public void testErrorPropagation() {
    ForeignExceptionListener listener1 = Mockito.mock(ForeignExceptionListener.class);
    ForeignExceptionListener listener2 = Mockito.mock(ForeignExceptionListener.class);
    ForeignExceptionDispatcher dispatcher = new ForeignExceptionDispatcher();

    // add the listeners
    dispatcher.addListener(listener1);
    dispatcher.addListener(listener2);

    // create an artificial error
    dispatcher.receive(EXTEXN);

    // make sure the listeners got the error
    Mockito.verify(listener1, Mockito.times(1)).receive(EXTEXN);
    Mockito.verify(listener2, Mockito.times(1)).receive(EXTEXN);

    // make sure that we get an exception
    try {
      dispatcher.rethrowException();
      fail("Monitor should have thrown an exception after getting error.");
    } catch (ForeignException ex) {
      assertTrue("Got an unexpected exception:" + ex, ex.getCause() == EXTEXN.getCause());
      LOG.debug("Got the testing exception!");
    }

    // push another error, which should be not be passed to listeners
    dispatcher.receive(EXTEXN2);
    Mockito.verify(listener1, Mockito.never()).receive(EXTEXN2);
    Mockito.verify(listener2, Mockito.never()).receive(EXTEXN2);
  }
Tests that a dispatcher only dispatches only the first exception, and does not propagate
subsequent exceptions.
hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionDispatcher.java