Search in sources :

Example 1 with AsynchronousJobListener

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));
}
Also used : UserTransaction(javax.transaction.UserTransaction) AsynchronousJobListener(org.jbpm.executor.AsynchronousJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) CommandContext(org.kie.api.executor.CommandContext) ArrayList(java.util.ArrayList) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) AsynchronousJobEvent(org.jbpm.executor.AsynchronousJobEvent) CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 UserTransaction (javax.transaction.UserTransaction)1 AsynchronousJobEvent (org.jbpm.executor.AsynchronousJobEvent)1 AsynchronousJobListener (org.jbpm.executor.AsynchronousJobListener)1 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)1 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)1 Test (org.junit.Test)1 CommandContext (org.kie.api.executor.CommandContext)1 RequestInfo (org.kie.api.executor.RequestInfo)1 QueryContext (org.kie.api.runtime.query.QueryContext)1