Java Code Examples for org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl#initHistoryCleanup()

The following examples show how to use org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl#initHistoryCleanup() . 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: AbstractHistoryCleanupSchedulerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void initEngineConfiguration(ProcessEngineConfigurationImpl engineConfiguration) {
  engineConfiguration
    .setHistoryRemovalTimeStrategy(HISTORY_REMOVAL_TIME_STRATEGY_END)
    .setHistoryRemovalTimeProvider(new DefaultHistoryRemovalTimeProvider())
    .initHistoryRemovalTime();

  engineConfiguration.setHistoryCleanupStrategy(HISTORY_CLEANUP_STRATEGY_REMOVAL_TIME_BASED);

  engineConfiguration.setHistoryCleanupBatchSize(MAX_BATCH_SIZE);
  engineConfiguration.setHistoryCleanupBatchWindowStartTime("13:00");
  engineConfiguration.setHistoryCleanupDegreeOfParallelism(1);

  engineConfiguration.initHistoryCleanup();
}
 
Example 2
Source File: BatchSetRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSetRemovalTimeForBatch_BaseTimeStart() {
  // given
  String processInstanceId = testRule.process().serviceTask().deploy().start();
  Batch batch = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceId), "");

  HistoricBatch historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // assume
  assertThat(historicBatch.getRemovalTime()).isNull();

  ProcessEngineConfigurationImpl configuration = testRule.getProcessEngineConfiguration();
  configuration.setBatchOperationHistoryTimeToLive("P5D");
  configuration.initHistoryCleanup();

  HistoricBatchQuery query = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION);

  // when
  testRule.syncExec(
    historyService.setRemovalTimeToHistoricBatches()
      .calculatedRemovalTime()
      .byQuery(query)
      .executeAsync()
  );

  historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // then
  assertThat(historicBatch.getRemovalTime()).isEqualTo(addDays(CURRENT_DATE, 5));

  // clear database
  managementService.deleteBatch(batch.getId(), true);
}
 
Example 3
Source File: BatchSetRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldClearRemovalTimeForBatch_BaseTimeEnd() {
  // given
  ProcessEngineConfigurationImpl configuration = testRule.getProcessEngineConfiguration();
  configuration.setBatchOperationHistoryTimeToLive("P5D");
  configuration.initHistoryCleanup();

  String processInstanceId = testRule.process().serviceTask().deploy().start();
  Batch batch = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceId), "");

  HistoricBatch historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // assume
  assertThat(historicBatch.getRemovalTime()).isNotNull();

  configuration.setHistoryRemovalTimeStrategy(HISTORY_REMOVAL_TIME_STRATEGY_END);

  HistoricBatchQuery query = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION);

  // when
  testRule.syncExec(
    historyService.setRemovalTimeToHistoricBatches()
      .calculatedRemovalTime()
      .byQuery(query)
      .executeAsync()
  );

  historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // then
  assertThat(historicBatch.getRemovalTime()).isNull();

  // clear database
  managementService.deleteBatch(batch.getId(), true);
}
 
Example 4
Source File: BatchSetRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSetRemovalTimeForBatch_Null() {
  // given
  ProcessEngineConfigurationImpl configuration = testRule.getProcessEngineConfiguration();

  configuration.setBatchOperationHistoryTimeToLive("P5D");
  configuration.initHistoryCleanup();

  String processInstanceId = testRule.process().serviceTask().deploy().start();
  Batch batch = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceId), "");

  HistoricBatch historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // assume
  assertThat(historicBatch.getRemovalTime()).isNotNull();

  HistoricBatchQuery query = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION);

  // when
  testRule.syncExec(
    historyService.setRemovalTimeToHistoricBatches()
      .clearedRemovalTime()
      .byQuery(query)
      .executeAsync()
  );

  historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // then
  assertThat(historicBatch.getRemovalTime()).isNull();

  // clear database
  managementService.deleteBatch(batch.getId(), true);
}
 
