Search in sources :

Example 11 with QueryContext

use of org.kie.api.runtime.query.QueryContext 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 QueryContext

use of org.kie.api.runtime.query.QueryContext 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 QueryContext

use of org.kie.api.runtime.query.QueryContext 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 QueryContext

use of org.kie.api.runtime.query.QueryContext 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 QueryContext

use of org.kie.api.runtime.query.QueryContext 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

QueryContext (org.kie.api.runtime.query.QueryContext)315 Test (org.junit.Test)299 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)131 HashMap (java.util.HashMap)115 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)109 ArrayList (java.util.ArrayList)99 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)67 RequestInfo (org.kie.api.executor.RequestInfo)53 TaskSummary (org.kie.api.task.model.TaskSummary)53 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)51 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)49 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)45 CommandContext (org.kie.api.executor.CommandContext)39 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)37 UserImpl (org.jbpm.services.task.impl.model.UserImpl)37 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)36 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)34 QueryFilter (org.kie.internal.query.QueryFilter)30 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)29 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)29