I am testing integration of the Activiti engine in a fairly direct fashion (no Tomcat or other container, no spring). So far, so good! I am able to build a custom ServiceTask that calls my JavaDelegate execute() method, access and set variables, and so on. I am also able to call complete() on a UserTask inserted into the process, and I can see that it executes and moves to the next task.
However, while the process without a UserTask completes, the process with a UserTask does not. I can see this calling ProcessInstance.isEnded() and also in the debug log. There must be something trivial I am missing, but I cannot figure it out.
I've packaged this into a simple standalone maven project with a main() and attached the whole project. The main() is shown below.
The attached "activiti-tester.txt" can be renamed to activiti-tester.zip (I hope) for extraction. I've been building with Netbeans, but Eclipse should also work.
When doTest2=true, it runs "test2.bpmn", which is only the service task, and all is well. When doTest2=false, it runs "test1.bpmn" including the user task, and it does not seem to end.
Any help is much appreciated!
public static void main(String[] args) throws Exception {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
TaskService taskService = processEngine.getTaskService();
DeploymentBuilder db = repositoryService.createDeployment();
Deployment d = db.addClasspathResource("test1.bpmn").addClasspathResource("test2.bpmn").deploy();
RuntimeService runtimeService = processEngine.getRuntimeService();
Map<String, Object> variableMap = new HashMap<>();
variableMap.put("name", "john");
System.out.println("Starting");
boolean doTest2 = false;
ProcessInstance processInstance = null;
if (doTest2) {
processInstance = runtimeService.startProcessInstanceByKey("test2", variableMap);
} else {
processInstance = runtimeService.startProcessInstanceByKey("test1", variableMap);
System.out.println("Returned");
String activityId = processInstance.getActivityId();
List<Task> tasks = taskService.createTaskQuery().processInstanceBusinessKey(processInstance.getBusinessKey()).list();
Map<String,Object> vars = new HashMap<>();
vars.put("address", "pobox 16");
taskService.complete(tasks.get(0).getId(), vars);
}
System.out.println("process ended? " + processInstance.isEnded());
Thread.sleep(2000);
System.out.println("process ended? " + processInstance.isEnded());
}