use of org.camunda.bpm.engine.impl.history.event.HistoricProcessInstanceEventEntity in project camunda-bpm-platform by camunda.
the class HistoricProcessInstanceTest method testHistoricDataCreatedForProcessExecution.
@Deployment(resources = { "org/camunda/bpm/engine/test/history/oneTaskProcess.bpmn20.xml" })
public void testHistoricDataCreatedForProcessExecution() {
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.YEAR, 2010);
calendar.set(Calendar.MONTH, 8);
calendar.set(Calendar.DAY_OF_MONTH, 30);
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
Date noon = calendar.getTime();
ClockUtil.setCurrentTime(noon);
final ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", "myBusinessKey");
assertEquals(1, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().finished().count());
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(historicProcessInstance);
assertEquals(processInstance.getId(), historicProcessInstance.getId());
assertEquals(processInstance.getBusinessKey(), historicProcessInstance.getBusinessKey());
assertEquals(processInstance.getProcessDefinitionId(), historicProcessInstance.getProcessDefinitionId());
assertEquals(noon, historicProcessInstance.getStartTime());
assertNull(historicProcessInstance.getEndTime());
assertNull(historicProcessInstance.getDurationInMillis());
assertNull(historicProcessInstance.getCaseInstanceId());
List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
assertEquals(1, tasks.size());
// in this test scenario we assume that 25 seconds after the process start, the
// user completes the task (yes! he must be almost as fast as me)
Date twentyFiveSecsAfterNoon = new Date(noon.getTime() + 25 * 1000);
ClockUtil.setCurrentTime(twentyFiveSecsAfterNoon);
taskService.complete(tasks.get(0).getId());
historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(historicProcessInstance);
assertEquals(processInstance.getId(), historicProcessInstance.getId());
assertEquals(processInstance.getProcessDefinitionId(), historicProcessInstance.getProcessDefinitionId());
assertEquals(noon, historicProcessInstance.getStartTime());
assertEquals(twentyFiveSecsAfterNoon, historicProcessInstance.getEndTime());
assertEquals(new Long(25 * 1000), historicProcessInstance.getDurationInMillis());
assertTrue(((HistoricProcessInstanceEventEntity) historicProcessInstance).getDurationRaw() >= 25000);
assertNull(historicProcessInstance.getCaseInstanceId());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().finished().count());
runtimeService.startProcessInstanceByKey("oneTaskProcess", "myBusinessKey");
assertEquals(1, historyService.createHistoricProcessInstanceQuery().finished().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().finished().unfinished().count());
}
use of org.camunda.bpm.engine.impl.history.event.HistoricProcessInstanceEventEntity in project camunda-bpm-platform by camunda.
the class HistoricProcessInstanceTest method testLongRunningHistoricDataCreatedForProcessExecution.
@Deployment(resources = { "org/camunda/bpm/engine/test/history/oneTaskProcess.bpmn20.xml" })
public void testLongRunningHistoricDataCreatedForProcessExecution() {
final long ONE_YEAR = 1000 * 60 * 60 * 24 * 365;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date now = cal.getTime();
ClockUtil.setCurrentTime(now);
final ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", "myBusinessKey");
assertEquals(1, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().finished().count());
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(now, historicProcessInstance.getStartTime());
List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
assertEquals(1, tasks.size());
// in this test scenario we assume that one year after the process start, the
// user completes the task (incredible speedy!)
cal.add(Calendar.YEAR, 1);
Date oneYearLater = cal.getTime();
ClockUtil.setCurrentTime(oneYearLater);
taskService.complete(tasks.get(0).getId());
historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(now, historicProcessInstance.getStartTime());
assertEquals(oneYearLater, historicProcessInstance.getEndTime());
assertTrue(historicProcessInstance.getDurationInMillis() >= ONE_YEAR);
assertTrue(((HistoricProcessInstanceEventEntity) historicProcessInstance).getDurationRaw() >= ONE_YEAR);
assertEquals(0, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().finished().count());
}
use of org.camunda.bpm.engine.impl.history.event.HistoricProcessInstanceEventEntity in project camunda-bpm-platform by camunda.
the class AbstractSetProcessInstanceStateCmd method triggerHistoryEvent.
@Override
protected void triggerHistoryEvent(CommandContext commandContext) {
HistoryLevel historyLevel = commandContext.getProcessEngineConfiguration().getHistoryLevel();
List<ProcessInstance> updatedProcessInstances = obtainProcessInstances(commandContext);
// suspension state is not updated synchronously
if (getNewSuspensionState() != null && updatedProcessInstances != null) {
for (final ProcessInstance processInstance : updatedProcessInstances) {
if (historyLevel.isHistoryEventProduced(HistoryEventTypes.PROCESS_INSTANCE_UPDATE, processInstance)) {
HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {
@Override
public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
HistoricProcessInstanceEventEntity processInstanceUpdateEvt = (HistoricProcessInstanceEventEntity) producer.createProcessInstanceUpdateEvt((DelegateExecution) processInstance);
if (SuspensionState.SUSPENDED.getStateCode() == getNewSuspensionState().getStateCode()) {
processInstanceUpdateEvt.setState(HistoricProcessInstance.STATE_SUSPENDED);
} else {
processInstanceUpdateEvt.setState(HistoricProcessInstance.STATE_ACTIVE);
}
return processInstanceUpdateEvt;
}
});
}
}
}
}
Aggregations