@Test public void shouldCheckCreateTimeOnMessage() { // given testRule.deploy(Bpmn.createExecutableProcess("process") .startEvent() .camundaAsyncBefore() .endEvent() .done()); runtimeService.startProcessInstanceByKey("process"); // when Job messageJob = managementService.createJobQuery().singleResult(); // then assertThat(messageJob.getCreateTime(), is(CREATE_DATE)); assertThat(messageJob.getClass().getSimpleName(), is("MessageEntity")); // cleanup jobIds.add(messageJob.getId()); }
public static BpmnModelInstance oneBpmnCallActivityProcessAsExpressionAsync(int processNumber){ return ProcessModels.newModel(processNumber) .startEvent() .camundaAsyncBefore(true) .callActivity() .calledElement("${NextProcess}") .camundaIn("NextProcess", "NextProcess") .endEvent() .done(); }
public void testHistoricProcInstExecutedJobWithTwoProcInsts() { BpmnModelInstance asyncModel = Bpmn.createExecutableProcess("async").startEvent().camundaAsyncBefore().endEvent().done(); deployment(asyncModel);
@Test @RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testHistoricProcInstExecutedJobWithEmptyInterval() { // given BpmnModelInstance asyncModel = Bpmn.createExecutableProcess("async").startEvent().camundaAsyncBefore().endEvent().done(); deployment(asyncModel); BpmnModelInstance model = Bpmn.createExecutableProcess("proc").startEvent().endEvent().done(); deployment(model); Calendar now = Calendar.getInstance(); ClockUtil.setCurrentTime(now.getTime()); Calendar hourBeforeNow = (Calendar) now.clone(); hourBeforeNow.add(Calendar.HOUR_OF_DAY, -1); runtimeService.startProcessInstanceByKey("async"); Job job = managementService.createJobQuery().singleResult(); managementService.executeJob(job.getId()); runtimeService.startProcessInstanceByKey("proc"); //when query historic proc inst with executed job before and after an hour before the starting time HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() .executedJobBefore(hourBeforeNow.getTime()) .executedJobAfter(hourBeforeNow.getTime()).singleResult(); //then query returns no result assertNull(historicProcessInstance); }
@Test public void shouldResolveJobLog() { // given testRule.deploy(CALLING_PROCESS); testRule.deploy(Bpmn.createExecutableProcess(CALLED_PROCESS_KEY) .startEvent().camundaAsyncBefore() .userTask("userTask").name("userTask") .endEvent().done()); ClockUtil.setCurrentTime(START_DATE); runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); String jobId = managementService.createJobQuery() .singleResult() .getId(); try { managementService.executeJob(jobId); } catch (Exception ignored) { } List<HistoricJobLog> jobLog = historyService.createHistoricJobLogQuery().list(); // assume assertThat(jobLog.get(0).getRemovalTime(), nullValue()); assertThat(jobLog.get(1).getRemovalTime(), nullValue()); ClockUtil.setCurrentTime(END_DATE); String taskId = taskService.createTaskQuery().singleResult().getId(); // when taskService.complete(taskId); jobLog = historyService.createHistoricJobLogQuery().list(); Date removalTime = addDays(END_DATE, 5); // then assertThat(jobLog.get(0).getRemovalTime(), is(removalTime)); assertThat(jobLog.get(1).getRemovalTime(), is(removalTime)); }
/** * See https://app.camunda.com/jira/browse/CAM-9505 */ @Test public void shouldResolveJobLogWithTimestampPreserved() { // given testRule.deploy(CALLING_PROCESS); testRule.deploy(Bpmn.createExecutableProcess(CALLED_PROCESS_KEY) .startEvent().camundaAsyncBefore() .userTask("userTask").name("userTask") .endEvent().done()); ClockUtil.setCurrentTime(START_DATE); runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); String jobId = managementService.createJobQuery() .singleResult() .getId(); try { managementService.executeJob(jobId); } catch (Exception ignored) { } String taskId = taskService.createTaskQuery().singleResult().getId(); // when taskService.complete(taskId); List<HistoricJobLog> jobLog = historyService.createHistoricJobLogQuery().list(); // then assertThat(jobLog.get(0).getTimestamp(), is(START_DATE)); assertThat(jobLog.get(1).getTimestamp(), is(START_DATE)); }
@Test @RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testHistoricProcInstExecutedJobBefore() { // given BpmnModelInstance asyncModel = Bpmn.createExecutableProcess("async").startEvent().camundaAsyncBefore().endEvent().done(); deployment(asyncModel); BpmnModelInstance model = Bpmn.createExecutableProcess("proc").startEvent().endEvent().done(); deployment(model); Calendar now = Calendar.getInstance(); ClockUtil.setCurrentTime(now.getTime()); Calendar hourBeforeNow = (Calendar) now.clone(); hourBeforeNow.add(Calendar.HOUR_OF_DAY, -1); runtimeService.startProcessInstanceByKey("async"); Job job = managementService.createJobQuery().singleResult(); managementService.executeJob(job.getId()); runtimeService.startProcessInstanceByKey("proc"); //when query historic process instance which has executed an job before the start time HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() .executedJobBefore(now.getTime()).singleResult(); //then query returns only a single process instance since before is less-then-equal assertNotNull(historicProcessInstance); //when query historic proc inst with executed job before an hour of the starting time historicProcessInstance = historyService.createHistoricProcessInstanceQuery().executedJobBefore(hourBeforeNow.getTime()).singleResult(); //then query returns no result assertNull(historicProcessInstance); }
@Test @RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testHistoricProcInstExecutedJobAfter() { // given BpmnModelInstance asyncModel = Bpmn.createExecutableProcess("async").startEvent().camundaAsyncBefore().endEvent().done(); deployment(asyncModel); BpmnModelInstance model = Bpmn.createExecutableProcess("proc").startEvent().endEvent().done(); deployment(model); Calendar now = Calendar.getInstance(); ClockUtil.setCurrentTime(now.getTime()); Calendar hourFromNow = (Calendar) now.clone(); hourFromNow.add(Calendar.HOUR_OF_DAY, 1); runtimeService.startProcessInstanceByKey("async"); Job job = managementService.createJobQuery().singleResult(); managementService.executeJob(job.getId()); runtimeService.startProcessInstanceByKey("proc"); //when query historic process instance which has executed an job after the start time HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() .executedJobAfter(now.getTime()).singleResult(); //then query returns only a single process instance assertNotNull(historicProcessInstance); //when query historic proc inst with execute job after a hour of the starting time historicProcessInstance = historyService.createHistoricProcessInstanceQuery().executedJobAfter(hourFromNow.getTime()).singleResult(); //then query returns no result assertNull(historicProcessInstance); }
@Test public void shouldCleanupJobLog() { // given testRule.deploy(CALLING_PROCESS); testRule.deploy(Bpmn.createExecutableProcess(PROCESS_KEY) .startEvent().camundaAsyncBefore() .userTask("userTask").name("userTask") .endEvent().done()); runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); ClockUtil.setCurrentTime(END_DATE); String jobId = managementService.createJobQuery() .singleResult() .getId(); managementService.executeJob(jobId); List<HistoricJobLog> jobLogs = historyService.createHistoricJobLogQuery() .processDefinitionKey(PROCESS_KEY) .list(); // assume assertThat(jobLogs.size(), is(2)); String taskId = taskService.createTaskQuery().singleResult().getId(); taskService.complete(taskId); ClockUtil.setCurrentTime(addDays(END_DATE, 5)); // when runHistoryCleanup(); jobLogs = historyService.createHistoricJobLogQuery() .processDefinitionKey(PROCESS_KEY) .list(); // then assertThat(jobLogs.size(), is(0)); }
@Test public void testRetryOnAsyncStartEvent() throws Exception { BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("process") .startEvent() .camundaAsyncBefore() .camundaFailedJobRetryTimeCycle("R5/PT5M") .serviceTask() .camundaClass("bar") .endEvent() .done(); testRule.deploy(bpmnModelInstance); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process"); assertJobRetries(processInstance, 4); }
@Test public void shouldCleanupUserOperationLog() { // given testRule.deploy(CALLING_PROCESS); testRule.deploy(Bpmn.createExecutableProcess(PROCESS_KEY) .startEvent().camundaAsyncBefore() .userTask("userTask").name("userTask") .endEvent().done()); runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); String jobId = managementService.createJobQuery() .singleResult() .getId(); identityService.setAuthenticatedUserId("aUserId"); managementService.setJobRetries(jobId, 65); identityService.clearAuthentication(); List<UserOperationLogEntry> userOperationLogs = historyService.createUserOperationLogQuery().list(); // assume assertThat(userOperationLogs.size(), is(1)); managementService.executeJob(jobId); ClockUtil.setCurrentTime(END_DATE); String taskId = taskService.createTaskQuery().singleResult().getId(); taskService.complete(taskId); ClockUtil.setCurrentTime(addDays(END_DATE, 5)); // when runHistoryCleanup(); userOperationLogs = historyService.createUserOperationLogQuery().list(); // then assertThat(userOperationLogs.size(), is(0)); }
public void testRetryOnAsyncStartEvent() throws Exception { BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("process") .startEvent() .camundaAsyncBefore() .camundaFailedJobRetryTimeCycle("R5/PT5M") .serviceTask() .camundaClass("bar") .endEvent() .done(); deployment(bpmnModelInstance); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date startDate = simpleDateFormat.parse("2018-01-01T10:00:00"); ClockUtil.setCurrentTime(startDate); runtimeService.startProcessInstanceByKey("process"); Job job = managementService.createJobQuery().singleResult(); // assume Assert.assertEquals(3, job.getRetries()); // when job fails try { managementService.executeJob(job.getId()); } catch (Exception e) { // ignore } // then job = managementService.createJobQuery().singleResult(); Assert.assertEquals(4, job.getRetries()); Date expectedDate = simpleDateFormat.parse("2018-01-01T10:05:00"); assertEquals(expectedDate, ((JobEntity) job).getLockExpirationTime()); }
public void testSetVariableInEndListenerOfAsyncStartEvent () throws Exception { //given BpmnModelInstance subProcess = Bpmn.createExecutableProcess("process") .startEvent() .camundaAsyncBefore() .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, SubProcessActivityStartListener.class.getName()) .endEvent() .done(); org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment() .addModelInstance("process.bpmn", subProcess) .deploy(); //when runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValue("executionListenerCounter",1)); managementService.executeJob(managementService.createJobQuery().active().singleResult().getId()); //then assertThat(historyService.createHistoricVariableInstanceQuery().count(), is (2L)); repositoryService.deleteDeployment(deployment.getId(),true); }
public void testSetVariableInStartListenerOfAsyncStartEvent () throws Exception { //given BpmnModelInstance subProcess = Bpmn.createExecutableProcess("process") .startEvent() .camundaAsyncBefore() .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_START, SubProcessActivityStartListener.class.getName()) .endEvent() .done(); org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment() .addModelInstance("process.bpmn", subProcess) .deploy(); //when runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValue("executionListenerCounter",1)); managementService.executeJob(managementService.createJobQuery().active().singleResult().getId()); //then assertThat(historyService.createHistoricVariableInstanceQuery().count(), is (2L)); repositoryService.deleteDeployment(deployment.getId(),true); }
public void testTxListenersInvokeAsync() { BpmnModelInstance process = Bpmn.createExecutableProcess("testProcess") .startEvent() .camundaAsyncBefore() .camundaAsyncAfter() .endEvent() .done(); Deployment deployment = repositoryService.createDeployment() .addModelInstance("testProcess.bpmn", process) .deploy(); ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess"); waitForJobExecutorToProcessAllJobs(6000); assertProcessEnded(pi.getId()); repositoryService.deleteDeployment(deployment.getId(), true); }
@Test public void shouldResolveUserOperationLog_SetJobRetries() { // given testRule.deploy(CALLING_PROCESS); testRule.deploy(Bpmn.createExecutableProcess(CALLED_PROCESS_KEY) .startEvent().camundaAsyncBefore() .userTask("userTask").name("userTask") .endEvent().done()); ClockUtil.setCurrentTime(START_DATE); runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); String jobId = managementService.createJobQuery() .singleResult() .getId(); identityService.setAuthenticatedUserId("aUserId"); managementService.setJobRetries(jobId, 65); identityService.clearAuthentication(); UserOperationLogEntry userOperationLog = historyService.createUserOperationLogQuery().singleResult(); // assume assertThat(userOperationLog.getRemovalTime(), nullValue()); managementService.executeJob(jobId); ClockUtil.setCurrentTime(END_DATE); String taskId = taskService.createTaskQuery().singleResult().getId(); // when taskService.complete(taskId); userOperationLog = historyService.createUserOperationLogQuery().singleResult(); Date removalTime = addDays(END_DATE, 5); // then assertThat(userOperationLog.getRemovalTime(), is(removalTime)); }
public void testSetVariableInSubProcessStartEventWithEndListener () throws Exception { //given BpmnModelInstance topProcess = Bpmn.createExecutableProcess("topProcess") .startEvent() .callActivity() .calledElement("subProcess") .camundaIn("executionListenerCounter","executionListenerCounter") .endEvent() .done(); BpmnModelInstance subProcess = Bpmn.createExecutableProcess("subProcess") .startEvent() .camundaAsyncBefore() .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, "org.camunda.bpm.engine.test.history.SubProcessActivityStartListener") .endEvent() .done(); org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment() .addModelInstance("process.bpmn", topProcess) .addModelInstance("subProcess.bpmn", subProcess) .deploy(); //when runtimeService.startProcessInstanceByKey("topProcess", Variables.createVariables().putValue("executionListenerCounter",1)); managementService.executeJob(managementService.createJobQuery().active().singleResult().getId()); //then assertThat(historyService.createHistoricVariableInstanceQuery().count(), is (3L)); repositoryService.deleteDeployment(deployment.getId(),true); }
public void testAsyncStartEventWithChangedVariable() { // given a process definition with asynchronous start event deployment(Bpmn.createExecutableProcess("testProcess") .startEvent() .camundaAsyncBefore() .endEvent() .done()); // when create an instance with a variable ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess", Variables.putValue("var", "foo")); // and update this variable before the instance is created runtimeService.setVariable(processInstance.getId(), "var", "bar"); executeAvailableJobs(); assertProcessEnded(processInstance.getId()); if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) { // then the history contains only one entry for the latest update (value = "bar") // - the entry for the initial value (value = "foo") is lost because of current limitations HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery(); assertEquals(query.count(), 1); HistoricVariableInstance variable = query.singleResult(); assertEquals(variable.getValue(), "bar"); assertNotNull(variable.getActivityInstanceId()); } }
@Test public void testPurgeWithAsyncProcessInstance() { // given process with variable and async process instance BpmnModelInstance test = Bpmn.createExecutableProcess(PROCESS_DEF_KEY) .startEvent() .camundaAsyncBefore() .userTask() .userTask() .endEvent() .done(); engineRule.getRepositoryService().createDeployment().addModelInstance(PROCESS_MODEL_NAME, test).deploy(); VariableMap variables = Variables.createVariables(); variables.put("key", "value"); engineRule.getRuntimeService().startProcessInstanceByKey(PROCESS_DEF_KEY, variables); Job job = engineRule.getManagementService().createJobQuery().singleResult(); engineRule.getManagementService().executeJob(job.getId()); Task task = engineRule.getTaskService().createTaskQuery().singleResult(); engineRule.getTaskService().complete(task.getId()); // when purge is executed ManagementServiceImpl managementService = (ManagementServiceImpl) engineRule.getManagementService(); managementService.purge(); // then no more data exist assertAndEnsureCleanDbAndCache(engineRule.getProcessEngine(), true); }
public void testAsyncStartEventWithAddedVariable() { // given a process definition with asynchronous start event deployment(Bpmn.createExecutableProcess("testProcess") .startEvent() .camundaAsyncBefore() .endEvent() .done()); // when create an instance with a variable ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess", Variables.putValue("var1", "foo")); // and add a variable before the instance is created runtimeService.setVariable(processInstance.getId(), "var2", "bar"); executeAvailableJobs(); assertProcessEnded(processInstance.getId()); if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) { // then the history contains one entry for each variable HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery(); assertEquals(query.count(), 2); HistoricVariableInstance firstVariable = query.variableName("var1").singleResult(); assertNotNull(firstVariable); assertEquals(firstVariable.getValue(), "foo"); assertNotNull(firstVariable.getActivityInstanceId()); HistoricVariableInstance secondVariable = query.variableName("var2").singleResult(); assertNotNull(secondVariable); assertEquals(secondVariable.getValue(), "bar"); assertNotNull(secondVariable.getActivityInstanceId()); } }