Search in sources :

Example 1 with HistoryCleanupJobHandlerConfiguration

use of org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method testLessThanThresholdWithinBatchWindowMaxDelayReached.

@Test
public void testLessThanThresholdWithinBatchWindowMaxDelayReached() {
    // given
    prepareData(5);
    // we're within batch window
    Date now = new Date();
    ClockUtil.setCurrentTime(now);
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(new SimpleDateFormat("HH:mm").format(now));
    processEngineConfiguration.setHistoryCleanupBatchWindowEndTime(new SimpleDateFormat("HH:mm").format(DateUtils.addHours(now, 2)));
    processEngineConfiguration.initHistoryCleanup();
    // when
    String jobId = historyService.cleanUpHistoryAsync().getId();
    for (int i = 1; i <= 11; i++) {
        managementService.executeJob(jobId);
    }
    // then
    JobEntity jobEntity = getJobEntity(jobId);
    HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity);
    // job rescheduled till current time + max delay
    Date nextRun = getNextRunWithDelay(ClockUtil.getCurrentTime(), 10);
    assertTrue(jobEntity.getDuedate().equals(nextRun) || jobEntity.getDuedate().after(nextRun));
    assertTrue(jobEntity.getDuedate().before(getNextRunWithinBatchWindow(now)));
    // countEmptyRuns incremented
    assertEquals(11, configuration.getCountEmptyRuns());
    // data is still removed
    assertResult(0);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) HistoryCleanupJobHandlerConfiguration(org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 2 with HistoryCleanupJobHandlerConfiguration

use of org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method testLessThanThresholdWithinBatchWindowAgain.

@Test
public void testLessThanThresholdWithinBatchWindowAgain() {
    // given
    prepareData(5);
    // we're within batch window
    Date now = new Date();
    ClockUtil.setCurrentTime(now);
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(new SimpleDateFormat("HH:mm").format(now));
    processEngineConfiguration.setHistoryCleanupBatchWindowEndTime(new SimpleDateFormat("HH:mm").format(DateUtils.addHours(now, 1)));
    processEngineConfiguration.initHistoryCleanup();
    // when
    String jobId = historyService.cleanUpHistoryAsync().getId();
    for (int i = 1; i <= 6; i++) {
        managementService.executeJob(jobId);
    }
    // then
    JobEntity jobEntity = getJobEntity(jobId);
    HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity);
    // job rescheduled till current time + (2 power count)*delay
    Date nextRun = getNextRunWithDelay(ClockUtil.getCurrentTime(), HISTORY_TIME_TO_LIVE);
    assertTrue(jobEntity.getDuedate().equals(nextRun) || jobEntity.getDuedate().after(nextRun));
    Date nextRunMax = DateUtils.addSeconds(ClockUtil.getCurrentTime(), HistoryCleanupJobHandlerConfiguration.MAX_DELAY);
    assertTrue(jobEntity.getDuedate().before(nextRunMax));
    // countEmptyRuns incremented
    assertEquals(6, configuration.getCountEmptyRuns());
    // data is still removed
    assertResult(0);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) HistoryCleanupJobHandlerConfiguration(org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 3 with HistoryCleanupJobHandlerConfiguration

use of org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method testLessThanThresholdWithinBatchWindowBeforeMidnight.

@Test
public void testLessThanThresholdWithinBatchWindowBeforeMidnight() {
    // given
    prepareData(5);
    // we're within batch window, but batch window passes midnight
    Date date = new Date();
    // 23:10
    ClockUtil.setCurrentTime(DateUtils.setMinutes(DateUtils.setHours(date, 23), 10));
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00");
    processEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00");
    processEngineConfiguration.initHistoryCleanup();
    // when
    String jobId = historyService.cleanUpHistoryAsync().getId();
    ExecuteJobHelper.executeJob(jobId, processEngineConfiguration.getCommandExecutorTxRequired());
    // then
    JobEntity jobEntity = getJobEntity(jobId);
    HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity);
    // job rescheduled till current time + delay
    Date nextRun = getNextRunWithDelay(ClockUtil.getCurrentTime(), 0);
    assertTrue(jobEntity.getDuedate().equals(nextRun) || jobEntity.getDuedate().after(nextRun));
    Date nextRunMax = DateUtils.addSeconds(ClockUtil.getCurrentTime(), HistoryCleanupJobHandlerConfiguration.MAX_DELAY);
    assertTrue(jobEntity.getDuedate().before(nextRunMax));
    // countEmptyRuns incremented
    assertEquals(1, configuration.getCountEmptyRuns());
    // data is still removed
    assertResult(0);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) HistoryCleanupJobHandlerConfiguration(org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration) Date(java.util.Date) Test(org.junit.Test)

