Java Code Examples for org.camunda.bpm.engine.impl.util.ClockUtil#offset()

The following examples show how to use org.camunda.bpm.engine.impl.util.ClockUtil#offset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProcessDataLoggingContextTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@WatchLogger(loggerNames = {JOBEXEC_LOGGER, PVM_LOGGER}, level = "DEBUG")
public void shouldLogMdcPropertiesForTimerInTaskContext() {
  // given
  manageDeployment(Bpmn.createExecutableProcess(PROCESS)
      .startEvent("start")
      .intermediateCatchEvent("timer").timerWithDuration("PT10S")
      .userTask("waitState")
      .endEvent("end")
      .done());
  // when
  ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS, B_KEY);
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(2L));
  testRule.waitForJobExecutorToProcessAllJobs();
  taskService.complete(taskService.createTaskQuery().singleResult().getId());
  // then
  assertActivityLogsPresent(pi, Arrays.asList("start", "timer", "waitState", "end"));
  // job executor logs do not contain MDC properties
  assertActivityLogsPresentWithoutMdc("ENGINE-140");
}
 
Example 2
Source File: ProcessDataLoggingContextTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@WatchLogger(loggerNames = {CONTEXT_LOGGER, JOBEXEC_LOGGER}, level = "WARN")
public void shouldLogFailureFromTimeoutTaskListenerInTaskContext() {
  // given
  manageDeployment(Bpmn.createExecutableProcess(PROCESS)
      .startEvent("start")
      .userTask("failingTask")
        .camundaTaskListenerClassTimeoutWithDuration("failure-listener", FailingTaskListener.class, "PT10S")
      .endEvent("end")
      .done());
  ProcessInstance instance = runtimeService.startProcessInstanceByKey(PROCESS, B_KEY);
  // when
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(2L));
  testRule.waitForJobExecutorToProcessAllJobs();
  // then
  assertFailureLogPresent(instance, "failingTask", 3);
  assertFailureLogPresent(instance, "ENGINE-14006", "failingTask", null, instance.getBusinessKey(), 3);
}
 
Example 3
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryOrderByDeployTime() {
  // given a deployment that is guaranteed to be deployed later than the default deployments
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(10));
  Deployment tempDeploymentOne = repositoryService.createDeployment()
      .addClasspathResource(getResourceOnePath()).addClasspathResource(getResourceOnePath()).deploy();
  engineRule.manageDeployment(tempDeploymentOne);
  
  // when
  ProcessDefinitionQuery processDefinitionOrderByDeploymentTimeAscQuery = 
      repositoryService.createProcessDefinitionQuery().orderByDeploymentTime().asc();
  ProcessDefinitionQuery processDefinitionOrderByDeploymentTimeDescQuery = 
      repositoryService.createProcessDefinitionQuery().orderByDeploymentTime().desc();

  // then
  verifySortingAndCount(processDefinitionOrderByDeploymentTimeAscQuery, 5, 
      processDefinitionByDeployTime(engineRule.getProcessEngine()));
  verifySortingAndCount(processDefinitionOrderByDeploymentTimeDescQuery, 5, 
      inverted(processDefinitionByDeployTime(engineRule.getProcessEngine())));
}
 
Example 4
Source File: MigrationUserTaskTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testAccessModelInNewTimeoutTaskListenerAfterMultipleListenerMigration() {
  // given
  String sourceProcessDefinitionId = testHelper
      .deployAndGetDefinition("org/camunda/bpm/engine/test/api/runtime/migration/MigrationUserTaskTest.noTimeoutTaskListener.bpmn20.xml")
      .getId();
  String targetProcessDefinitionId = testHelper
      .deployAndGetDefinition("org/camunda/bpm/engine/test/api/runtime/migration/MigrationUserTaskTest.twoTimeoutTaskListeners.bpmn20.xml")
      .getId();

  MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinitionId, targetProcessDefinitionId)
    .mapEqualActivities()
    .build();

  // when
  ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan);

  // then
  testHelper.assertTaskListenerTimerJobsCreated("userTask", 2);
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(70L));
  testHelper.waitForJobExecutorToProcessAllJobs(5000L);
  String variableValue =
      (String) rule.getRuntimeService().getVariable(processInstance.getId(), AccessModelInstanceTaskListener.VARIABLE_NAME);
  Assert.assertEquals("userTask", variableValue);
}
 
Example 5
Source File: TaskListenerDelegateCompletionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testCompletionIsPossibleOnTimeout() {
  TaskQuery taskQuery = taskService.createTaskQuery();

  // given
  runtimeService.startProcessInstanceByKey("process");

  // assume
  assertThat(taskQuery.count(), is(1L));

  // when
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(70L));
  testHelper.waitForJobExecutorToProcessAllJobs(5000L);

  // then
  assertThat(taskQuery.count(), is(0L));
}
 
Example 6
Source File: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testMultipleTimeoutTaskListeners() {
  // given
  ProcessInstance instance = runtimeService.startProcessInstanceByKey("process");

  // assume
  assertThat(managementService.createJobQuery().count()).isEqualTo(2L);

  // when
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(70L));
  testRule.waitForJobExecutorToProcessAllJobs(5000L);

  // then
  assertThat(managementService.createJobQuery().count()).isEqualTo(1L);
  assertThat(runtimeService.getVariable(instance.getId(), "timeout-status")).isEqualTo("fired");
}
 
Example 7
Source File: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testTimeoutTaskListenerNotCalledWhenTaskCompletedByBoundaryEvent() {
  // given
  JobQuery jobQuery = managementService.createJobQuery();
  runtimeService.startProcessInstanceByKey("process");

  // assume
  assertThat(jobQuery.count()).isEqualTo(2L);

  // when the boundary event is triggered
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(70L));
  testRule.waitForJobExecutorToProcessAllJobs(5000L);

  // then
  HistoricVariableInstanceQuery variableQuery = historyService.createHistoricVariableInstanceQuery().variableName("timeout-status");
  assertThat(variableQuery.count()).isEqualTo(0L);
  assertThat(jobQuery.count()).isEqualTo(0L);
}
 
Example 8
Source File: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/tasklistener/TaskListenerTest.testRecalculateTimeoutTaskListenerDuedateCreationDateBased.bpmn20.xml")
public void testRecalculateTimeoutTaskListenerDuedateCurrentDateBased() {
  // given
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("process", Variables.putValue("duration", "PT1H"));

  JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId());
  List<Job> jobs = jobQuery.list();
  assertEquals(1, jobs.size());
  Job job = jobs.get(0);
  Date oldDate = job.getDuedate();
  ClockUtil.offset(2000L);

  // when
  managementService.recalculateJobDuedate(job.getId(), false);

  // then
  Job jobUpdated = jobQuery.singleResult();
  assertEquals(job.getId(), jobUpdated.getId());
  assertNotEquals(oldDate, jobUpdated.getDuedate());
  assertTrue(oldDate.before(jobUpdated.getDuedate()));
}
 
Example 9
Source File: HistoricIncidentTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml"})
public void testJobLogReferenceWithNewIncidentCreatedOnSetRetriesAfterFailure() {
  startProcessInstance(PROCESS_DEFINITION_KEY, false);
  ProcessInstance pi = runtimeService.createProcessInstanceQuery().singleResult();
  Job job = managementService.createJobQuery().singleResult();

  ClockUtil.offset(2000L);
  executeAvailableJobs(false);

  List<HistoricJobLog> logs = getHistoricJobLogOrdered(job.getId());
  assertEquals(2, logs.size());
  HistoricIncidentQuery query = historyService.createHistoricIncidentQuery().processInstanceId(pi.getId());
  assertEquals(0, query.count());

  // set retries to 0
  managementService.setJobRetries(job.getId(), 0);

  // an incident is created, it references the latest log entry
  assertEquals(1, query.count());
  HistoricIncident incident = query.singleResult();
  assertEquals(logs.get(0).getId(), incident.getHistoryConfiguration());
}
 
Example 10
Source File: SetBusinessKeyTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testNewKeyInTimeoutTaskListener() {
  // given
  String newBusinessKeyValue = "newBusinessKey";
  runtimeService.startProcessInstanceByKey(PROCESS_KEY, Variables.createVariables().putValue(BUSINESS_KEY_VARIABLE, newBusinessKeyValue));

  // when
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(70L));
  testRule.waitForJobExecutorToProcessAllJobs(5000L);

  // then
  checkBusinessKeyChanged(newBusinessKeyValue);
}
 
Example 11
Source File: UserTaskBpmnModelExecutionContextTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void shouldGetBpmnModelElementInstanceOnTimeout() {
  runtimeService.startProcessInstanceByKey(PROCESS_ID);

  assertNull(ModelExecutionContextTaskListener.modelInstance);
  assertNull(ModelExecutionContextTaskListener.userTask);

  ClockUtil.offset(TimeUnit.MINUTES.toMillis(70L));
  testRule.waitForJobExecutorToProcessAllJobs(5000L);

  assertModelInstance();
  assertUserTask(TaskListener.EVENTNAME_TIMEOUT);
}
 
