use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class IncidentTest method testDoNotSetNegativeRetries.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/IncidentTest.testShouldCreateOneIncident.bpmn" })
public void testDoNotSetNegativeRetries() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("failingProcess");
executeAvailableJobs();
// it exists a job with 0 retries and an incident
Job job = managementService.createJobQuery().singleResult();
assertEquals(0, job.getRetries());
assertEquals(1, runtimeService.createIncidentQuery().count());
// it should not be possible to set negative retries
final JobEntity jobEntity = (JobEntity) job;
processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
jobEntity.setRetries(-100);
return null;
}
});
assertEquals(0, job.getRetries());
// retries should still be 0 after execution this job again
try {
managementService.executeJob(job.getId());
fail("Exception expected");
} catch (ProcessEngineException e) {
// expected
}
job = managementService.createJobQuery().singleResult();
assertEquals(0, job.getRetries());
// also no new incident was created
assertEquals(1, runtimeService.createIncidentQuery().count());
// it should not be possible to set the retries to a negative number with the management service
try {
managementService.setJobRetries(job.getId(), -200);
fail("Exception expected");
} catch (ProcessEngineException e) {
// expected
}
try {
managementService.setJobRetriesByJobDefinitionId(job.getJobDefinitionId(), -300);
fail("Exception expected");
} catch (ProcessEngineException e) {
// expected
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class HistoryCleanupBatchWindowTest 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 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);
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity 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);
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class HistoryCleanupTest method testHistoryCleanupJobResolveIncident.
@Test
public void testHistoryCleanupJobResolveIncident() {
// given
String jobId = historyService.cleanUpHistoryAsync(true).getId();
imitateFailedJob(jobId);
assertEquals(5, processEngineConfiguration.getDefaultNumberOfRetries());
// when
// call to cleanup history means that incident was resolved
jobId = historyService.cleanUpHistoryAsync(true).getId();
// then
JobEntity jobEntity = getJobEntity(jobId);
assertEquals(5, jobEntity.getRetries());
assertEquals(null, jobEntity.getExceptionByteArrayId());
assertEquals(null, jobEntity.getExceptionMessage());
}
Aggregations