use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity 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);
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class HistoryCleanupTest method clearDatabase.
@After
public void clearDatabase() {
// reset configuration changes
processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(defaultStartTime);
processEngineConfiguration.setHistoryCleanupBatchWindowEndTime(defaultEndTime);
processEngineConfiguration.setHistoryCleanupBatchSize(defaultBatchSize);
processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
List<Job> jobs = managementService.createJobQuery().list();
if (jobs.size() > 0) {
assertEquals(1, jobs.size());
String jobId = jobs.get(0).getId();
commandContext.getJobManager().deleteJob((JobEntity) jobs.get(0));
commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(jobId);
}
List<HistoricIncident> historicIncidents = historyService.createHistoricIncidentQuery().list();
for (HistoricIncident historicIncident : historicIncidents) {
commandContext.getDbEntityManager().delete((HistoricIncidentEntity) historicIncident);
}
commandContext.getMeterLogManager().deleteAll();
return null;
}
});
List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().list();
for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
historyService.deleteHistoricProcessInstance(historicProcessInstance.getId());
}
List<HistoricDecisionInstance> historicDecisionInstances = historyService.createHistoricDecisionInstanceQuery().list();
for (HistoricDecisionInstance historicDecisionInstance : historicDecisionInstances) {
historyService.deleteHistoricDecisionInstanceByInstanceId(historicDecisionInstance.getId());
}
List<HistoricCaseInstance> historicCaseInstances = historyService.createHistoricCaseInstanceQuery().list();
for (HistoricCaseInstance historicCaseInstance : historicCaseInstances) {
historyService.deleteHistoricCaseInstance(historicCaseInstance.getId());
}
clearMetrics();
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity 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);
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class HistoryCleanupOnEngineStartTest method clearDatabase.
@After
public void clearDatabase() {
ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) engineRule.getProcessEngine().getProcessEngineConfiguration();
processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
List<Job> jobs = engineRule.getProcessEngine().getManagementService().createJobQuery().list();
if (jobs.size() > 0) {
assertEquals(1, jobs.size());
String jobId = jobs.get(0).getId();
commandContext.getJobManager().deleteJob((JobEntity) jobs.get(0));
commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(jobId);
}
return null;
}
});
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class ConcurrentJobExecutorTest method testCompetingJobExecutionDefaultRetryStrategy.
@Test
@Deployment
public void testCompetingJobExecutionDefaultRetryStrategy() {
// given an MI subprocess with two instances
runtimeService.startProcessInstanceByKey("miParallelSubprocess");
List<Job> currentJobs = managementService.createJobQuery().list();
assertEquals(2, currentJobs.size());
// when the jobs are executed in parallel
JobExecutionThread threadOne = new JobExecutionThread(currentJobs.get(0).getId());
threadOne.startAndWaitUntilControlIsReturned();
JobExecutionThread threadTwo = new JobExecutionThread(currentJobs.get(1).getId());
threadTwo.startAndWaitUntilControlIsReturned();
// then the first committing thread succeeds
LOG.debug("test thread notifies thread 1");
threadOne.proceedAndWaitTillDone();
assertNull(threadOne.exception);
// then the second committing thread fails with an OptimisticLockingException
// and the job retries have not been decremented
LOG.debug("test thread notifies thread 2");
threadTwo.proceedAndWaitTillDone();
assertNotNull(threadTwo.exception);
Job remainingJob = managementService.createJobQuery().singleResult();
assertEquals(currentJobs.get(1).getRetries(), remainingJob.getRetries());
assertNotNull(remainingJob.getExceptionMessage());
JobEntity jobEntity = (JobEntity) remainingJob;
assertNull(jobEntity.getLockOwner());
// and there is no lock expiration time due to the default retry strategy
assertNull(jobEntity.getLockExpirationTime());
}
Aggregations