@Before public void setUpRuntimeData() { runtimeServiceMock = mock(RuntimeService.class); when(processEngine.getRuntimeService()).thenReturn(runtimeServiceMock); historyServiceMock = mock(HistoryService.class); when(processEngine.getHistoryService()).thenReturn(historyServiceMock); builderMock = mock(RestartProcessInstanceBuilder.class); when(builderMock.startAfterActivity(anyString())).thenReturn(builderMock); when(builderMock.startBeforeActivity(anyString())).thenReturn(builderMock); when(builderMock.startTransition(anyString())).thenReturn(builderMock); when(builderMock.processInstanceIds(anyListOf(String.class))).thenReturn(builderMock); when(builderMock.historicProcessInstanceQuery(any(HistoricProcessInstanceQuery.class))).thenReturn(builderMock); when(builderMock.skipCustomListeners()).thenReturn(builderMock); when(builderMock.skipIoMappings()).thenReturn(builderMock); when(builderMock.initialSetOfVariables()).thenReturn(builderMock); when(builderMock.withoutBusinessKey()).thenReturn(builderMock); Batch batchMock = createMockBatch(); when(builderMock.executeAsync()).thenReturn(batchMock); when(runtimeServiceMock.restartProcessInstances(anyString())).thenReturn(builderMock); }
@Test public void testBatchCreationWithOverlappingProcessInstanceIdsAndQuery() { // given int processInstanceCount = 2; ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when HistoricProcessInstanceQuery processInstanceQuery = engineRule.getHistoryService() .createHistoricProcessInstanceQuery() .processDefinitionId(processDefinition.getId()); Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .historicProcessInstanceQuery(processInstanceQuery) .executeAsync(); helper.completeBatch(batch); // then List<ProcessInstance> restartedProcessInstances = engineRule.getRuntimeService().createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).list(); assertEquals(restartedProcessInstances.size(), processInstanceCount); }
.startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync();
@Test public void testMonitorJobRemovesBatchAfterCompletion() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); helper.executeSeedJob(batch); helper.executeJobs(batch); helper.executeMonitorJob(batch); // then the batch was completed and removed assertEquals(0, engineRule.getManagementService().createBatchQuery().count()); // and the seed jobs was removed assertEquals(0, engineRule.getManagementService().createJobQuery().count()); }
@Test public void testBatchWithFailedSeedJobDeletionWithCascade() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); // create incident Job seedJob = helper.getSeedJob(batch); engineRule.getManagementService().setJobRetries(seedJob.getId(), 0); engineRule.getManagementService().deleteBatch(batch.getId(), true); // then the no historic incidents exists long historicIncidents = engineRule.getHistoryService().createHistoricIncidentQuery().count(); assertEquals(0, historicIncidents); }
@Test public void testBatchWithFailedMonitorJobDeletionWithCascade() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); helper.executeSeedJob(batch); // create incident Job monitorJob = helper.getMonitorJob(batch); engineRule.getManagementService().setJobRetries(monitorJob.getId(), 0); engineRule.getManagementService().deleteBatch(batch.getId(), true); // then the no historic incidents exists long historicIncidents = engineRule.getHistoryService().createHistoricIncidentQuery().count(); assertEquals(0, historicIncidents); }
@Test public void testBatchWithFailedExecutionJobDeletionWithCascade() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); helper.executeSeedJob(batch); // create incidents List<Job> executionJobs = helper.getExecutionJobs(batch); for (Job executionJob : executionJobs) { engineRule.getManagementService().setJobRetries(executionJob.getId(), 0); } engineRule.getManagementService().deleteBatch(batch.getId(), true); // then the no historic incidents exists long historicIncidents = engineRule.getHistoryService().createHistoricIncidentQuery().count(); assertEquals(0, historicIncidents); }
@Test public void testMonitorJobPollingForCompletion() { processEngineConfiguration.setEnsureJobDueDateNotNull(false); // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); // when the seed job creates the monitor job Date createDate = ClockTestUtil.setClockToDateWithoutMilliseconds(); helper.executeSeedJob(batch); // then the monitor job has a no due date set Job monitorJob = helper.getMonitorJob(batch); assertNotNull(monitorJob); assertNull(monitorJob.getDuedate()); // when the monitor job is executed helper.executeMonitorJob(batch); // then the monitor job has a due date of the default batch poll time monitorJob = helper.getMonitorJob(batch); Date dueDate = helper.addSeconds(createDate, 30); assertEquals(dueDate, monitorJob.getDuedate()); }
.startTransition("flow1") .processInstanceIds(list) .executeAsync();
@Test public void testBatchDeletionWithCascade() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); helper.executeSeedJob(batch); engineRule.getManagementService().deleteBatch(batch.getId(), true); // then the batch was deleted assertEquals(0, engineRule.getManagementService().createBatchQuery().count()); // and the seed and execution job definition were deleted assertEquals(0, engineRule.getManagementService().createJobDefinitionQuery().count()); // and the seed job and execution jobs were deleted assertEquals(0, engineRule.getManagementService().createJobQuery().count()); }
@Test public void testBatchDeletionWithoutCascade() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); helper.executeSeedJob(batch); engineRule.getManagementService().deleteBatch(batch.getId(), false); // then the batch was deleted assertEquals(0, engineRule.getManagementService().createBatchQuery().count()); // and the seed and execution job definition were deleted assertEquals(0, engineRule.getManagementService().createJobDefinitionQuery().count()); // and the seed job and execution jobs were deleted assertEquals(0, engineRule.getManagementService().createJobQuery().count()); }
@Test public void testBatchCreationWithOverlappingProcessInstanceIdsAndQuery() { // given int processInstanceCount = 2; ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when HistoricProcessInstanceQuery processInstanceQuery = engineRule.getHistoryService() .createHistoricProcessInstanceQuery() .processDefinitionId(processDefinition.getId()); Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .historicProcessInstanceQuery(processInstanceQuery) .executeAsync(); helper.completeBatch(batch); // then List<ProcessInstance> restartedProcessInstances = engineRule.getRuntimeService().createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).list(); assertEquals(restartedProcessInstances.size(), processInstanceCount); }
@Test public void testMonitorJobRemovesBatchAfterCompletion() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); helper.executeSeedJob(batch); helper.executeJobs(batch); helper.executeMonitorJob(batch); // then the batch was completed and removed assertEquals(0, engineRule.getManagementService().createBatchQuery().count()); // and the seed jobs was removed assertEquals(0, engineRule.getManagementService().createJobQuery().count()); }
@Test public void testBatchWithFailedSeedJobDeletionWithCascade() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); // create incident Job seedJob = helper.getSeedJob(batch); engineRule.getManagementService().setJobRetries(seedJob.getId(), 0); engineRule.getManagementService().deleteBatch(batch.getId(), true); // then the no historic incidents exists long historicIncidents = engineRule.getHistoryService().createHistoricIncidentQuery().count(); assertEquals(0, historicIncidents); }
@Test public void testBatchWithFailedExecutionJobDeletionWithCascade() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); helper.executeSeedJob(batch); // create incidents List<Job> executionJobs = helper.getExecutionJobs(batch); for (Job executionJob : executionJobs) { engineRule.getManagementService().setJobRetries(executionJob.getId(), 0); } engineRule.getManagementService().deleteBatch(batch.getId(), true); // then the no historic incidents exists long historicIncidents = engineRule.getHistoryService().createHistoricIncidentQuery().count(); assertEquals(0, historicIncidents); }
@Test public void testBatchWithFailedMonitorJobDeletionWithCascade() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); helper.executeSeedJob(batch); // create incident Job monitorJob = helper.getMonitorJob(batch); engineRule.getManagementService().setJobRetries(monitorJob.getId(), 0); engineRule.getManagementService().deleteBatch(batch.getId(), true); // then the no historic incidents exists long historicIncidents = engineRule.getHistoryService().createHistoricIncidentQuery().count(); assertEquals(0, historicIncidents); }
@Test public void testMonitorJobPollingForCompletion() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); // when the seed job creates the monitor job Date createDate = ClockTestUtil.setClockToDateWithoutMilliseconds(); helper.executeSeedJob(batch); // then the monitor job has a no due date set Job monitorJob = helper.getMonitorJob(batch); assertNotNull(monitorJob); assertNull(monitorJob.getDuedate()); // when the monitor job is executed helper.executeMonitorJob(batch); // then the monitor job has a due date of the default batch poll time monitorJob = helper.getMonitorJob(batch); Date dueDate = helper.addSeconds(createDate, 30); assertEquals(dueDate, monitorJob.getDuedate()); }
@Test public void testBatchDeletionWithCascade() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); helper.executeSeedJob(batch); engineRule.getManagementService().deleteBatch(batch.getId(), true); // then the batch was deleted assertEquals(0, engineRule.getManagementService().createBatchQuery().count()); // and the seed and execution job definition were deleted assertEquals(0, engineRule.getManagementService().createJobDefinitionQuery().count()); // and the seed job and execution jobs were deleted assertEquals(0, engineRule.getManagementService().createJobQuery().count()); }
.startTransition("flow1") .processInstanceIds(list) .executeAsync();
@Test public void testBatchDeletionWithoutCascade() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); helper.executeSeedJob(batch); engineRule.getManagementService().deleteBatch(batch.getId(), false); // then the batch was deleted assertEquals(0, engineRule.getManagementService().createBatchQuery().count()); // and the seed and execution job definition were deleted assertEquals(0, engineRule.getManagementService().createJobDefinitionQuery().count()); // and the seed job and execution jobs were deleted assertEquals(0, engineRule.getManagementService().createJobQuery().count()); }