Search in sources :

Example 21 with RequestInfo

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

the class BasicExecutorBaseTest method testCustomConstantRequestRetry.

@Test(timeout = 10000)
public void testCustomConstantRequestRetry() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(3);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    ctxCMD.setData("retryDelay", "2s");
    ctxCMD.setData("retries", 2);
    executorService.scheduleRequest("org.jbpm.executor.ThrowExceptionCommand", ctxCMD);
    countDownListener.waitTillCompleted();
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(1, inErrorRequests.size());
    RequestInfo failedJob = inErrorRequests.get(0);
    assertEquals(3, failedJob.getExecutions());
    List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
    // Three retries means 4 executions in total 1(regular) + 2(retries)
    assertEquals(3, errors.size());
    long firstError = errors.get(0).getTime().getTime();
    long secondError = errors.get(1).getTime().getTime();
    long thirdError = errors.get(2).getTime().getTime();
    // time difference between first and second should be at least 3 seconds
    long diff = secondError - firstError;
    assertTrue(diff > 2000);
    // time difference between second and third should be at least 6 seconds
    diff = thirdError - secondError;
    assertTrue(diff > 2000);
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) 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 22 with RequestInfo

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

the class BasicExecutorBaseTest method testCustomIncrementingRequestRetry.

@Test(timeout = 10000)
public void testCustomIncrementingRequestRetry() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(3);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    ctxCMD.setData("retryDelay", "3s, 6s");
    ctxCMD.setData("retries", 2);
    executorService.scheduleRequest("org.jbpm.executor.ThrowExceptionCommand", ctxCMD);
    countDownListener.waitTillCompleted();
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(1, inErrorRequests.size());
    List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
    // Three retries means 4 executions in total 1(regular) + 3(retries)
    assertEquals(3, errors.size());
    long firstError = errors.get(0).getTime().getTime();
    long secondError = errors.get(1).getTime().getTime();
    long thirdError = errors.get(2).getTime().getTime();
    // time difference between first and second should be at least 3 seconds
    long diff = secondError - firstError;
    assertTrue(diff > 3000);
    // time difference between second and third should be at least 6 seconds
    diff = thirdError - secondError;
    assertTrue(diff > 6000);
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) 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 23 with RequestInfo

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

the class JmsAvaiableJobExecutorTest method testAsyncAuditProducerNotExistingDeployment.

@Test
public void testAsyncAuditProducerNotExistingDeployment() throws Exception {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    ctxCMD.setData("deploymentId", "not-existing");
    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, 3000);
    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());
}
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 24 with RequestInfo

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

the class BasicExecutorIntegrationTest method cancelRequestTest.

@Test
public void cancelRequestTest() throws InterruptedException {
    // The executor is on purpose not started to not fight against race condition
    // with the request cancelations.
    CommandContext ctxCMD = new CommandContext();
    String businessKey = UUID.randomUUID().toString();
    ctxCMD.setData("businessKey", businessKey);
    Date futureDate = new Date(System.currentTimeMillis() + 5000);
    Long requestId = executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", futureDate, ctxCMD);
    List<RequestInfo> requests = executorService.getRequestsByBusinessKey(businessKey, new QueryContext());
    assertNotNull(requests);
    assertEquals(1, requests.size());
    assertEquals(requestId, requests.get(0).getId());
    // cancel the task immediately
    executorService.cancelRequest(requestId);
    List<RequestInfo> cancelledRequests = executorService.getCancelledRequests(new QueryContext());
    assertEquals(1, cancelledRequests.size());
}
Also used : 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) Date(java.util.Date) Test(org.junit.Test)

Example 25 with RequestInfo

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

the class BasicExecutorIntegrationTest method multipleCallbackTest.

@Test
public void multipleCallbackTest() throws InterruptedException {
    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.ejb.impl.test.SimpleIncrementCallback, org.jbpm.executor.ejb.impl.test.CustomCallback");
    executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", commandContext);
    Thread.sleep(10000);
    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());
    ExecutionResults results = null;
    byte[] responseData = executedRequests.get(0).getResponseData();
    ObjectInputStream in = null;
    try {
        in = new ObjectInputStream(new ByteArrayInputStream(responseData));
        results = (ExecutionResults) in.readObject();
    } catch (Exception e) {
        logger.warn("Exception while serializing context data", e);
        return;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    String result = (String) results.getData("custom");
    assertNotNull(result);
    assertEquals("custom callback invoked", result);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CommandContext(org.kie.api.executor.CommandContext) ByteArrayInputStream(java.io.ByteArrayInputStream) ExecutionResults(org.kie.api.executor.ExecutionResults) QueryContext(org.kie.api.runtime.query.QueryContext) IOException(java.io.IOException) RequestInfo(org.kie.api.executor.RequestInfo) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream) 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