Search in sources :

Example 16 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class BasicExecutorBaseTest method testPrioritizedJobsExecution.

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

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class BasicExecutorBaseTest method testProcessContextJobsExecution.

@Test(timeout = 10000)
public void testProcessContextJobsExecution() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    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> 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());
    countDownListener.waitTillCompleted(5000);
    inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(0, inErrorRequests.size());
    queuedRequests = executorService.getQueuedRequests(new QueryContext());
    assertEquals(1, queuedRequests.size());
    executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(0, executedRequests.size());
    executorService.cancelRequest(requestId);
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) 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)

Example 18 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class BasicExecutorBaseTest method executorExceptionTrimmingTest.

@Test(timeout = 10000)
public void executorExceptionTrimmingTest() throws InterruptedException {
    System.setProperty("org.kie.executor.msg.length", "10");
    System.setProperty("org.kie.executor.stacktrace.length", "20");
    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");
    commandContext.setData("retries", 0);
    executorService.scheduleRequest("org.jbpm.executor.ThrowExceptionCommand", commandContext);
    logger.info("{} Sleeping for 10 secs", System.currentTimeMillis());
    countDownListener.waitTillCompleted();
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(1, inErrorRequests.size());
    logger.info("Error: {}", inErrorRequests.get(0));
    List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
    logger.info("Errors: {}", errors);
    assertEquals(1, errors.size());
    ErrorInfo error = errors.get(0);
    assertEquals(10, error.getMessage().length());
    assertEquals(20, error.getStacktrace().length());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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 19 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class BasicExecutorBaseTest method reoccurringExecutionTest.

@Test(timeout = 10000)
public void reoccurringExecutionTest() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(3);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    executorService.scheduleRequest("org.jbpm.executor.commands.ReoccurringPrintOutCommand", ctxCMD);
    countDownListener.waitTillCompleted();
    List<RequestInfo> rescheduled = executorService.getRequestsByBusinessKey((String) ctxCMD.getData("businessKey"), Arrays.asList(STATUS.QUEUED), new QueryContext());
    assertEquals(1, rescheduled.size());
    executorService.cancelRequest(rescheduled.get(0).getId());
    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(3, 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)

Example 20 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class BasicExecutorBaseTest method executorExceptionTest.

@Test(timeout = 10000)
public void executorExceptionTest() 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");
    commandContext.setData("retries", 0);
    executorService.scheduleRequest("org.jbpm.executor.ThrowExceptionCommand", commandContext);
    logger.info("{} Sleeping for 10 secs", System.currentTimeMillis());
    countDownListener.waitTillCompleted();
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(1, inErrorRequests.size());
    logger.info("Error: {}", inErrorRequests.get(0));
    assertEquals(1, inErrorRequests.get(0).getExecutions());
    List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
    logger.info("Errors: {}", errors);
    assertEquals(1, errors.size());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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)

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