use of org.jbpm.executor.AsynchronousJobListener in project jbpm by kiegroup.
the class JmsAvaiableJobExecutorTest method testAsyncAuditProducerPrioritizedJobs.
@Test
public void testAsyncAuditProducerPrioritizedJobs() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(2);
final List<String> executedJobs = new ArrayList<String>();
((ExecutorServiceImpl) executorService).addAsyncJobListener(new AsynchronousJobListener() {
@Override
public void beforeJobScheduled(AsynchronousJobEvent event) {
}
@Override
public void beforeJobExecuted(AsynchronousJobEvent event) {
}
@Override
public void beforeJobCancelled(AsynchronousJobEvent event) {
}
@Override
public void afterJobScheduled(AsynchronousJobEvent event) {
}
@Override
public void afterJobExecuted(AsynchronousJobEvent event) {
executedJobs.add(event.getJob().getKey());
}
@Override
public void afterJobCancelled(AsynchronousJobEvent event) {
}
});
CommandContext ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", "low priority");
ctxCMD.setData("priority", 2);
CommandContext ctxCMD2 = new CommandContext();
ctxCMD2.setData("businessKey", "high priority");
ctxCMD2.setData("priority", 8);
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", ctxCMD);
executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", ctxCMD2);
ut.commit();
MessageReceiver receiver = new MessageReceiver();
receiver.receiveAndProcess(queue, countDownListener);
List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
assertEquals(0, inErrorRequests.size());
List<RequestInfo> queuedRequests = executorService.getQueuedRequests(new QueryContext());
assertEquals(0, queuedRequests.size());
List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
assertEquals(2, executedRequests.size());
assertEquals(2, executedJobs.size());
assertEquals("high priority", executedJobs.get(0));
assertEquals("low priority", executedJobs.get(1));
}
Aggregations