Search in sources :

Example 6 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class ExclusiveTimerEventTest method testCatchingTimerEvent.

@Deployment
public void testCatchingTimerEvent() throws Exception {
    // Set the clock fixed
    Date startTime = new Date();
    // After process start, there should be 3 timers created
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("exclusiveTimers");
    TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    assertThat(jobQuery.count()).isEqualTo(3);
    // After setting the clock to time '50minutes and 5 seconds', the timers should fire
    processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((50 * 60 * 1000) + 5000)));
    waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(5000L, 500L);
    assertThat(jobQuery.count()).isEqualTo(0);
    assertProcessEnded(pi.getProcessInstanceId());
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Date(java.util.Date) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 7 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class StartTimerEventTest method testDurationStartTimerEvent.

@Deployment
public void testDurationStartTimerEvent() throws Exception {
    // Set the clock fixed
    Date startTime = new Date();
    // After process start, there should be timer created
    TimerJobQuery jobQuery = managementService.createTimerJobQuery();
    assertThat(jobQuery.count()).isEqualTo(1);
    // After setting the clock to time '50 minutes and 5 seconds', the second timer should fire
    processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((50 * 60 * 1000) + 5000)));
    waitForJobExecutorToProcessAllJobs(5000L, 200L);
    List<ProcessInstance> pi = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample").list();
    assertThat(pi).hasSize(1);
    assertThat(jobQuery.count()).isEqualTo(0);
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Date(java.util.Date) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 8 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class StartTimerEventTest method testCycleDateStartTimerEvent.

// FIXME: This test likes to run in an endless loop when invoking the
// waitForJobExecutorOnCondition method
@Deployment
public void testCycleDateStartTimerEvent() throws Exception {
    processEngineConfiguration.getClock().setCurrentTime(new Date());
    // After process start, there should be timer created
    TimerJobQuery jobQuery = managementService.createTimerJobQuery();
    assertThat(jobQuery.count()).isEqualTo(1);
    final ProcessInstanceQuery piq = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample");
    moveByMinutes(5);
    waitForJobExecutorOnCondition(10000, 500, new Callable<Boolean>() {

        public Boolean call() throws Exception {
            return 1 == piq.count();
        }
    });
    assertThat(jobQuery.count()).isEqualTo(1);
    moveByMinutes(5);
    waitForJobExecutorOnCondition(10000, 500, new Callable<Boolean>() {

        public Boolean call() throws Exception {
            return 2 == piq.count();
        }
    });
    assertThat(jobQuery.count()).isEqualTo(1);
    // have to manually delete pending timer
    cleanDB();
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) Date(java.util.Date) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 9 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class StartTimerEventTest method testTimerShouldNotBeRecreatedOnDeploymentCacheReboot.

@Deployment
public void testTimerShouldNotBeRecreatedOnDeploymentCacheReboot() {
    // Just to be sure, I added this test. Sounds like something that could easily happen
    // when the order of deploy/parsing is altered.
    // After process start, there should be timer created
    TimerJobQuery jobQuery = managementService.createTimerJobQuery();
    assertThat(jobQuery.count()).isEqualTo(1);
    // Reset deployment cache
    processEngineConfiguration.getProcessDefinitionCache().clear();
    // Start one instance of the process definition, this will trigger a
    // cache reload
    runtimeService.startProcessInstanceByKey("startTimer");
    // No new jobs should have been created
    assertThat(jobQuery.count()).isEqualTo(1);
}
Also used : TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 10 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class StartTimerEventTest method testExpressionStartTimerEvent.

@Deployment
public void testExpressionStartTimerEvent() throws Exception {
    // ACT-1415: fixed start-date is an expression
    TimerJobQuery jobQuery = managementService.createTimerJobQuery();
    assertThat(jobQuery.count()).isEqualTo(1);
    processEngineConfiguration.getClock().setCurrentTime(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("15/11/2036 11:12:30"));
    waitForJobExecutorToProcessAllJobs(5000L, 200L);
    List<ProcessInstance> pi = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample").list();
    assertThat(pi).hasSize(1);
    assertThat(jobQuery.count()).isEqualTo(0);
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SimpleDateFormat(java.text.SimpleDateFormat) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Aggregations

TimerJobQuery (org.activiti.engine.runtime.TimerJobQuery)35 Deployment (org.activiti.engine.test.Deployment)20 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)18 Date (java.util.Date)16 Job (org.activiti.engine.runtime.Job)10 JobQuery (org.activiti.engine.runtime.JobQuery)7 Task (org.activiti.engine.task.Task)5 HashMap (java.util.HashMap)3 Execution (org.activiti.engine.runtime.Execution)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 ProcessInstanceQuery (org.activiti.engine.runtime.ProcessInstanceQuery)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 List (java.util.List)1 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)1 Test (org.junit.Test)1