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

The following examples show how to use org.camunda.bpm.engine.impl.util.ClockUtil#setCurrentTime() . 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: ProcessInstanceSuspensionTest.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/ProcessInstanceSuspensionTest.testJobNotExecutedAfterProcessInstanceSuspend.bpmn20.xml"})
public void testJobNotExecutedAfterProcessInstanceSuspendByProcessDefinitionId() {

  Date now = new Date();
  ClockUtil.setCurrentTime(now);

  // Suspending the process instance should also stop the execution of jobs for that process instance
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  runtimeService.startProcessInstanceById(processDefinition.getId());
  assertEquals(1, managementService.createJobQuery().count());
  runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinition.getId());
  assertEquals(1, managementService.createJobQuery().count());

  // The jobs should not be executed now
  ClockUtil.setCurrentTime(new Date(now.getTime() + (60 * 60 * 1000))); // Timer is set to fire on 5 minutes
  assertEquals(0, managementService.createJobQuery().executable().count());

  // Activation of the process instance should now allow for job execution
  runtimeService.activateProcessInstanceByProcessDefinitionId(processDefinition.getId());
  assertEquals(1, managementService.createJobQuery().executable().count());
  managementService.executeJob(managementService.createJobQuery().singleResult().getId());
  assertEquals(0, managementService.createJobQuery().count());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
 
Example 2
Source File: LoginAttemptsTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testUsuccessfulAttemptsResultInLockedUser() throws ParseException {
  // given
  User user = identityService.newUser("johndoe");
  user.setPassword("xxx");
  identityService.saveUser(user);

  Date now = sdf.parse("2000-01-24T13:00:00");
  ClockUtil.setCurrentTime(now);
  // when
  for (int i = 0; i <= 6; i++) {
    assertThat(identityService.checkPassword("johndoe", "invalid pwd")).isFalse();
    now = DateUtils.addSeconds(now, 5);
    ClockUtil.setCurrentTime(now);
  }

  // then
  assertThat(loggingRule.getFilteredLog(INDENTITY_LOGGER, "The user with id 'johndoe' is permanently locked.").size()).isEqualTo(1);
}
 
Example 3
Source File: GetHistoricOperationLogsForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void occurredAfterAndOccurredAtParameterWorks() {
  // given
  Date now = new Date();
  ClockUtil.setCurrentTime(now);
  final ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("process");
  runtimeService.suspendProcessInstanceById(processInstance.getProcessInstanceId());

  Date nowPlus2Seconds = new Date(now.getTime() + 2000L);
  ClockUtil.setCurrentTime(nowPlus2Seconds);
  runtimeService.activateProcessInstanceById(processInstance.getProcessInstanceId());

  // when
  List<UserOperationLogEntry> userOperationsLog =
    optimizeService.getHistoricUserOperationLogs(now, now, 10);

  // then
  assertThat(userOperationsLog.size(), is(0));
}
 
Example 4
Source File: VariableSetter.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void execute(DelegateExecution execution) throws Exception {
  
  SimpleDateFormat sdf =  new SimpleDateFormat("dd/MM/yyyy hh:mm:ss SSS");
  // We set the time to check of the updated time is picked up in the history
  Date updatedDate = sdf.parse("01/01/2001 01:23:46 000");
  ClockUtil.setCurrentTime(updatedDate);
  
  
  execution.setVariable("aVariable", "updated value");
  execution.setVariable("bVariable", 123);
  execution.setVariable("cVariable", 12345L);
  execution.setVariable("dVariable", 1234.567);
  execution.setVariable("eVariable", (short)12);
  
  Date theDate =sdf.parse("01/01/2001 01:23:45 678");
  execution.setVariable("fVariable", theDate);
  
  execution.setVariable("gVariable", new SerializableVariable("hello hello"));
  execution.setVariable("hVariable", ";-)".getBytes());
}
 
