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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations