Search in sources :

Example 51 with CommandContext

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

the class BasicExecutorIntegrationTest method callbackTest.

@Test
public void callbackTest() 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");
    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());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CommandContext(org.kie.api.executor.CommandContext) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 52 with CommandContext

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

the class AsyncIntermediateCatchSignalTest method testCorrectProcessStateAfterExceptionSignalCommandMulti.

@Test(timeout = 20000)
public void testCorrectProcessStateAfterExceptionSignalCommandMulti() throws InterruptedException {
    latch = new CountDownLatch(5);
    RuntimeManager runtimeManager = createRuntimeManager(BPMN_AICS);
    KieSession ksession = getRuntimeEngine().getKieSession();
    long[] pid = new long[5];
    for (int i = 0; i < 5; i++) {
        ProcessInstance pi = ksession.startProcess(PROCESS_AICS, null);
        pid[i] = pi.getId();
        CommandContext ctx = new CommandContext();
        ctx.setData("DeploymentId", runtimeManager.getIdentifier());
        ctx.setData("ProcessInstanceId", pi.getId());
        ctx.setData("Signal", "MySignal");
        ctx.setData("Event", null);
        executorService.scheduleRequest(AsyncSignalEventCommand.class.getName(), ctx);
    }
    latch.await();
    for (long p : pid) {
        ProcessInstance pi = ksession.getProcessInstance(p);
        Assertions.assertThat(pi).isNull();
    }
}
Also used : CommandContext(org.kie.api.executor.CommandContext) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncSignalEventCommand(org.jbpm.process.core.async.AsyncSignalEventCommand) Test(org.junit.Test)

Aggregations

CommandContext (org.kie.api.executor.CommandContext)52 Test (org.junit.Test)43 RequestInfo (org.kie.api.executor.RequestInfo)39 QueryContext (org.kie.api.runtime.query.QueryContext)39 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)25 AtomicLong (java.util.concurrent.atomic.AtomicLong)22 Date (java.util.Date)10 ErrorInfo (org.kie.api.executor.ErrorInfo)9 KieSession (org.kie.api.runtime.KieSession)6 HashMap (java.util.HashMap)5 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)5 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 ObjectInputStream (java.io.ObjectInputStream)4 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)4 AsyncSignalEventCommand (org.jbpm.process.core.async.AsyncSignalEventCommand)4 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)4 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)4 UserTransaction (javax.transaction.UserTransaction)3