Example 5
Source File: GetRunningHistoricProcessInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void startedAfterParameterWorks() {
   // given
  BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process")
    .startEvent()
    .userTask()
    .endEvent()
    .done();
  testHelper.deploy(simpleDefinition);
  Date now = new Date();
  ClockUtil.setCurrentTime(now);
  engineRule.getRuntimeService().startProcessInstanceByKey("process");
  Date nowPlus2Seconds = new Date(now.getTime() + 2000L);
  ClockUtil.setCurrentTime(nowPlus2Seconds);
  runtimeService.startProcessInstanceByKey("process");

  // when
  List<HistoricProcessInstance> runningHistoricProcessInstances =
    optimizeService.getRunningHistoricProcessInstances(now, null, 10);

  // then
  assertThat(runningHistoricProcessInstances.size(), is(1));
}
 
Example 6
Source File: GetRunningHistoricProcessInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void startedAtParameterWorks() {
   // given
  BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process")
    .startEvent()
    .userTask()
    .endEvent()
    .done();
  testHelper.deploy(simpleDefinition);
  Date now = new Date();
  ClockUtil.setCurrentTime(now);
  ProcessInstance processInstance =
    runtimeService.startProcessInstanceByKey("process");
  Date nowPlus2Seconds = new Date(now.getTime() + 2000L);
  ClockUtil.setCurrentTime(nowPlus2Seconds);
  runtimeService.startProcessInstanceByKey("process");

  // when
  List<HistoricProcessInstance> runningHistoricProcessInstances =
    optimizeService.getRunningHistoricProcessInstances(null, now, 10);

  // then
  assertThat(runningHistoricProcessInstances.size(), is(1));
  assertThat(runningHistoricProcessInstances.get(0).getId(), is(processInstance.getId()));
}
 
Example 7
Source File: HistoryCleanupSchedulerCommentsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldScheduleToNow() {
  // given
  testRule.deploy(PROCESS);

  runtimeService.startProcessInstanceByKey(PROCESS_KEY);

  String processInstanceId = runtimeService.createProcessInstanceQuery()
    .activityIdIn("userTask")
    .singleResult()
    .getId();

  ClockUtil.setCurrentTime(END_DATE);

  for (int i = 0; i < 5; i++) {
    taskService.createComment(null, processInstanceId, "aMessage");
  }

  String taskId = taskService.createTaskQuery().singleResult().getId();
  taskService.complete(taskId);

  engineConfiguration.setHistoryCleanupBatchSize(5);
  engineConfiguration.initHistoryCleanup();

  Date removalTime = addDays(END_DATE, 5);
  ClockUtil.setCurrentTime(addDays(END_DATE, 5));

  // when
  runHistoryCleanup();

  Job job = historyService.findHistoryCleanupJobs().get(0);

  // then
  assertThat(job.getDuedate(), is(removalTime));
}
 
Example 8
Source File: ExternalTaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testCompleteReclaimedLockExpiredTask() {
  // given
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");

  // when
  List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID)
    .topic(TOPIC_NAME, LOCK_TIME)
    .execute();

  // and the lock expires
  ClockUtil.setCurrentTime(new DateTime(ClockUtil.getCurrentTime()).plus(LOCK_TIME * 2).toDate());

  // and it is reclaimed by another worker
  List<LockedExternalTask> reclaimedTasks = externalTaskService.fetchAndLock(1, "anotherWorkerId")
    .topic(TOPIC_NAME, LOCK_TIME)
    .execute();

  // then the first worker cannot complete the task
  try {
    externalTaskService.complete(externalTasks.get(0).getId(), WORKER_ID);
    fail("exception expected");
  } catch (ProcessEngineException e) {
    assertTextPresent("cannot be completed by worker '" + WORKER_ID + "'. It is locked by worker 'anotherWorkerId'.", e.getMessage());
  }

  // and the second worker can
  externalTaskService.complete(reclaimedTasks.get(0).getId(), "anotherWorkerId");

  externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID)
    .topic(TOPIC_NAME, LOCK_TIME)
    .execute();
  assertEquals(0, externalTasks.size());
  assertProcessEnded(processInstance.getId());
}
 
