Search in sources :

Example 11 with RequestInfo

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

the class BasicExecutorBaseTest method cancelRequestWithSearchByCommandTest.

@Test(timeout = 10000)
public void cancelRequestWithSearchByCommandTest() throws InterruptedException {
    CommandContext ctxCMD = new CommandContext();
    String businessKey = UUID.randomUUID().toString();
    ctxCMD.setData("businessKey", businessKey);
    Date futureDate = new Date(System.currentTimeMillis() + EXTRA_TIME);
    Long requestId = executorService.scheduleRequest("org.jbpm.executor.test.CustomCommand", futureDate, ctxCMD);
    List<RequestInfo> requests = executorService.getRequestsByCommand("org.jbpm.executor.test.CustomCommand", 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 12 with RequestInfo

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

the class BasicExecutorBaseTest method defaultRequestRetryTest.

@Test(timeout = 10000)
public void defaultRequestRetryTest() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(4);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    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(4, failedJob.getExecutions());
    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());
}
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 13 with RequestInfo

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

the class BasicExecutorBaseTest method cleanupLogExecutionTest.

@Test(timeout = 10000)
public void cleanupLogExecutionTest() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(3);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    Long requestId = executorService.scheduleRequest("org.jbpm.executor.commands.ReoccurringPrintOutCommand", ctxCMD);
    countDownListener.waitTillCompleted();
    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(3, executedRequests.size());
    executorService.cancelRequest(requestId + 3);
    List<RequestInfo> canceled = executorService.getCancelledRequests(new QueryContext());
    ExecutorJPAAuditService auditService = new ExecutorJPAAuditService(emf);
    int resultCount = auditService.requestInfoLogDeleteBuilder().date(canceled.get(0).getTime()).status(STATUS.ERROR).build().execute();
    assertEquals(0, resultCount);
    resultCount = auditService.errorInfoLogDeleteBuilder().date(canceled.get(0).getTime()).build().execute();
    assertEquals(0, resultCount);
    ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    ctxCMD.setData("SingleRun", "true");
    ctxCMD.setData("EmfName", "org.jbpm.executor");
    ctxCMD.setData("SkipProcessLog", "true");
    ctxCMD.setData("SkipTaskLog", "true");
    executorService.scheduleRequest("org.jbpm.executor.commands.LogCleanupCommand", ctxCMD);
    countDownListener.reset(1);
    countDownListener.waitTillCompleted();
    inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(0, inErrorRequests.size());
    queuedRequests = executorService.getQueuedRequests(new QueryContext());
    assertEquals(0, queuedRequests.size());
    executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(1, executedRequests.size());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) CommandContext(org.kie.api.executor.CommandContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryContext(org.kie.api.runtime.query.QueryContext) ExecutorJPAAuditService(org.jbpm.executor.impl.jpa.ExecutorJPAAuditService) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 14 with RequestInfo

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

the class BasicExecutorBaseTest method clearAllRequestsTest.

@Test(timeout = 10000)
public void clearAllRequestsTest() throws InterruptedException {
    CommandContext ctxCMD = new CommandContext();
    String businessKey = UUID.randomUUID().toString();
    ctxCMD.setData("businessKey", businessKey);
    Date futureDate = new Date(System.currentTimeMillis() + EXTRA_TIME);
    // Testing clearing of active request.
    Long requestId = executorService.scheduleRequest("org.jbpm.executor.test.CustomCommand", futureDate, ctxCMD);
    List<RequestInfo> allRequests = executorService.getAllRequests(new QueryContext());
    assertEquals(1, allRequests.size());
    executorService.clearAllRequests();
    allRequests = executorService.getAllRequests(new QueryContext());
    assertEquals(0, allRequests.size());
    // Testing clearing of cancelled request.
    requestId = executorService.scheduleRequest("org.jbpm.executor.test.CustomCommand", futureDate, ctxCMD);
    allRequests = executorService.getAllRequests(new QueryContext());
    assertEquals(1, allRequests.size());
    executorService.cancelRequest(requestId);
    executorService.clearAllRequests();
    allRequests = executorService.getAllRequests(new QueryContext());
    assertEquals(0, allRequests.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 15 with RequestInfo

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

the class BasicExecutorBaseTest method testJobsQueryWithStatus.

@Test(timeout = 10000)
public void testJobsQueryWithStatus() throws InterruptedException {
    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> byKeyRequests = executorService.getRequestsByBusinessKey("low priority", statuses, new QueryContext());
    assertEquals(1, byKeyRequests.size());
    List<RequestInfo> byCommandRequests = executorService.getRequestsByCommand("org.jbpm.executor.commands.PrintOutCommand", statuses, new QueryContext());
    assertEquals(1, byCommandRequests.size());
    statuses = Arrays.asList(STATUS.DONE);
    byDeploymentRequests = executorService.getRequestsByDeployment("not-deployed-here", statuses, new QueryContext());
    assertEquals(0, byDeploymentRequests.size());
    byProcessInstanceRequests = executorService.getRequestsByProcessInstance(2L, statuses, new QueryContext());
    assertEquals(0, byProcessInstanceRequests.size());
    byKeyRequests = executorService.getRequestsByBusinessKey("low priority", statuses, new QueryContext());
    assertEquals(0, byKeyRequests.size());
    byCommandRequests = executorService.getRequestsByCommand("org.jbpm.executor.commands.PrintOutCommand", statuses, new QueryContext());
    assertEquals(0, byCommandRequests.size());
    executorService.cancelRequest(requestId);
}
Also used : 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)

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