Search in sources :

Example 46 with RequestInfo

use of org.kie.api.executor.RequestInfo 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)

Example 47 with RequestInfo

use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.

the class JmsAvaiableJobExecutorTest method testAsyncAuditProducer.

@Test
public void testAsyncAuditProducer() throws Exception {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    ut.begin();
    executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", ctxCMD);
    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(1, executedRequests.size());
}
Also used : UserTransaction(javax.transaction.UserTransaction) CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) CommandContext(org.kie.api.executor.CommandContext) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 48 with RequestInfo

use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.

the class LoadAndScheduleRequestsTask method run.

@Override
public void run() {
    logger.info("Load of jobs from storage started at {}", new Date());
    List<RequestInfo> loaded = executorStoreService.loadRequests();
    if (!loaded.isEmpty()) {
        logger.info("Found {} jobs that are waiting for execution, scheduling them...", loaded.size());
        int scheduledCounter = 0;
        for (RequestInfo request : loaded) {
            PrioritisedRunnable job = new PrioritisedRunnable(request.getId(), request.getPriority(), request.getTime(), jobProcessor);
            long delay = request.getTime().getTime() - System.currentTimeMillis();
            logger.debug("Scheduling with delay {} for request {}", delay, request.getId());
            boolean scheduled = ((PrioritisedScheduledThreadPoolExecutor) scheduler).scheduleNoDuplicates(job, delay, TimeUnit.MILLISECONDS);
            if (scheduled) {
                logger.debug("Request {} has been successfully scheduled", request.getId());
                scheduledCounter++;
            } else {
                logger.debug("Request {} has not been scheduled as it's already there", request.getId());
            }
        }
        logger.info("{} jobs have been successfully scheduled", scheduledCounter);
    }
    logger.info("Load of jobs from storage finished at {}", new Date());
}
Also used : RequestInfo(org.kie.api.executor.RequestInfo) Date(java.util.Date)

Example 49 with RequestInfo

use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.

the class BasicExecutorIntegrationTest method defaultRequestRetryTest.

@Test
public void defaultRequestRetryTest() throws InterruptedException {
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    executorService.scheduleRequest("org.jbpm.executor.ejb.impl.test.ThrowExceptionCommand", ctxCMD);
    Thread.sleep(12000);
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(1, inErrorRequests.size());
    List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
    logger.info("Errors: {}", errors);
    // Three retries means 4 executions in total 1(regular) + 3(retries)
    assertEquals(4, errors.size());
}
Also used : CommandContext(org.kie.api.executor.CommandContext) ErrorInfo(org.kie.api.executor.ErrorInfo) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 50 with RequestInfo

use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.

the class BasicExecutorIntegrationTest method reoccurringExcecutionTest.

@Test
public void reoccurringExcecutionTest() throws InterruptedException {
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    executorService.scheduleRequest("org.jbpm.executor.commands.ReoccurringPrintOutCommand", ctxCMD);
    Thread.sleep(4000);
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(0, inErrorRequests.size());
    List<RequestInfo> queuedRequests = executorService.getQueuedRequests(new QueryContext());
    assertEquals(1, queuedRequests.size());
    List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(4, executedRequests.size());
}
Also used : CommandContext(org.kie.api.executor.CommandContext) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Aggregations

RequestInfo (org.kie.api.executor.RequestInfo)54 QueryContext (org.kie.api.runtime.query.QueryContext)53 Test (org.junit.Test)51 CommandContext (org.kie.api.executor.CommandContext)39 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)25 AtomicLong (java.util.concurrent.atomic.AtomicLong)22 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)13 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)13 KieSession (org.kie.api.runtime.KieSession)13 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)13 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)13 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)13 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)11 Date (java.util.Date)9 ErrorInfo (org.kie.api.executor.ErrorInfo)9 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)8 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)8 HashMap (java.util.HashMap)7 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)6 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)5