Example 9
Source File: HistoryCleanupRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {
  "org/camunda/bpm/engine/test/dmn/deployment/drdDish.dmn11.xml"
})
public void shouldNotSeeCleanableDecisionInstancesInReport() {
  // given
  engineConfiguration
    .setHistoryRemovalTimeStrategy(HISTORY_REMOVAL_TIME_STRATEGY_END)
    .initHistoryRemovalTime();

  testRule.deploy(CALLING_PROCESS_CALLS_DMN);

  ClockUtil.setCurrentTime(END_DATE);

  for (int i = 0; i < 5; i++) {
    runtimeService.startProcessInstanceByKey(CALLING_PROCESS_CALLS_DMN_KEY,
      Variables.createVariables()
        .putValue("temperature", 32)
        .putValue("dayType", "Weekend"));
  }

  ClockUtil.setCurrentTime(addDays(END_DATE, 5));

  // when
  CleanableHistoricDecisionInstanceReportResult report = historyService.createCleanableHistoricDecisionInstanceReport()
    .decisionDefinitionKeyIn("dish-decision")
    .compact()
    .singleResult();

  // then
  assertThat(report.getCleanableDecisionInstanceCount(), is(0L));
  assertThat(report.getFinishedDecisionInstanceCount(), is(5L));
}
 
Example 10
Source File: RemovalTimeStrategyStartTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldResolveByteArray_ExternalTaskLog() {
  // given
  ClockUtil.setCurrentTime(START_DATE);

  testRule.deploy(Bpmn.createExecutableProcess("calledProcess")
    .startEvent()
      .serviceTask().camundaExternalTask("aTopicName")
    .endEvent().done());

  testRule.deploy(Bpmn.createExecutableProcess("callingProcess")
    .camundaHistoryTimeToLive(5)
    .startEvent()
      .callActivity()
        .calledElement("calledProcess")
    .endEvent().done());

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callingProcess");

  List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, "aWorkerId")
    .topic("aTopicName", Integer.MAX_VALUE)
    .execute();

  // when
  externalTaskService.handleFailure(tasks.get(0).getId(), "aWorkerId", null, "errorDetails", 5, 3000L);

  HistoricExternalTaskLogEntity externalTaskLog = (HistoricExternalTaskLogEntity) historyService.createHistoricExternalTaskLogQuery()
    .failureLog()
    .singleResult();

  // assume
  assertThat(externalTaskLog, notNullValue());

  ByteArrayEntity byteArrayEntity = findByteArrayById(externalTaskLog.getErrorDetailsByteArrayId());

  Date removalTime = addDays(START_DATE, 5);

  // then
  assertThat(byteArrayEntity.getRemovalTime(), is(removalTime));
}
 
Example 11
Source File: FoxJobRetryCmdTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testEventBasedGateway() throws Exception {
  BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("process")
      .startEvent()
      .eventBasedGateway()
        .camundaAsyncBefore()
        .camundaFailedJobRetryTimeCycle("R5/PT5M")
        .camundaExecutionListenerClass("start", "foo")
      .intermediateCatchEvent()
        .condition("${true}")
      .endEvent()
      .done();

  deployment(bpmnModelInstance);

  Date startDate = simpleDateFormat.parse("2018-01-01T10:00:00");
  ClockUtil.setCurrentTime(startDate);

  runtimeService.startProcessInstanceByKey("process");
  Job job = managementService.createJobQuery().singleResult();

  // assume
  Assert.assertEquals(3, job.getRetries());

  // when job fails
  try {
    managementService.executeJob(job.getId());
  } catch (Exception e) {
    // ignore
  }

  // then
  job = managementService.createJobQuery().singleResult();
  Assert.assertEquals(4, job.getRetries());

  Date expectedDate = simpleDateFormat.parse("2018-01-01T10:05:00");
  assertEquals(expectedDate, job.getDuedate());
}
 