Example 5
Source File: BatchSetRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSetRemovalTimeForBatch_ExistingAndNotExistingId() {
  // given
  String processInstanceId = testRule.process().serviceTask().deploy().start();
  Batch batchOne = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceId), "");

  HistoricBatch historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // assume
  assertThat(historicBatch.getRemovalTime()).isNull();

  ProcessEngineConfigurationImpl configuration = testRule.getProcessEngineConfiguration();
  configuration.setBatchOperationHistoryTimeToLive("P5D");
  configuration.initHistoryCleanup();

  // when
  testRule.syncExec(
    historyService.setRemovalTimeToHistoricBatches()
      .calculatedRemovalTime()
      .byIds("notExistingId", batchOne.getId())
      .executeAsync()
  );

  historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // then
  assertThat(historicBatch.getRemovalTime()).isEqualTo(addDays(CURRENT_DATE, 5));

  // clear database
  managementService.deleteBatch(batchOne.getId(), true);
}
 
Example 6
Source File: BatchSetRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldNotSetRemovalTimeForBatch_BaseTimeNone() {
  // given
  ProcessEngineConfigurationImpl configuration = testRule.getProcessEngineConfiguration();
  configuration.setHistoryCleanupStrategy("endTimeBased");
  configuration.setHistoryRemovalTimeStrategy(HISTORY_REMOVAL_TIME_STRATEGY_NONE);

  configuration.setBatchOperationHistoryTimeToLive("P5D");
  configuration.initHistoryCleanup();

  String processInstanceIdOne = testRule.process().serviceTask().deploy().start();
  Batch batchOne = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceIdOne), "");
  testRule.syncExec(batchOne);

  String processInstanceIdTwo = testRule.process().serviceTask().deploy().start();
  Batch batchTwo = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceIdTwo), "");
  testRule.syncExec(batchTwo);

  List<HistoricBatch> historicBatches = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .list();

  // assume
  assertThat(historicBatches.get(0).getRemovalTime()).isNull();
  assertThat(historicBatches.get(1).getRemovalTime()).isNull();

  HistoricBatchQuery query = historyService.createHistoricBatchQuery();

  // when
  testRule.syncExec(
    historyService.setRemovalTimeToHistoricBatches()
      .calculatedRemovalTime()
      .byQuery(query)
      .executeAsync()
  );

  historicBatches = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .list();

  // then
  assertThat(historicBatches.get(0).getRemovalTime()).isNull();
  assertThat(historicBatches.get(1).getRemovalTime()).isNull();
}
 
Example 7
Source File: BatchSetRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldClearRemovalTimeForBatch_BaseTimeNone() {
  // given
  ProcessEngineConfigurationImpl configuration = testRule.getProcessEngineConfiguration();

  configuration.setBatchOperationHistoryTimeToLive("P5D");
  configuration.initHistoryCleanup();

  String processInstanceIdOne = testRule.process().serviceTask().deploy().start();
  Batch batchOne = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceIdOne), "");
  testRule.syncExec(batchOne);

  String processInstanceIdTwo = testRule.process().serviceTask().deploy().start();
  Batch batchTwo = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceIdTwo), "");
  testRule.syncExec(batchTwo);

  List<HistoricBatch> historicBatches = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .list();

  // assume
  assertThat(historicBatches.get(0).getRemovalTime()).isNotNull();
  assertThat(historicBatches.get(1).getRemovalTime()).isNotNull();

  configuration.setHistoryRemovalTimeStrategy(HISTORY_REMOVAL_TIME_STRATEGY_NONE);

  HistoricBatchQuery query = historyService.createHistoricBatchQuery();

  // when
  testRule.syncExec(
    historyService.setRemovalTimeToHistoricBatches()
      .calculatedRemovalTime()
      .byQuery(query)
      .executeAsync()
  );

  historicBatches = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .list();

  // then
  assertThat(historicBatches.get(0).getRemovalTime()).isNull();
  assertThat(historicBatches.get(1).getRemovalTime()).isNull();
}
 
