AnsweredAssumed Answered

Multiple Timer Boundary Event not working

Question asked by det on May 11, 2016
Latest reply on May 15, 2016 by det
I'm trying to attach two Timer Boundary Events to a single user task.

One boundary event is using Time Cycle with two repetitions (R2/PT1S) and the other is using Time Duration (PT10S).

This is the process:
<code lang="xml">
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="User Task"></userTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <boundaryEvent id="boundarytimer1" name="Timer" attachedToRef="usertask1" cancelActivity="false">
      <timerEventDefinition>
        <timeCycle>R2/PT1S</timeCycle>
      </timerEventDefinition>
    </boundaryEvent>
    <boundaryEvent id="boundarytimer2" name="Timer" attachedToRef="usertask1" cancelActivity="true">
      <timerEventDefinition>
        <timeDuration>PT10S</timeDuration>
      </timerEventDefinition>
    </boundaryEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <manualTask id="manualtask1" name="Manual Task"></manualTask>
    <manualTask id="manualtask2" name="Manual Task"></manualTask>
    <sequenceFlow id="flow2" sourceRef="boundarytimer1" targetRef="manualtask1"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="boundarytimer2" targetRef="manualtask2"></sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="manualtask2" targetRef="endevent1"></sequenceFlow>
  </process>
</code>

And here is a unit test:
<code lang="java">
   public void testMultipleTimerBoundary() {

      runtimeService.startProcessInstanceByKey("myProcess");
      
      Task task = taskService.createTaskQuery().singleResult();
      assertThat(task.getTaskDefinitionKey(), equalTo("usertask1"));

      Calendar oneHour = Calendar.getInstance();
      oneHour.add(Calendar.HOUR, 1);
      processEngineConfiguration.getClock().setCurrentTime(oneHour.getTime());
      
      JobTestHelper.waitForJobExecutorToProcessAllJobs(activitiRule, 1000*30, 1000);
      
      List<HistoricActivityInstance> historicActivities =
         historyService.createHistoricActivityInstanceQuery()
            .finished()
            .orderByHistoricActivityInstanceStartTime()
            .asc()
            .list();
      
      List<String> activityIds = new ArrayList<>();
      for (HistoricActivityInstance instance : historicActivities) {
         activityIds.add(instance.getActivityId());
      }
      
      List<String> expectedIds = Arrays.asList(
         "startevent1",
         "usertask1",
         "boundarytimer1",
         "manualtask1",
         "boundarytimer1",
         "manualtask1",
         "boundarytimer2",
         "manualtask2",
         "endevent1");
      
      assertEquals(expectedIds, activityIds);
   }
</code>

<code lang="java">
java.lang.AssertionError: expected:<[startevent1, usertask1, boundarytimer1, manualtask1, boundarytimer1, manualtask1, boundarytimer2, manualtask2, endevent1]> but was:<[startevent1, usertask1, boundarytimer1, manualtask1, boundarytimer2, manualtask2, endevent1]>
</code>

I would expect that 'manualtask1' would be executed twice during the 10second duration but it is only occurring once.

If I remove 'boundarytimer2', the 'manualtask1' task gets executed twice as expected.

Please advise whether this scenario is not possible with Activiti or is this a bug?

Outcomes