Example 12
Source File: RemovalTimeStrategyStartTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldResolveIncident() {
  // given
  ClockUtil.setCurrentTime(START_DATE);

  testRule.deploy(CALLING_PROCESS);

  testRule.deploy(CALLED_PROCESS);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY);
  taskService.complete(taskService.createTaskQuery().singleResult().getId());

  String jobId = managementService.createJobQuery()
    .singleResult()
    .getId();

  managementService.setJobRetries(jobId, 0);

  try {
    // when
    managementService.executeJob(jobId);
  } catch (Exception ignored) { }

  List<HistoricIncident> historicIncidents = historyService.createHistoricIncidentQuery().list();

  // assume
  assertThat(historicIncidents.size(), is(2));

  Date removalTime = addDays(START_DATE, 5);

  // then
  assertThat(historicIncidents.get(0).getRemovalTime(), is(removalTime));
  assertThat(historicIncidents.get(1).getRemovalTime(), is(removalTime));
}
 
Example 13
Source File: SignalEventTest.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/signal/SignalEventTests.catchAlertSignal.bpmn20.xml",
    "org/camunda/bpm/engine/test/bpmn/event/signal/SignalEventTests.throwAlertSignalAsynch.bpmn20.xml"})
@Test
public void testSignalCatchIntermediateAsynch() {

  runtimeService.startProcessInstanceByKey("catchSignal");

  assertEquals(1, createEventSubscriptionQuery().count());
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());

  runtimeService.startProcessInstanceByKey("throwSignal");

  assertEquals(1, createEventSubscriptionQuery().count());
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());

  // there is a job:
  assertEquals(1, managementService.createJobQuery().count());

  try {
    ClockUtil.setCurrentTime(new Date(System.currentTimeMillis() + 1000));
    testRule.waitForJobExecutorToProcessAllJobs(10000);

    assertEquals(0, createEventSubscriptionQuery().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    assertEquals(0, managementService.createJobQuery().count());
  } finally {
    ClockUtil.setCurrentTime(new Date());
  }

}
 
Example 14
Source File: StartTimerEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testExpressionStartTimerEvent() throws Exception {
  // ACT-1415: fixed start-date is an expression
  JobQuery jobQuery = managementService.createJobQuery();
  assertEquals(1, jobQuery.count());

  ClockUtil.setCurrentTime(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("15/11/2036 11:12:30"));
  executeAllJobs();

  List<ProcessInstance> pi = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample").list();
  assertEquals(1, pi.size());

  assertEquals(0, jobQuery.count());
}
 
Example 15
Source File: HistoricIdentityLinkLogQueryTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Should add 3 history records of identity link addition at 01-01-2016
 * 00:00.00 Should add 3 history records of identity link deletion at
 * 01-01-2016 12:00.00
 *
 * Should add 3 history records of identity link addition at 01-01-2016
 * 12:30.00 Should add 3 history records of identity link deletion at
 * 01-01-2016 21:00.00
 *
 * Test case: Query the number of added records at different time interval.
 */
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testShouldAddTaskOwnerForAddandDeleteIdentityLinkByTimeStamp() {

  List<HistoricIdentityLinkLog> historicIdentityLinks = historyService.createHistoricIdentityLinkLogQuery().list();
  assertEquals(historicIdentityLinks.size(), 0);

  // given
  startProcessInstance(PROCESS_DEFINITION_KEY);
  String taskId = taskService.createTaskQuery().singleResult().getId();

  // if
  ClockUtil.setCurrentTime(newYearMorning(0));
  identityService.setAuthenticatedUserId(A_ASSIGNER_ID);
  // Adds aUserId1, deletes aUserID1, adds aUserId2, deletes aUserId2, Adds aUserId3 - 5
  addUserIdentityLinks(taskId);

  ClockUtil.setCurrentTime(newYearNoon(0));
  //Deletes aUserId3
  deleteUserIdentityLinks(taskId);

  ClockUtil.setCurrentTime(newYearNoon(30));
  addUserIdentityLinks(taskId);

  ClockUtil.setCurrentTime(newYearEvening());
  deleteUserIdentityLinks(taskId);

  // Query records with time before 12:20
  HistoricIdentityLinkLogQuery query = historyService.createHistoricIdentityLinkLogQuery();
  assertEquals(query.dateBefore(newYearNoon(20)).count(), 6);
  assertEquals(query.operationType(IDENTITY_LINK_ADD).count(), 3);
  assertEquals(query.operationType(IDENTITY_LINK_DELETE).count(), 3);

  // Query records with time between 00:01 and 12:00
  query = historyService.createHistoricIdentityLinkLogQuery();
  assertEquals(query.dateBefore(newYearNoon(0)).count(), 6);
  assertEquals(query.dateAfter(newYearMorning(1)).count(), 1);
  assertEquals(query.operationType(IDENTITY_LINK_ADD).count(), 0);
  assertEquals(query.operationType(IDENTITY_LINK_DELETE).count(), 1);

  // Query records with time after 12:45
  query = historyService.createHistoricIdentityLinkLogQuery();
  assertEquals(query.dateAfter(newYearNoon(45)).count(), 1);
  assertEquals(query.operationType(IDENTITY_LINK_ADD).count(), 0);
  assertEquals(query.operationType(IDENTITY_LINK_DELETE).count(), 1);

  ClockUtil.setCurrentTime(new Date());
}
 
