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));
}
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());
}
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());
}
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());
}
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());
}
Aggregations