Search in sources :

Example 41 with CountDownAsyncJobListener

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

the class BasicExecutorBaseTest method multipleCallbackTest.

@Test(timeout = 10000)
public void multipleCallbackTest() 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, org.jbpm.executor.test.CustomCallback");
    executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", commandContext);
    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(1, executedRequests.size());
    assertEquals(3, ((AtomicLong) cachedEntities.get((String) commandContext.getData("businessKey"))).longValue());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) AtomicLong(java.util.concurrent.atomic.AtomicLong) CommandContext(org.kie.api.executor.CommandContext) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 42 with CountDownAsyncJobListener

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

the class BasicExecutorBaseTest method testPrioritizedJobsExecutionInvalidProrities.

@Test(timeout = 10000)
public void testPrioritizedJobsExecutionInvalidProrities() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(2);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", "low priority");
    ctxCMD.setData("priority", -1);
    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", 10);
    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 43 with CountDownAsyncJobListener

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

the class BasicExecutorBaseTest method testUpdateRequestData.

@Test(timeout = 10000)
public void testUpdateRequestData() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(2);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    ctxCMD.setData("retryDelay", "1s, 2s");
    Long requestId = executorService.scheduleRequest("org.jbpm.executor.test.MissingDataCommand", ctxCMD);
    countDownListener.waitTillCompleted();
    List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(0, executedRequests.size());
    Map<String, Object> fixedData = new HashMap<>();
    fixedData.put("amount", 200);
    executorService.updateRequestData(requestId, fixedData);
    countDownListener.reset(1);
    countDownListener.waitTillCompleted();
    executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(1, executedRequests.size());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) CommandContext(org.kie.api.executor.CommandContext) HashMap(java.util.HashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 44 with CountDownAsyncJobListener

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

the class BasicExecutorBaseTest method callbackTest.

@Test(timeout = 10000)
public void callbackTest() 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");
    executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", commandContext);
    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(1, executedRequests.size());
    assertEquals(2, ((AtomicLong) cachedEntities.get((String) commandContext.getData("businessKey"))).longValue());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) AtomicLong(java.util.concurrent.atomic.AtomicLong) CommandContext(org.kie.api.executor.CommandContext) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 45 with CountDownAsyncJobListener

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

the class BasicExecutorBaseTest method testReturnNullCommand.

@Test(timeout = 10000)
public void testReturnNullCommand() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    executorService.scheduleRequest("org.jbpm.executor.test.ReturnNullCommand", ctxCMD);
    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(1, 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)

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