Example 16
Source File: ExternalTaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void testHandleBpmnErrorPassVariablesEventSubProcess() {
  // when
  BpmnModelInstance process =
      Bpmn.createExecutableProcess("process")
      .startEvent("startEvent")
      .serviceTask("externalTask")
        .camundaType("external")
        .camundaTopic(TOPIC_NAME)
      .endEvent("endEvent")
      .done();

  BpmnModelInstance subProcess = modify(process)
      .addSubProcessTo("process")
        .id("eventSubProcess")
        .triggerByEvent()
        .embeddedSubProcess()
          .startEvent("eventSubProcessStart")
              .error("ERROR-SPEC-10")
          .userTask("afterBpmnError")
          .endEvent()
        .subProcessDone()
        .done();

  BpmnModelInstance targetProcess = modify(subProcess);

  deploymentId = deployment(targetProcess);

  ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");

  List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID)
    .topic(TOPIC_NAME, LOCK_TIME)
    .execute();

  // and the lock expires without the task being reclaimed
  ClockUtil.setCurrentTime(new DateTime(ClockUtil.getCurrentTime()).plus(LOCK_TIME * 2).toDate());

  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("foo", "bar");
  variables.put("transientVar", Variables.integerValue(1, true));

  // when
  externalTaskService.handleBpmnError(externalTasks.get(0).getId(), WORKER_ID, "ERROR-SPEC-10", null, variables);

  externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID)
    .topic(TOPIC_NAME, LOCK_TIME)
    .execute();

  // then
  assertEquals(0, externalTasks.size());
  assertEquals(0, externalTaskService.createExternalTaskQuery().count());
  Task afterBpmnError = taskService.createTaskQuery().singleResult();
  assertNotNull(afterBpmnError);
  assertEquals(afterBpmnError.getTaskDefinitionKey(), "afterBpmnError");
  List<VariableInstance> list = runtimeService.createVariableInstanceQuery().processInstanceIdIn(pi.getId()).list();
  assertEquals(1, list.size());
  assertEquals("foo", list.get(0).getName());
}
 