Example 12
Source File: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testTimeoutTaskListenerDuration() {
  // given
  ProcessInstance instance = runtimeService.startProcessInstanceByKey("process");

  // when
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(70L));
  testRule.waitForJobExecutorToProcessAllJobs(5000L);

  // then
  assertThat(runtimeService.getVariable(instance.getId(), "timeout-status")).isEqualTo("fired");
}
 
Example 13
Source File: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testTimeoutTaskListenerCycle() {
  // given
  ProcessInstance instance = runtimeService.startProcessInstanceByKey("process");

  // when
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(70L));
  testRule.waitForJobExecutorToProcessAllJobs(5000L);
  ClockUtil.offset(TimeUnit.MINUTES.toMillis(130L));
  testRule.waitForJobExecutorToProcessAllJobs(5000L);

  // then
  assertThat(runtimeService.getVariable(instance.getId(), "timeout-status")).isEqualTo("fired2");
}
 
Example 14
Source File: BoundaryTimerEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/timer/BoundaryTimerEventTest.testRecalculateUnchangedExpressionOnTimerCurrentDateBased.bpmn20.xml")
public void testRecalculateChangedExpressionOnTimerCurrentDateBased(){
  // Set the clock fixed
  Date startTime = new Date();

  HashMap<String, Object> variables = new HashMap<String, Object>();
  variables.put("duedate", "PT1H");

  // After process start, there should be a timer created
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("testExpressionOnTimer", variables);

  JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId());
  List<Job> jobs = jobQuery.list();
  assertEquals(1, jobs.size());
  Job job = jobs.get(0);
  Date oldDate = job.getDuedate();
  ClockUtil.offset(2000L);

  // After recalculation of the timer, the job's duedate should be changed
  managementService.recalculateJobDuedate(job.getId(), false);
  Job jobUpdated = jobQuery.singleResult();
  assertEquals(job.getId(), jobUpdated.getId());
  assertNotEquals(oldDate, jobUpdated.getDuedate());
  assertTrue(oldDate.before(jobUpdated.getDuedate()));

  // After setting the clock to time '16 minutes', the timer should fire
  ClockUtil.setCurrentTime(new Date(startTime.getTime() + TimeUnit.HOURS.toMillis(2L)));
  waitForJobExecutorToProcessAllJobs(5000L);
  assertEquals(0L, jobQuery.count());

  // which means the process has ended
  assertProcessEnded(pi.getId());
}
 
Example 15
Source File: ProcessApplicationDeploymentTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldRegisterExistingDeploymentsOnLatestProcessDefinitionRemoval() {
  // given
  Date timeFreeze = new Date();
  ClockUtil.setCurrentTime(timeFreeze);
  BpmnModelInstance process1 = Bpmn.createExecutableProcess("process").done();
  BpmnModelInstance process2 = Bpmn.createExecutableProcess("process").startEvent().done();

  DeploymentWithDefinitions deployment1 = testRule.deploy(repositoryService
      .createDeployment(processApplication.getReference())
      .name("foo")
      .addModelInstance("process.bpmn", process1));

  // offset second deployment time to detect latest deployment with MySQL timestamps
  ClockUtil.offset(1000L);
  DeploymentWithDefinitions deployment2 = testRule.deploy(repositoryService
      .createDeployment(processApplication.getReference())
      .name("foo")
      .addModelInstance("process.bpmn", process2)
      .resumePreviousVersions()
      .enableDuplicateFiltering(true));

  ProcessDefinition latestProcessDefinition = deployment2.getDeployedProcessDefinitions().get(0);

  // assume
  assumeNotNull(managementService.getProcessApplicationForDeployment(deployment1.getId()));
  assumeNotNull(managementService.getProcessApplicationForDeployment(deployment2.getId()));

  // delete latest process definition
  repositoryService.deleteProcessDefinition(latestProcessDefinition.getId());

  // stop process engine by clearing the caches
  clearProcessApplicationDeployments();

  // when
  testRule.deploy(repositoryService
      .createDeployment(processApplication.getReference())
      .addModelInstance("process.bpmn", process2)
      .resumePreviousVersions()
      .enableDuplicateFiltering(true)
      .name("foo"));

  // then
  assertNotNull(managementService.getProcessApplicationForDeployment(deployment1.getId()));
  assertNotNull(managementService.getProcessApplicationForDeployment(deployment2.getId()));
}