cancel
Showing results for 
Search instead for 
Did you mean: 

BPM Timer Expiry

samsmith
Champ in-the-making
Champ in-the-making
Hi,

I have got a BPM process that has got an 'Timer Intermediate Catch Event' with duration set to 10 seconds [PT10S].
When I try to unit test the BPM process, I noticed that  the timer doesn't get expired at all. 'asyncExecutorActivate' property is set to true.


But when I write the following code in my unit test, then the timer does get expired after 10 seconds.

JobQuery jobQuery = processEngine.getManagementService().createJobQuery().processInstanceId(processInstance.getId());
Date startTime = new Date();
processEngine.getProcessEngineConfiguration().getClock().setCurrentTime(new Date(startTime.getTime() + (10 * 1000) + 1000));
JobTestHelper.waitForJobExecutorToProcessAllJobs(processEngine.getProcessEngineConfiguration(), processEngine.getManagementService(), 10000L, 25L);
assertEquals(0L, jobQuery.count());


My question is that why do I have to write the above code for the timer to work from my unit test.

Thanks
3 REPLIES 3

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Sam,

explanation could be

  public static void waitForJobExecutorToProcessAllJobs(ProcessEngineConfiguration processEngineConfiguration,
      ManagementService managementService, long maxMillisToWait, long intervalMillis, boolean shutdownExecutorWhenFinished) {
   
    JobExecutor jobExecutor = null;
    AsyncExecutor asyncExecutor = null;
    if (processEngineConfiguration.isAsyncExecutorEnabled() == false) {
      jobExecutor = processEngineConfiguration.getJobExecutor();
      jobExecutor.start();
     
    } else {
      asyncExecutor = processEngineConfiguration.getAsyncExecutor();
      asyncExecutor.start();
    }


Regards
Martin

samsmith
Champ in-the-making
Champ in-the-making
Hi Martin,

When I test my code in tomcat using  Activiti - Explorer, then the timer does expire automatically  after 10 seconds, but in my junit, I have to write a snippet of code. Are you implying that in tomcat, the 'asyncExecutor' is automatically started on the server start whereas in J-Unit, I start the 'asyncExecutor' by calling the below code:

JobTestHelper.waitForJobExecutorToProcessAllJobs(processEngine.getProcessEngineConfiguration(), processEngine.getManagementService(), 10000L, 25L);

Thanks

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Sam,

it all depends on your process engine configuration. (By default job executor is not started in jUnit test)

Regards
Martin