@Test
public void testBatchPollException() {

    try
    {
        System.setProperty("workflow.system.task.queue.pollCount", "2");
        System.setProperty("workflow.system.task.worker.thread.count", "2");
        Configuration configuration = new SystemPropertiesConfiguration();
        when(queueDAO.pop(anyString(), anyInt(), anyInt()))
                .thenThrow(RuntimeException.class)
                .thenReturn(Collections.nCopies(2,"taskId"));
        systemTaskExecutor = new SystemTaskExecutor(queueDAO, workflowExecutor, configuration, executionService);
        CountDownLatch latch = new CountDownLatch(2);
        doAnswer(invocation -> {
                    latch.countDown();
                    return null;
                }
        ).when(workflowExecutor).executeSystemTask(any(), anyString(), anyInt());
        scheduledExecutorService.scheduleAtFixedRate(
                () -> systemTaskExecutor.pollAndExecute(TEST_TASK), 0, 1, TimeUnit.SECONDS);
        Uninterruptibles.awaitUninterruptibly(latch);
        verify(workflowExecutor, Mockito.times(2)).executeSystemTask(any(), anyString(), anyInt());
    }
    finally {
        //Revert the batch poll settings
        System.setProperty("workflow.system.task.queue.pollCount", "1");
    }
}