Example 4 with HistoryCleanupJobHandlerConfiguration

use of org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method testLessThanThresholdWithinBatchWindowAfterMidnight.

@Test
public void testLessThanThresholdWithinBatchWindowAfterMidnight() {
    // given
    prepareData(5);
    // we're within batch window, but batch window passes midnight
    Date date = new Date();
    // 00:10
    ClockUtil.setCurrentTime(DateUtils.setMinutes(DateUtils.setHours(date, 0), 10));
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00");
    processEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00");
    processEngineConfiguration.initHistoryCleanup();
    // when
    String jobId = historyService.cleanUpHistoryAsync().getId();
    ExecuteJobHelper.executeJob(jobId, processEngineConfiguration.getCommandExecutorTxRequired());
    // then
    JobEntity jobEntity = getJobEntity(jobId);
    HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity);
    // job rescheduled till current time + delay
    Date nextRun = getNextRunWithDelay(ClockUtil.getCurrentTime(), 0);
    assertTrue(jobEntity.getDuedate().equals(nextRun) || jobEntity.getDuedate().after(nextRun));
    Date nextRunMax = DateUtils.addSeconds(ClockUtil.getCurrentTime(), HistoryCleanupJobHandlerConfiguration.MAX_DELAY);
    assertTrue(jobEntity.getDuedate().before(nextRunMax));
    // countEmptyRuns incremented
    assertEquals(1, configuration.getCountEmptyRuns());
    // data is still removed
    assertResult(0);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) HistoryCleanupJobHandlerConfiguration(org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration) Date(java.util.Date) Test(org.junit.Test)

Example 5 with HistoryCleanupJobHandlerConfiguration

use of org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method testLessThanThresholdOutsideBatchWindowBeforeMidnight.

@Test
public void testLessThanThresholdOutsideBatchWindowBeforeMidnight() {
    // given
    prepareData(5);
    // we're outside batch window, batch window passes midnight
    Date date = new Date();
    // 22:10
    ClockUtil.setCurrentTime(DateUtils.setMinutes(DateUtils.setHours(date, 22), 10));
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00");
    processEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00");
    processEngineConfiguration.initHistoryCleanup();
    // when
    String jobId = historyService.cleanUpHistoryAsync().getId();
    managementService.executeJob(jobId);
    // then
    JobEntity jobEntity = getJobEntity(jobId);
    HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity);
    // job rescheduled till next batch window start
    Date nextRun = getNextRunWithinBatchWindow(ClockUtil.getCurrentTime());
    assertTrue(jobEntity.getDuedate().equals(nextRun));
    assertTrue(nextRun.after(ClockUtil.getCurrentTime()));
    // countEmptyRuns cancelled
    assertEquals(0, configuration.getCountEmptyRuns());
    // nothing was removed
    assertResult(5);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) HistoryCleanupJobHandlerConfiguration(org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Date (java.util.Date)9 HistoryCleanupJobHandlerConfiguration (org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration)9 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)9 Test (org.junit.Test)9 SimpleDateFormat (java.text.SimpleDateFormat)5