Uploaded image for project: 'jBPM'
  1. jBPM
  2. JBPM-2528

Behavior of tasks completion when inside two or more

    XMLWordPrintable

Details

    Description

      I do not understand the behavior of tasks completion when they are inside two or more forks. You will find the accurate questions in the test case comments.

      [code]
      <?xml version="1.0" encoding="UTF-8"?>
      <process key="test1" name="test1" xmlns="http://jbpm.org/4.0/jpdl">
      <start name="start1">
      <transition name="to fork1" to="fork1"/>
      </start>
      <fork name="fork1">
      <transition name="to task1" to="task1"/>
      <transition name="to task2" to="task2"/>
      </fork>
      <task name="task2">
      <transition name="to join2" to="join2"/>
      </task>
      <task name="task1">
      <transition name="to fork2" to="fork2"/>
      </task>
      <fork name="fork2">
      <transition name="to task1.1" to="task1.1"/>
      <transition name="to task1.2" to="task1.2"/>
      </fork>
      <taskname="task1.1">
      <transition name="to join1" to="join1"/>
      </task>
      <task name="task1.2">
      <transition name="to join1" to="join1"/>
      </task>
      <join name="join1">
      <transition name="to join2" to="join2"/>
      </join>
      <join name="join2">
      <transition name="to end1" to="end1"/>
      </join>
      <end name="end1"/>
      </process>
      [/code]

      [code]
      // test case which extends JbpmTestCase
      public void testTaskConcurrency() {
      repositoryService.createDeployment().addResourceFromClasspath("test1.jpdl.xml").deploy();

      ProcessInstance processInstance = executionService.startProcessInstanceByKey("test1");
      String processInstanceId = processInstance.getId();
      System.out.println("Process started:");
      for (Task taskTemp : taskService.createTaskQuery().processInstanceId(processInstanceId).list())

      { System.out.println(String.format("> Task '%s' with execution '%s'", taskTemp.getActivityName(), taskTemp.getExecutionId())); }
      /* Output (ok):
      * > Task 'task1' with execution 'test1.1.to task1'
      * > Task 'task2' with execution 'test1.1.to task2'
      */

      Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).activityName("task1").uniqueResult();
      taskService.completeTask(task.getId());
      System.out.println("task1 completed:");
      for (Task taskTemp : taskService.createTaskQuery().processInstanceId(processInstanceId).list()) { System.out.println(String.format("> Task '%s' with execution '%s'", taskTemp.getActivityName(), taskTemp.getExecutionId())); }

      /* Output (strange):

      • > Task 'task2' with execution 'test1.1.to task2'
      • > Task 'task1.1' with execution 'test1.1.to task1.1'
      • > Task 'task1.2' with execution 'test1.1.to task1.2'
      • > Task 'task1.1' with execution 'test1.1.to task1'
        */
        /* Questions:
      • Why do I have 2 different 'task1.1' (with different execution id)?
      • Which one should I complete?
      • Imagine task1 is not a task but a subprocess, this subprocess would be started twice. Is it norm
        al?
        */

      // I cannot use the uniqueResult() method (the task I want to get is not unique)
      task = taskService.createTaskQuery().processInstanceId(processInstanceId).activityName("task1.1").list().get(0);
      taskService.completeTask(task.getId());
      System.out.println("task1.1 completed:");
      for (Task taskTemp : taskService.createTaskQuery().processInstanceId(processInstanceId).list())

      { System.out.println(String.format("> Task '%s' with execution '%s'", taskTemp.getActivityName(), taskTemp.getExecutionId())); }
      /* Output (still strange):
      * > Task 'task2' with execution 'test1.1.to task2'
      * > Task 'task1.1' with execution 'test1.1.to task1.1'
      * > Task 'task1.2' with execution 'test1.1.to task1.2'
      */

      task = taskService.createTaskQuery().processInstanceId(processInstanceId).activityName("task1.2").uniqueResult();
      taskService.completeTask(task.getId());
      System.out.println("task1.2 completed:");
      for (Task taskTemp : taskService.createTaskQuery().processInstanceId(processInstanceId).list()) { System.out.println(String.format("> Task '%s' with execution '%s'", taskTemp.getActivityName(), taskTemp.getExecutionId())); }

      /* Output (still strange):

      • > Task 'task2' with execution 'test1.1.to task2'
      • > Task 'task1.1' with execution 'test1.1.to task1.1'
        */
        /* Question:
      • I reached the first join, why do I still see the second 'task1.1'?
        */

      task = taskService.createTaskQuery().processInstanceId(processInstanceId).activityName("task2").uniqueResult();
      taskService.completeTask(task.getId());
      System.out.println("task2 completed:");
      for (Task taskTemp : taskService.createTaskQuery().processInstanceId(processInstanceId).list())

      { System.out.println(String.format("> Task '%s' with execution '%s'", taskTemp.getActivityName(), taskTemp.getExecutionId())); }

      /* Output (ok):

      • [nothing]
        */
        }
        [/code]

      Attachments

        Activity

          People

            Unassigned Unassigned
            romain_l-m Romain LM (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: