cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Timer Boundary Event not working

det
Champ in-the-making
Champ in-the-making
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?
2 REPLIES 2

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi det,

Does it happen when you change timers to
t1 -> R2/10S
t2 -> 30S
(change wait time too)

Regards
Martin

det
Champ in-the-making
Champ in-the-making
I increased the timers to

T1 -> R2/P3D

T2 -> P10D

This was still an issue so I changed the clock time to increment in 3 day blocks and called waitForJobExecutorToProcessAllJobs() after each increment. It works now.

So the issue was with my unit test, not a a bug. Sorry for the confusion.