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

The following examples show how to use org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl#setHistoryCleanupBatchWindowStartTime() . 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: CompetingHistoryCleanupAcquisitionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void initializeProcessEngine() {
  processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
    .createProcessEngineConfigurationFromResource("camunda.cfg.xml");

  jobExecutor.setMaxJobsPerAcquisition(1);
  processEngineConfiguration.setJobExecutor(jobExecutor);
  processEngineConfiguration.setHistoryCleanupBatchWindowStartTime("12:00");

  processEngineConfiguration.setCustomPostCommandInterceptorsTxRequiresNew(Collections.<CommandInterceptor>singletonList(new CommandInterceptor() {
    @Override
    public <T> T execute(Command<T> command) {

      T executed = next.execute(command);
      if(syncBeforeFlush.get() != null && syncBeforeFlush.get()) {
        cleanupThread.sync();
      }

      return executed;
    }
  }));

  processEngine = processEngineConfiguration.buildProcessEngine();
}
 
Example 2
Source File: HistoryCleanupOnEngineBootstrapTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testHistoryCleanupJobScheduled() throws ParseException {

  final ProcessEngineConfigurationImpl standaloneInMemProcessEngineConfiguration = (ProcessEngineConfigurationImpl)ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
  standaloneInMemProcessEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00");
  standaloneInMemProcessEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00");
  standaloneInMemProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:camunda" + getClass().getSimpleName() + "testHistoryCleanupJobScheduled");

  ProcessEngine engine = standaloneInMemProcessEngineConfiguration
    .buildProcessEngine();

  try {
    final List<Job> historyCleanupJobs = engine.getHistoryService().findHistoryCleanupJobs();
    assertFalse(historyCleanupJobs.isEmpty());
    final ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) engine.getProcessEngineConfiguration();
    for (Job historyCleanupJob : historyCleanupJobs) {
      assertEquals(processEngineConfiguration.getBatchWindowManager().getCurrentOrNextBatchWindow(ClockUtil.getCurrentTime(), processEngineConfiguration).getStart(), historyCleanupJob.getDuedate());
    }
  } finally {
    closeProcessEngine(engine);
  }
}
 
Example 3
Source File: HistoryCleanupOnEngineBootstrapTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCreateHistoryCleanupJobLogs() {

  final ProcessEngineConfigurationImpl standaloneInMemProcessEngineConfiguration =
      (ProcessEngineConfigurationImpl)ProcessEngineConfiguration
          .createStandaloneInMemProcessEngineConfiguration();
  standaloneInMemProcessEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00");
  standaloneInMemProcessEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00");
  standaloneInMemProcessEngineConfiguration
      .setJdbcUrl("jdbc:h2:mem:camunda" + getClass().getSimpleName() + "testHistoryCleanupJobScheduled");

  ProcessEngine engine = standaloneInMemProcessEngineConfiguration.buildProcessEngine();
  try {
    List<HistoricJobLog> historicJobLogs = engine.getHistoryService()
                                                 .createHistoricJobLogQuery()
                                                 .jobDefinitionType(HistoryCleanupJobHandler.TYPE)
                                                 .list();
    for (HistoricJobLog historicJobLog : historicJobLogs) {
      assertNotNull(historicJobLog.getHostname());
    }
  } finally {
    closeProcessEngine(engine);
  }
}
 
Example 4
Source File: ConcurrentHistoryCleanupReconfigureTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void initializeProcessEngine() {
  processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
    .createProcessEngineConfigurationFromResource("camunda.cfg.xml");

  processEngineConfiguration.setHistoryCleanupBatchWindowStartTime("12:00");

  processEngine = processEngineConfiguration.buildProcessEngine();
}
 
Example 5
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 6
Source File: HistoryCleanupDisabledOnBootstrapTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public ProcessEngineConfiguration configureEngine(ProcessEngineConfigurationImpl configuration) {
  configuration.setJdbcUrl("jdbc:h2:mem:" + HistoryCleanupDisabledOnBootstrapTest.class.getSimpleName());
  configuration.setHistoryCleanupEnabled(false);
  configuration.setHistoryCleanupBatchWindowStartTime("12:00");
  configuration.setDatabaseSchemaUpdate(DB_SCHEMA_UPDATE_CREATE_DROP);
  return configuration;
}
 
Example 7
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 8
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();
    }
  };
}