Example 17
Source File: ProcessDefinitionSuspensionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void testDelayedMultipleSuspendByKeyAndIncludeInstances_shouldSuspendJobDefinitionAndRetainJob() {
  Date startTime = new Date();
  ClockUtil.setCurrentTime(startTime);
  final long hourInMs = 60 * 60 * 1000;

  String key = "oneFailingServiceTaskProcess";

  // Deploy five versions of the same process, so that there exists
  // five job definitions
  int nrOfProcessDefinitions = 5;
  for (int i=0; i<nrOfProcessDefinitions; i++) {
    repositoryService.createDeployment()
      .addClasspathResource("org/camunda/bpm/engine/test/api/repository/ProcessDefinitionSuspensionTest.testWithOneAsyncServiceTask.bpmn").deploy();

    // a running process instance with a failed service task
    Map<String, Object> params = new HashMap<>();
    params.put("fail", Boolean.TRUE);
    runtimeService.startProcessInstanceByKey(key, params);
  }

  // when
  // the process definition will be suspended
  repositoryService.suspendProcessDefinitionByKey(key, false, new Date(startTime.getTime() + (2 * hourInMs)));

  // then
  // there exists a timer job to suspend the process definition delayed
  Job timerToSuspendProcessDefinition = managementService.createJobQuery().timers().singleResult();
  assertNotNull(timerToSuspendProcessDefinition);

  // the job definitions should be still active
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery();

  assertEquals(0, jobDefinitionQuery.suspended().count());
  assertEquals(5, jobDefinitionQuery.active().count());

  // ...and the corresponding jobs should be still active
  JobQuery jobQuery = managementService.createJobQuery();

  assertEquals(0, jobQuery.suspended().count());
  assertEquals(6, jobQuery.active().count());

  // when
  // execute job
  managementService.executeJob(timerToSuspendProcessDefinition.getId());

  // then
  // the job definitions should be suspended...
  assertEquals(0, jobDefinitionQuery.active().count());
  assertEquals(5, jobDefinitionQuery.suspended().count());

  // ...and the corresponding jobs should be still active
  assertEquals(0, jobQuery.suspended().count());
  assertEquals(5, jobQuery.active().count());

  // Clean DB
  for (org.camunda.bpm.engine.repository.Deployment deployment : repositoryService.createDeploymentQuery().list()) {
    repositoryService.deleteDeployment(deployment.getId(), true);
  }
}
 
Example 18
Source File: ExternalTaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testSetRetriesToZeroAfterFailureWithRetriesLeft() {
  // given
  runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");

  List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, WORKER_ID)
    .topic(TOPIC_NAME, LOCK_TIME)
    .execute();
  LockedExternalTask task = tasks.get(0);
  String errorMessage = "errorMessage";
  externalTaskService.handleFailure(task.getId(), WORKER_ID, errorMessage, 2, 3000L);
  ClockUtil.setCurrentTime(nowPlus(3000L));
  tasks = externalTaskService.fetchAndLock(5, WORKER_ID)
      .topic(TOPIC_NAME, LOCK_TIME)
      .execute();
  ClockUtil.setCurrentTime(nowPlus(5000L));
  externalTaskService.handleFailure(task.getId(), WORKER_ID, errorMessage, 1, 3000L);
  tasks = externalTaskService.fetchAndLock(5, WORKER_ID)
      .topic(TOPIC_NAME, LOCK_TIME)
      .execute();


  // when setting retries to 0
  ClockUtil.setCurrentTime(nowPlus(7000L));
  externalTaskService.setRetries(task.getId(), 0);

  // an incident has been created
  Incident incident = runtimeService.createIncidentQuery().singleResult();
  assertNotNull(incident);
  assertNotNull(incident.getId());

  if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_FULL.getId()) {
    // there are one incident in the history
    HistoricIncident historicIncident = historyService.createHistoricIncidentQuery().configuration(task.getId()).singleResult();
    assertNotNull(historicIncident);
    // there are two failure logs for external tasks
    List<HistoricExternalTaskLog> logs = getHistoricTaskLogOrdered(task.getId());
    assertEquals(2, logs.size());
    HistoricExternalTaskLog log = logs.get(0);
    // the incident is open and correlates to the oldest external task log entry
    assertTrue(historicIncident.isOpen());
    assertEquals(log.getId(), historicIncident.getHistoryConfiguration());
  }
}
 
Example 19
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected Date oneWeekLater() {
  Date startTime = new Date();
  ClockUtil.setCurrentTime(startTime);
  long oneWeekFromStartTime = startTime.getTime() + (7 * 24 * 60 * 60 * 1000);
  return new Date(oneWeekFromStartTime);
}
 
Example 20
Source File: HistoricTaskDurationReportTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void addToCalendar(int field, int month) {
  Calendar calendar = Calendar.getInstance();
  calendar.setTime(ClockUtil.getCurrentTime());
  calendar.add(field, month);
  ClockUtil.setCurrentTime(calendar.getTime());
}