Search in sources :

Example 21 with CountDownAsyncJobListener

use of org.jbpm.executor.test.CountDownAsyncJobListener 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 CountDownAsyncJobListener

use of org.jbpm.executor.test.CountDownAsyncJobListener 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 CountDownAsyncJobListener

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

the class BasicExecutorBaseTest method configureListener.

protected CountDownAsyncJobListener configureListener(int threads) {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(threads);
    ((ExecutorServiceImpl) executorService).addAsyncJobListener(countDownListener);
    return countDownListener;
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl)

Example 24 with CountDownAsyncJobListener

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

the class ReconfiguredExecutorTest method configureListener.

protected CountDownAsyncJobListener configureListener(int threads) {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(threads);
    ((ExecutorServiceImpl) executorService).addAsyncJobListener(countDownListener);
    return countDownListener;
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl)

Example 25 with CountDownAsyncJobListener

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

the class JmsAvaiableJobExecutorTest method configureListener.

protected CountDownAsyncJobListener configureListener(int threads) {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(threads);
    ((ExecutorServiceImpl) executorService).addAsyncJobListener(countDownListener);
    return countDownListener;
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl)

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