@Test
public void errorDuringDispatcherExecutionStopsDispatcher() throws Throwable {

  @SuppressWarnings("unused")
  class ErrorDuringDispatcherExecutionStopsDispatcher extends MultithreadedTestCase {
    public void threadDispatcher() {
      when(workflowInstances.pollNextWorkflowInstanceIds(anyInt())).thenThrow(new AssertionError()).thenReturn(ids(1L));
      try {
        dispatcher.run();
        Assertions.fail("Error should stop the dispatcher");
      } catch (AssertionError expected) {
        assertPoolIsShutdown(true);
      }
    }
    @Override
    public void finish() {
      verify(workflowInstances).pollNextWorkflowInstanceIds(anyInt());
      verify(executorFactory, never()).createProcessor(anyLong(), any());
    }
  }
  runOnce(new ErrorDuringDispatcherExecutionStopsDispatcher());
}