use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class HistoryCleanupAuthorizationTest method clearDatabase.
protected void clearDatabase() {
// reset configuration changes
String defaultStartTime = processEngineConfiguration.getHistoryCleanupBatchWindowStartTime();
String defaultEndTime = processEngineConfiguration.getHistoryCleanupBatchWindowEndTime();
int defaultBatchSize = processEngineConfiguration.getHistoryCleanupBatchSize();
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());
}
}
use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class ManagementServiceTest method deleteJobAndIncidents.
protected void deleteJobAndIncidents(final Job job) {
final List<HistoricIncident> incidents = historyService.createHistoricIncidentQuery().incidentType(Incident.FAILED_JOB_HANDLER_TYPE).list();
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Void>() {
@Override
public Void execute(CommandContext commandContext) {
((JobEntity) job).delete();
HistoricIncidentManager historicIncidentManager = commandContext.getHistoricIncidentManager();
for (HistoricIncident incident : incidents) {
HistoricIncidentEntity incidentEntity = (HistoricIncidentEntity) incident;
historicIncidentManager.delete(incidentEntity);
}
commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(job.getId());
return null;
}
});
}
use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class ManagementServiceTest method createJob.
protected void createJob(final int retries, final String owner, final Date lockExpirationTime) {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Void>() {
@Override
public Void execute(CommandContext commandContext) {
JobManager jobManager = commandContext.getJobManager();
MessageEntity job = new MessageEntity();
job.setJobHandlerType("any");
job.setLockOwner(owner);
job.setLockExpirationTime(lockExpirationTime);
job.setRetries(retries);
jobManager.send(job);
return null;
}
});
}
use of org.camunda.bpm.engine.impl.interceptor.CommandContext 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.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class JobQueryTest method createJobWithoutExceptionMsg.
private void createJobWithoutExceptionMsg() {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
JobManager jobManager = commandContext.getJobManager();
timerEntity = new TimerEntity();
timerEntity.setLockOwner(UUID.randomUUID().toString());
timerEntity.setDuedate(new Date());
timerEntity.setRetries(0);
StringWriter stringWriter = new StringWriter();
NullPointerException exception = new NullPointerException();
exception.printStackTrace(new PrintWriter(stringWriter));
timerEntity.setExceptionStacktrace(stringWriter.toString());
jobManager.insert(timerEntity);
assertNotNull(timerEntity.getId());
return null;
}
});
}
Aggregations