@Test
public void testGetNextMessage_moreThreads() throws InterruptedException {

    // firstly commit messages to DB (we can commit because we have embedded DB for tests only)
    TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
    txTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            Message msg = insertNewMessage("1234_4567");
            confirmationService.insertFailedConfirmation(msg);
            msg = insertNewMessage("1234_4567_8");
            confirmationService.insertFailedConfirmation(msg);
            msg = insertNewMessage("1234_4567_9");
            confirmationService.insertFailedConfirmation(msg);
        }
    });
    // prepare threads
    int threads = 5;
    final CountDownLatch latch = new CountDownLatch(threads);
    Runnable task = new Runnable() {
        @Override
        public void run() {
            try {
                pollExecutor.run();
            } finally {
                latch.countDown();
            }
        }
    };
    mock.expectedMessageCount(3);
    // start processing and waits for result
    for (int i = 0; i < threads; i++) {
        new Thread(task).start();
    }
    latch.await();
    mock.assertIsSatisfied();
    // verify messages
    ExternalCall extCall1 = findConfirmation("1234_4567");
    assertThat(extCall1, notNullValue());
    assertThat(extCall1.getState(), is(ExternalCallStateEnum.PROCESSING));
    ExternalCall extCall2 = findConfirmation("1234_4567_8");
    assertThat(extCall2, notNullValue());
    assertThat(extCall2.getState(), is(ExternalCallStateEnum.PROCESSING));
    ExternalCall extCall3 = findConfirmation("1234_4567_9");
    assertThat(extCall3, notNullValue());
    assertThat(extCall3.getState(), is(ExternalCallStateEnum.PROCESSING));
    // check confirmationService
    confirmationService.confirmationFailed(extCall1);
    extCall1 = findConfirmation("1234_4567");
    assertThat(extCall1.getState(), is(ExternalCallStateEnum.FAILED));
    confirmationService.confirmationComplete(extCall2);
    extCall2 = findConfirmation("1234_4567_8");
    assertThat(extCall2.getState(), is(ExternalCallStateEnum.OK));
}