Example 8
Source File: BatchSetRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldNotSetRemovalTimeForBatch_BaseTimeEnd() {
  // given
  ProcessEngineConfigurationImpl configuration = testRule.getProcessEngineConfiguration();

  configuration
    .setHistoryRemovalTimeStrategy(HISTORY_REMOVAL_TIME_STRATEGY_END);

  String processInstanceId = testRule.process().serviceTask().deploy().start();
  Batch batch = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceId), "");

  HistoricBatch historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // assume
  assertThat(historicBatch.getRemovalTime()).isNull();

  configuration.setBatchOperationHistoryTimeToLive("P5D");
  configuration.initHistoryCleanup();

  HistoricBatchQuery query = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION);

  // when
  testRule.syncExec(
    historyService.setRemovalTimeToHistoricBatches()
      .calculatedRemovalTime()
      .byQuery(query)
      .executeAsync()
  );

  historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // then
  assertThat(historicBatch.getRemovalTime()).isNull();

  // clear database
  managementService.deleteBatch(batch.getId(), true);
}
 
Example 9
Source File: BatchSetRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldSetRemovalTimeForBatch_BaseTimeEnd() {
  // given
  ProcessEngineConfigurationImpl configuration = testRule.getProcessEngineConfiguration();

  configuration
    .setHistoryRemovalTimeStrategy(HISTORY_REMOVAL_TIME_STRATEGY_END);

  String processInstanceId = testRule.process().serviceTask().deploy().start();
  Batch batch = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceId), "");

  ClockUtil.setCurrentTime(addDays(CURRENT_DATE, 1));

  testRule.syncExec(batch);

  HistoricBatch historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // assume
  assertThat(historicBatch.getRemovalTime()).isNull();

  configuration.setBatchOperationHistoryTimeToLive("P5D");
  configuration.initHistoryCleanup();

  HistoricBatchQuery query = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION);

  // when
  testRule.syncExec(
    historyService.setRemovalTimeToHistoricBatches()
      .calculatedRemovalTime()
      .byQuery(query)
      .executeAsync()
  );

  historicBatch = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .singleResult();

  // then
  assertThat(historicBatch.getRemovalTime()).isEqualTo(addDays(CURRENT_DATE, 5+1));
}
 
Example 10
Source File: BatchSetRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldSetRemovalTimeForBatch_BothQueryAndIdsDefined() {
  // given
  String processInstanceId = testRule.process().serviceTask().deploy().start();
  Batch batchOne = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceId), "");
  Batch batchTwo = historyService.deleteHistoricProcessInstancesAsync(Collections.singletonList(processInstanceId), "");

  List<HistoricBatch> historicBatches = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .list();

  // assume
  assertThat(historicBatches.get(0).getRemovalTime()).isNull();
  assertThat(historicBatches.get(1).getRemovalTime()).isNull();

  ProcessEngineConfigurationImpl configuration = testRule.getProcessEngineConfiguration();
  configuration.setBatchOperationHistoryTimeToLive("P5D");
  configuration.initHistoryCleanup();

  HistoricBatchQuery query = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .batchId(batchOne.getId());

  // when
  testRule.syncExec(
    historyService.setRemovalTimeToHistoricBatches()
      .calculatedRemovalTime()
      .byQuery(query)
      .byIds(batchTwo.getId())
      .executeAsync()
  );

  historicBatches = historyService.createHistoricBatchQuery()
    .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION)
    .list();

  // then
  assertThat(historicBatches.get(0).getRemovalTime()).isEqualTo(addDays(CURRENT_DATE, 5));
  assertThat(historicBatches.get(1).getRemovalTime()).isEqualTo(addDays(CURRENT_DATE, 5));

  // clear database
  managementService.deleteBatch(batchOne.getId(), true);
  managementService.deleteBatch(batchTwo.getId(), true);
}
 
