Search in sources :

Example 16 with CountDownAsyncJobListener

use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.

the class BasicExecutorBaseTest method testPrioritizedJobsExecution.

@Test(timeout = 10000)
public void testPrioritizedJobsExecution() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(2);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", "low priority");
    ctxCMD.setData("priority", 2);
    Date futureDate = new Date(System.currentTimeMillis() + EXTRA_TIME);
    executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", futureDate, ctxCMD);
    CommandContext ctxCMD2 = new CommandContext();
    ctxCMD2.setData("businessKey", "high priority");
    ctxCMD2.setData("priority", 8);
    executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", futureDate, ctxCMD2);
    countDownListener.waitTillCompleted();
    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());
    RequestInfo executedHigh = executedRequests.get(1);
    assertNotNull(executedHigh);
    assertEquals("high priority", executedHigh.getKey());
    RequestInfo executedLow = executedRequests.get(0);
    assertNotNull(executedLow);
    assertEquals("low priority", executedLow.getKey());
    assertTrue(executedLow.getTime().getTime() > executedHigh.getTime().getTime());
}
Also used : 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) Date(java.util.Date) Test(org.junit.Test)

Example 17 with CountDownAsyncJobListener

use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.

the class BasicExecutorBaseTest method testProcessContextJobsExecution.

@Test(timeout = 10000)
public void testProcessContextJobsExecution() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", "low priority");
    ctxCMD.setData("deploymentId", "not-deployed-here");
    ctxCMD.setData("processInstanceId", 2L);
    Long requestId = executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", ctxCMD);
    List<STATUS> statuses = Arrays.asList(STATUS.QUEUED);
    List<RequestInfo> byDeploymentRequests = executorService.getRequestsByDeployment("not-deployed-here", statuses, new QueryContext());
    assertEquals(1, byDeploymentRequests.size());
    List<RequestInfo> byProcessInstanceRequests = executorService.getRequestsByProcessInstance(2L, statuses, new QueryContext());
    assertEquals(1, byProcessInstanceRequests.size());
    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(0, executedRequests.size());
    countDownListener.waitTillCompleted(5000);
    inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(0, inErrorRequests.size());
    queuedRequests = executorService.getQueuedRequests(new QueryContext());
    assertEquals(1, queuedRequests.size());
    executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(0, executedRequests.size());
    executorService.cancelRequest(requestId);
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) STATUS(org.kie.api.executor.STATUS) CommandContext(org.kie.api.executor.CommandContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 18 with CountDownAsyncJobListener

use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.

the class BasicExecutorBaseTest method executorExceptionTrimmingTest.

@Test(timeout = 10000)
public void executorExceptionTrimmingTest() throws InterruptedException {
    System.setProperty("org.kie.executor.msg.length", "10");
    System.setProperty("org.kie.executor.stacktrace.length", "20");
    CountDownAsyncJobListener countDownListener = configureListener(1);
    CommandContext commandContext = new CommandContext();
    commandContext.setData("businessKey", UUID.randomUUID().toString());
    cachedEntities.put((String) commandContext.getData("businessKey"), new AtomicLong(1));
    commandContext.setData("callbacks", "org.jbpm.executor.SimpleIncrementCallback");
    commandContext.setData("retries", 0);
    executorService.scheduleRequest("org.jbpm.executor.ThrowExceptionCommand", commandContext);
    logger.info("{} Sleeping for 10 secs", System.currentTimeMillis());
    countDownListener.waitTillCompleted();
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(1, inErrorRequests.size());
    logger.info("Error: {}", inErrorRequests.get(0));
    List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
    logger.info("Errors: {}", errors);
    assertEquals(1, errors.size());
    ErrorInfo error = errors.get(0);
    assertEquals(10, error.getMessage().length());
    assertEquals(20, error.getStacktrace().length());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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 19 with CountDownAsyncJobListener

use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.

the class BasicExecutorBaseTest method reoccurringExecutionTest.

@Test(timeout = 10000)
public void reoccurringExecutionTest() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(3);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    executorService.scheduleRequest("org.jbpm.executor.commands.ReoccurringPrintOutCommand", ctxCMD);
    countDownListener.waitTillCompleted();
    List<RequestInfo> rescheduled = executorService.getRequestsByBusinessKey((String) ctxCMD.getData("businessKey"), Arrays.asList(STATUS.QUEUED), new QueryContext());
    assertEquals(1, rescheduled.size());
    executorService.cancelRequest(rescheduled.get(0).getId());
    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(3, executedRequests.size());
}
Also used : 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 20 with CountDownAsyncJobListener

use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.

the class BasicExecutorBaseTest method executorExceptionTest.

@Test(timeout = 10000)
public void executorExceptionTest() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    CommandContext commandContext = new CommandContext();
    commandContext.setData("businessKey", UUID.randomUUID().toString());
    cachedEntities.put((String) commandContext.getData("businessKey"), new AtomicLong(1));
    commandContext.setData("callbacks", "org.jbpm.executor.SimpleIncrementCallback");
    commandContext.setData("retries", 0);
    executorService.scheduleRequest("org.jbpm.executor.ThrowExceptionCommand", commandContext);
    logger.info("{} Sleeping for 10 secs", System.currentTimeMillis());
    countDownListener.waitTillCompleted();
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(1, inErrorRequests.size());
    logger.info("Error: {}", inErrorRequests.get(0));
    assertEquals(1, inErrorRequests.get(0).getExecutions());
    List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
    logger.info("Errors: {}", errors);
    assertEquals(1, errors.size());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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)

Aggregations

CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)50 Test (org.junit.Test)43 QueryContext (org.kie.api.runtime.query.QueryContext)27 CommandContext (org.kie.api.executor.CommandContext)25 RequestInfo (org.kie.api.executor.RequestInfo)25 KieSession (org.kie.api.runtime.KieSession)20 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)20 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)19 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)19 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)19 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)17 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 HashMap (java.util.HashMap)8 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)7 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)7 TaskSummary (org.kie.api.task.model.TaskSummary)7 ExecutionError (org.kie.internal.runtime.error.ExecutionError)7 ExecutionErrorStorage (org.kie.internal.runtime.error.ExecutionErrorStorage)7 ErrorInfo (org.kie.api.executor.ErrorInfo)6 Date (java.util.Date)5