Search in sources :

Example 51 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity 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)

Example 52 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method testLessThanThresholdOutsideBatchWindowAfterMidnight.

@Test
public void testLessThanThresholdOutsideBatchWindowAfterMidnight() {
    // given
    prepareData(5);
    // we're outside batch window, batch window passes midnight
    Date date = new Date();
    // 01:10
    ClockUtil.setCurrentTime(DateUtils.setMinutes(DateUtils.setHours(date, 1), 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 canceled
    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)

Example 53 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method testRescheduleForNever.

@Test
public void testRescheduleForNever() {
    // given
    // force creation of job
    historyService.cleanUpHistoryAsync(true);
    JobEntity historyCleanupJob = (JobEntity) historyService.findHistoryCleanupJob();
    assertNotNull(historyCleanupJob);
    assertNotNull(historyCleanupJob.getDuedate());
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(null);
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(null);
    processEngineConfiguration.initHistoryCleanup();
    ClockUtil.setCurrentTime(new Date());
    // when
    historyService.cleanUpHistoryAsync(false);
    // then
    historyCleanupJob = (JobEntity) historyService.findHistoryCleanupJob();
    assertEquals(SuspensionState.SUSPENDED.getStateCode(), historyCleanupJob.getSuspensionState());
    assertNull(historyCleanupJob.getDuedate());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Date(java.util.Date) Test(org.junit.Test)

Example 54 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method testLessThanThresholdWithinBatchWindow.

@Test
public void testLessThanThresholdWithinBatchWindow() {
    // 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, HISTORY_TIME_TO_LIVE)));
    processEngineConfiguration.initHistoryCleanup();
    // when
    String jobId = historyService.cleanUpHistoryAsync().getId();
    managementService.executeJob(jobId);
    // 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) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 55 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method testLessThanThresholdOutsideBatchWindow.

@Test
public void testLessThanThresholdOutsideBatchWindow() {
    // given
    prepareData(5);
    // we're outside batch window
    Date twoHoursAgo = new Date();
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(new SimpleDateFormat("HH:mm").format(twoHoursAgo));
    processEngineConfiguration.setHistoryCleanupBatchWindowEndTime(new SimpleDateFormat("HH:mm").format(DateUtils.addHours(twoHoursAgo, 1)));
    processEngineConfiguration.initHistoryCleanup();
    ClockUtil.setCurrentTime(DateUtils.addHours(twoHoursAgo, 2));
    // when
    String jobId = historyService.cleanUpHistoryAsync().getId();
    for (int i = 1; i <= 3; i++) {
        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));
    // countEmptyRuns canceled
    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) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Aggregations

JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)68 Test (org.junit.Test)26 Date (java.util.Date)18 Job (org.camunda.bpm.engine.runtime.Job)13 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)11 HistoryCleanupJobHandlerConfiguration (org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration)9 Deployment (org.camunda.bpm.engine.test.Deployment)9 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)7 SimpleDateFormat (java.text.SimpleDateFormat)6 List (java.util.List)6 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)6 Page (org.camunda.bpm.engine.impl.Page)5 JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)4 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)4 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)4 ArrayList (java.util.ArrayList)3 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3