Example 11
Source File: HistoryCleanupTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
@ScenarioUnderTest("initHistoryCleanup.1")
public void testHistoryCleanup() {

  if (RollingUpdateConstants.OLD_ENGINE_TAG.equals(rule.getTag())) { // test cleanup with old engine

    Date currentDate = addDays(FIXED_DATE, 1);
    ClockUtil.setCurrentTime(currentDate);

    ProcessEngineConfigurationImpl configuration =
      rule.getProcessEngineConfiguration();

    configuration.setHistoryCleanupBatchWindowStartTime("13:00");
    configuration.setHistoryCleanupBatchWindowEndTime("15:00");
    configuration.setHistoryCleanupDegreeOfParallelism(3);
    configuration.initHistoryCleanup();

    List<Job> jobs = rule.getHistoryService().findHistoryCleanupJobs();

    Job jobOne = jobs.get(0);
    rule.getManagementService().executeJob(jobOne.getId());

    Job jobTwo = jobs.get(1);
    rule.getManagementService().executeJob(jobTwo.getId());

    Job jobThree = jobs.get(2);
    rule.getManagementService().executeJob(jobThree.getId());

    jobs = rule.getHistoryService().findHistoryCleanupJobs();

    // assume
    for (Job job : jobs) {
      assertThat(job.getDuedate(), is(addSeconds(currentDate, (int)(Math.pow(2., (double)4) * 10))));
    }

    List<HistoricProcessInstance> processInstances = rule.getHistoryService()
      .createHistoricProcessInstanceQuery()
      .processInstanceBusinessKey("HistoryCleanupScenario")
      .list();

    // assume
    assertThat(jobs.size(), is(3));
    assertThat(processInstances.size(), is(15));

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

    // when
    rule.getManagementService().executeJob(jobOne.getId());

    processInstances = rule.getHistoryService()
      .createHistoricProcessInstanceQuery()
      .processInstanceBusinessKey("HistoryCleanupScenario")
      .list();

    // then
    assertThat(processInstances.size(), is(10));

    // when
    rule.getManagementService().executeJob(jobTwo.getId());

    processInstances = rule.getHistoryService()
      .createHistoricProcessInstanceQuery()
      .processInstanceBusinessKey("HistoryCleanupScenario")
      .list();

    // then
    assertThat(processInstances.size(), is(5));

    // when
    rule.getManagementService().executeJob(jobThree.getId());

    processInstances = rule.getHistoryService()
      .createHistoricProcessInstanceQuery()
      .processInstanceBusinessKey("HistoryCleanupScenario")
      .list();

    // then
    assertThat(processInstances.size(), is(0));
  }
}
 
Example 12
Source File: HistoryCleanupScenario.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@DescribesScenario("initHistoryCleanup")
@Times(1)
public static ScenarioSetup initHistoryCleanup() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {

      for (int i = 0; i < 60; i++) {
        if (i % 4 == 0) {
          ClockUtil.setCurrentTime(FIXED_DATE);

          engine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess_710", "HistoryCleanupScenario");

          String taskId = engine.getTaskService().createTaskQuery()
            .processInstanceBusinessKey("HistoryCleanupScenario")
            .singleResult()
            .getId();


          ClockUtil.setCurrentTime(addMinutes(FIXED_DATE, i));

          engine.getTaskService().complete(taskId);
        }
      }

      ProcessEngineConfigurationImpl configuration =
        ((ProcessEngineConfigurationImpl) engine.getProcessEngineConfiguration());

      configuration.setHistoryCleanupBatchWindowStartTime("13:00");
      configuration.setHistoryCleanupBatchWindowEndTime("14:00");
      configuration.setHistoryCleanupDegreeOfParallelism(3);
      configuration.initHistoryCleanup();

      engine.getHistoryService().cleanUpHistoryAsync();

      List<Job> jobs = engine.getHistoryService().findHistoryCleanupJobs();

      for (int i = 0; i < 4; i++) {
        Job jobOne = jobs.get(0);
        engine.getManagementService().executeJob(jobOne.getId());

        Job jobTwo = jobs.get(1);
        engine.getManagementService().executeJob(jobTwo.getId());

        Job jobThree = jobs.get(2);
        engine.getManagementService().executeJob(jobThree.getId());
      }

      ClockUtil.reset();
    }
  };
}