AnsweredAssumed Answered

Timer Duration seems not to be working

Question asked by victorbos on Mar 1, 2016
Latest reply on Mar 1, 2016 by jbarrez
Hi all,

First of all let me say that I'm new to activiti and therefore might do something silly :-)
The thing is that I'm creating a unit test against a bpmn diagram that starts with a Timer start event in which i set the duration to 1 hour (PT1H). So I expect the process to wait for an hour before it continues. But instead of that I see that it progresses immediately. There must be something wrong in my setup I guess…..
Hope you can help!

Victor

This is the simple flow that I created to test the timer start event. It has a script with a counter and a gateway that will loop back to the start event five times. In the output I see that it hits the script without the hour delay that I expect:
<code>
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
   <process id="TestTimer" name="TestTimer" isExecutable="true">
      <startEvent id="timerstartevent1" name="Timer start">
         <timerEventDefinition>
            <timeDuration>PT1H</timeDuration>
         </timerEventDefinition>
      </startEvent>
      <endEvent id="endevent1" name="End"></endEvent>
      <scriptTask id="scripttask1" name="Script Task" scriptFormat="groovy">
         <script>def count = execution.getVariable("count") ?: 0
            count ++
            execution.setVariable("count", count)
            println("&gt;&gt;&gt;" + new Date() + " count=" + count)
         </script>
      </scriptTask>
      <sequenceFlow id="flow1" sourceRef="timerstartevent1" targetRef="scripttask1"></sequenceFlow>
      <sequenceFlow id="flow2" sourceRef="scripttask1" targetRef="exclusivegateway1"></sequenceFlow>
      <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
      <sequenceFlow id="flow3" sourceRef="exclusivegateway1" targetRef="timerstartevent1">
         <conditionExpression xsi:type="tFormalExpression"><![CDATA[${count<5}]]></conditionExpression>
      </sequenceFlow>
      <sequenceFlow id="flow4" sourceRef="exclusivegateway1" targetRef="endevent1">
         <conditionExpression xsi:type="tFormalExpression"><![CDATA[${count>=5}]]></conditionExpression>
      </sequenceFlow>
   </process>
</definitions>
<code>

And the corresponding unit test:
<code>
public class TestTimer {
   ProcessEngine processEngine;
   ActivitiRule activitiRule;

   @Before
   public void setup(){
      processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration().buildProcessEngine();
      activitiRule = new ActivitiRule(processEngine);
   }

   @Test
   public void testTimer(){
      Deployment deployment = processEngine.getRepositoryService().createDeployment().addClasspathResource("diagrams/TestTimer.bpmn").deploy();
      activitiRule.getRuntimeService().startProcessInstanceByKey("TestTimer");
   }
}
<code>

Outcomes