Search in sources :

Example 56 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class MessageIntermediateEventTest method testConcurrentIntermediateMessageEvent.

@Deployment
public void testConcurrentIntermediateMessageEvent() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(pi.getId());
    assertNotNull(activeActivityIds);
    assertEquals(2, activeActivityIds.size());
    assertTrue(activeActivityIds.contains("messageCatch1"));
    assertTrue(activeActivityIds.contains("messageCatch2"));
    String messageName = "newInvoiceMessage";
    List<Execution> executions = runtimeService.createExecutionQuery().messageEventSubscriptionName(messageName).list();
    assertNotNull(executions);
    assertEquals(2, executions.size());
    runtimeService.messageEventReceived(messageName, executions.get(0).getId());
    Task task = taskService.createTaskQuery().singleResult();
    assertNull(task);
    runtimeService.messageEventReceived(messageName, executions.get(1).getId());
    task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    taskService.complete(task.getId());
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 57 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class MessageNonInterruptingBoundaryEventTest method testSingleNonInterruptingBoundaryMessageEvent.

@Deployment
public void testSingleNonInterruptingBoundaryMessageEvent() {
    runtimeService.startProcessInstanceByKey("process");
    assertEquals(2, runtimeService.createExecutionQuery().count());
    Task userTask = taskService.createTaskQuery().taskDefinitionKey("task").singleResult();
    assertNotNull(userTask);
    Execution execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
    assertNotNull(execution);
    // 1. case: message received before completing the task
    runtimeService.messageEventReceived("messageName", execution.getId());
    // event subscription not removed
    execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
    assertNotNull(execution);
    assertEquals(2, taskService.createTaskQuery().count());
    userTask = taskService.createTaskQuery().taskDefinitionKey("taskAfterMessage").singleResult();
    assertNotNull(userTask);
    assertEquals("taskAfterMessage", userTask.getTaskDefinitionKey());
    taskService.complete(userTask.getId());
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    // send a message a second time
    runtimeService.messageEventReceived("messageName", execution.getId());
    // event subscription not removed
    execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
    assertNotNull(execution);
    assertEquals(2, taskService.createTaskQuery().count());
    userTask = taskService.createTaskQuery().taskDefinitionKey("taskAfterMessage").singleResult();
    assertNotNull(userTask);
    assertEquals("taskAfterMessage", userTask.getTaskDefinitionKey());
    taskService.complete(userTask.getId());
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    // now complete the user task with the message boundary event
    userTask = taskService.createTaskQuery().taskDefinitionKey("task").singleResult();
    assertNotNull(userTask);
    taskService.complete(userTask.getId());
    // event subscription removed
    execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
    assertNull(execution);
    userTask = taskService.createTaskQuery().taskDefinitionKey("taskAfterTask").singleResult();
    assertNotNull(userTask);
    taskService.complete(userTask.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    // 2nd. case: complete the user task cancels the message subscription
    runtimeService.startProcessInstanceByKey("process");
    userTask = taskService.createTaskQuery().taskDefinitionKey("task").singleResult();
    assertNotNull(userTask);
    taskService.complete(userTask.getId());
    execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
    assertNull(execution);
    userTask = taskService.createTaskQuery().taskDefinitionKey("taskAfterTask").singleResult();
    assertNotNull(userTask);
    assertEquals("taskAfterTask", userTask.getTaskDefinitionKey());
    taskService.complete(userTask.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) Deployment(org.activiti.engine.test.Deployment)

Example 58 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class InclusiveGatewayDefaultFlowTest method testCompatibleConditionFlow.

public void testCompatibleConditionFlow() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("var1", "true");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_DEFINITION_KEY, variables);
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("usertask2").singleResult();
    assertNotNull(execution);
    assertEquals("usertask2", execution.getActivityId());
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 59 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class SignalEventTest method testAsyncTriggeredSignalEvent.

@Deployment
public void testAsyncTriggeredSignalEvent() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processWithSignalCatch");
    assertNotNull(processInstance);
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).signalEventSubscriptionName("The Signal").singleResult();
    assertNotNull(execution);
    assertEquals(1, createEventSubscriptionQuery().count());
    assertEquals(2, runtimeService.createExecutionQuery().count());
    runtimeService.signalEventReceivedAsync("The Signal", execution.getId());
    assertEquals(1, managementService.createJobQuery().messages().count());
    waitForJobExecutorToProcessAllJobs(8000L, 200L);
    assertEquals(0, createEventSubscriptionQuery().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    assertEquals(0, managementService.createJobQuery().count());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 60 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class InclusiveGatewayTest method testLoop.

/** This test the isReachable() check thaty is done to check if 
   * upstream tokens can reach the inclusive gateway.
   * 
   * In case of loops, special care needs to be taken in the algorithm,
   * or else stackoverflows will happen very quickly.
   */
@Deployment
public void testLoop() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("inclusiveTestLoop", CollectionUtil.singletonMap("counter", 1));
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("task C", task.getName());
    taskService.complete(task.getId());
    assertEquals(0, taskService.createTaskQuery().count());
    for (Execution execution : runtimeService.createExecutionQuery().list()) {
        System.out.println(execution.getActivityId());
    }
    assertEquals("Found executions: " + runtimeService.createExecutionQuery().list(), 0, runtimeService.createExecutionQuery().count());
    assertProcessEnded(pi.getId());
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Execution (org.activiti.engine.runtime.Execution)131 Deployment (org.activiti.engine.test.Deployment)105 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)75 Task (org.activiti.engine.task.Task)33 HashMap (java.util.HashMap)30 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)12 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)10 ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)10 HttpPut (org.apache.http.client.methods.HttpPut)10 StringEntity (org.apache.http.entity.StringEntity)9 ArrayList (java.util.ArrayList)8 ActivitiException (org.activiti.engine.ActivitiException)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Date (java.util.Date)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5