diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/RestartProcessInstancesJobHandler.java b/engine/src/main/java/org/camunda/bpm/engine/impl/RestartProcessInstancesJobHandler.java index cd518f831e8..7f888ec228a 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/RestartProcessInstancesJobHandler.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/RestartProcessInstancesJobHandler.java @@ -54,6 +54,7 @@ protected void postProcessJob(RestartProcessInstancesBatchConfiguration configur .findDeployedProcessDefinitionById(configuration.getProcessDefinitionId()); job.setDeploymentId(processDefinitionEntity.getDeploymentId()); } + job.setProcessDefinitionId(configuration.getProcessDefinitionId()); } @Override diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/AbstractBatchJobHandler.java b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/AbstractBatchJobHandler.java index 1272ca59427..9deade17313 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/AbstractBatchJobHandler.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/AbstractBatchJobHandler.java @@ -21,6 +21,10 @@ import java.util.Iterator; import java.util.List; import java.util.Map; + +import org.camunda.bpm.engine.impl.batch.externaltask.SetExternalTaskRetriesJobHandler; +import org.camunda.bpm.engine.impl.batch.job.SetJobRetriesJobHandler; +import org.camunda.bpm.engine.impl.batch.removaltime.DecisionSetRemovalTimeJobHandler; import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; import org.camunda.bpm.engine.impl.context.Context; import org.camunda.bpm.engine.impl.db.DbEntity; @@ -28,6 +32,7 @@ import org.camunda.bpm.engine.impl.db.entitymanager.OptimisticLockingResult; import org.camunda.bpm.engine.impl.db.entitymanager.operation.DbEntityOperation; import org.camunda.bpm.engine.impl.db.entitymanager.operation.DbOperation; +import org.camunda.bpm.engine.impl.dmn.batch.DeleteHistoricDecisionInstancesJobHandler; import org.camunda.bpm.engine.impl.interceptor.CommandContext; import org.camunda.bpm.engine.impl.jobexecutor.JobDeclaration; import org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity; @@ -169,6 +174,17 @@ protected void createJobEntities(BatchEntity batch, T configuration, String depl ByteArrayEntity configurationEntity = saveConfiguration(byteArrayManager, jobConfiguration); JobEntity job = createBatchJob(batch, configurationEntity); + + if (jobConfiguration.getIds() != null && jobConfiguration.getIds().size() == 1 + && !(this instanceof DecisionSetRemovalTimeJobHandler) + && !(this instanceof DeleteHistoricDecisionInstancesJobHandler) + && !(this instanceof SetJobRetriesJobHandler) + && !(this instanceof SetExternalTaskRetriesJobHandler) +// && !(this instanceof BatchSetRemovalTimeJobHandler) + ) { + job.setProcessInstanceId(jobConfiguration.getIds().get(0)); + } + job.setDeploymentId(deploymentId); postProcessJob(configuration, job, jobConfiguration); jobManager.insertAndHintJobExecutor(job); diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/message/MessageCorrelationBatchJobHandler.java b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/message/MessageCorrelationBatchJobHandler.java index 32491d830b4..83511fcc23d 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/message/MessageCorrelationBatchJobHandler.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/message/MessageCorrelationBatchJobHandler.java @@ -66,10 +66,7 @@ protected MessageCorrelationBatchConfiguration createJobConfiguration(MessageCor @Override protected void postProcessJob(MessageCorrelationBatchConfiguration configuration, JobEntity job, MessageCorrelationBatchConfiguration jobConfiguration) { - // if there is only one process instance to adjust, set its ID to the job so exclusive scheduling is possible - if (jobConfiguration.getIds() != null && jobConfiguration.getIds().size() == 1) { - job.setProcessInstanceId(jobConfiguration.getIds().get(0)); - } + } @Override diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/variables/BatchSetVariablesHandler.java b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/variables/BatchSetVariablesHandler.java index e7e5fb85a58..193978d981e 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/variables/BatchSetVariablesHandler.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/variables/BatchSetVariablesHandler.java @@ -78,10 +78,7 @@ public String getType() { @Override protected void postProcessJob(BatchConfiguration configuration, JobEntity job, BatchConfiguration jobConfiguration) { - // if there is only one process instance to adjust, set its ID to the job so exclusive scheduling is possible - if (jobConfiguration.getIds() != null && jobConfiguration.getIds().size() == 1) { - job.setProcessInstanceId(jobConfiguration.getIds().get(0)); - } + } protected ByteArrayEntity findByteArrayById(String byteArrayId, CommandContext commandContext) { diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/history/producer/DefaultHistoryEventProducer.java b/engine/src/main/java/org/camunda/bpm/engine/impl/history/producer/DefaultHistoryEventProducer.java index 25b41dbf4a3..6247a05983e 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/history/producer/DefaultHistoryEventProducer.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/history/producer/DefaultHistoryEventProducer.java @@ -547,6 +547,7 @@ protected HistoricBatchEntity loadBatchEntity(BatchEntity batch) { // Implementation //////////////////////////////// + @Override public HistoryEvent createProcessInstanceStartEvt(DelegateExecution execution) { final ExecutionEntity executionEntity = (ExecutionEntity) execution; @@ -583,6 +584,7 @@ public HistoryEvent createProcessInstanceStartEvt(DelegateExecution execution) { return evt; } + @Override public HistoryEvent createProcessInstanceUpdateEvt(DelegateExecution execution) { final ExecutionEntity executionEntity = (ExecutionEntity) execution; @@ -620,6 +622,7 @@ public HistoryEvent createProcessInstanceMigrateEvt(DelegateExecution execution) return evt; } + @Override public HistoryEvent createProcessInstanceEndEvt(DelegateExecution execution) { final ExecutionEntity executionEntity = (ExecutionEntity) execution; @@ -690,6 +693,7 @@ protected void determineEndState(ExecutionEntity executionEntity, HistoricProces } } + @Override public HistoryEvent createActivityInstanceStartEvt(DelegateExecution execution) { final ExecutionEntity executionEntity = (ExecutionEntity) execution; @@ -744,6 +748,7 @@ public HistoryEvent createActivityInstanceMigrateEvt(MigratingActivityInstance a } + @Override public HistoryEvent createActivityInstanceEndEvt(DelegateExecution execution) { final ExecutionEntity executionEntity = (ExecutionEntity) execution; @@ -762,6 +767,7 @@ public HistoryEvent createActivityInstanceEndEvt(DelegateExecution execution) { return evt; } + @Override public HistoryEvent createTaskInstanceCreateEvt(DelegateTask task) { // create event instance @@ -775,6 +781,7 @@ public HistoryEvent createTaskInstanceCreateEvt(DelegateTask task) { return evt; } + @Override public HistoryEvent createTaskInstanceUpdateEvt(DelegateTask task) { // create event instance @@ -797,6 +804,7 @@ public HistoryEvent createTaskInstanceMigrateEvt(DelegateTask task) { return evt; } + @Override public HistoryEvent createTaskInstanceCompleteEvt(DelegateTask task, String deleteReason) { // create event instance @@ -819,6 +827,7 @@ public HistoryEvent createTaskInstanceCompleteEvt(DelegateTask task, String dele // User Operation Logs /////////////////////////// + @Override public List createUserOperationLogEvents(UserOperationLogContext context) { List historyEvents = new ArrayList(); @@ -840,14 +849,17 @@ public List createUserOperationLogEvents(UserOperationLogContext c // variables ///////////////////////////////// + @Override public HistoryEvent createHistoricVariableCreateEvt(VariableInstanceEntity variableInstance, VariableScope sourceVariableScope) { return createHistoricVariableEvent(variableInstance, sourceVariableScope, HistoryEventTypes.VARIABLE_INSTANCE_CREATE); } + @Override public HistoryEvent createHistoricVariableDeleteEvt(VariableInstanceEntity variableInstance, VariableScope sourceVariableScope) { return createHistoricVariableEvent(variableInstance, sourceVariableScope, HistoryEventTypes.VARIABLE_INSTANCE_DELETE); } + @Override public HistoryEvent createHistoricVariableUpdateEvt(VariableInstanceEntity variableInstance, VariableScope sourceVariableScope) { return createHistoricVariableEvent(variableInstance, sourceVariableScope, HistoryEventTypes.VARIABLE_INSTANCE_UPDATE); } @@ -859,6 +871,7 @@ public HistoryEvent createHistoricVariableMigrateEvt(VariableInstanceEntity vari // form Properties /////////////////////////// + @Override public HistoryEvent createFormPropertyUpdateEvt(ExecutionEntity execution, String propertyId, String propertyValue, String taskId) { final IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator(); @@ -903,22 +916,27 @@ public HistoryEvent createFormPropertyUpdateEvt(ExecutionEntity execution, Strin // Incidents ////////////////////////////////// + @Override public HistoryEvent createHistoricIncidentCreateEvt(Incident incident) { return createHistoricIncidentEvt(incident, HistoryEventTypes.INCIDENT_CREATE); } + @Override public HistoryEvent createHistoricIncidentUpdateEvt(Incident incident) { return createHistoricIncidentEvt(incident, HistoryEventTypes.INCIDENT_UPDATE); } + @Override public HistoryEvent createHistoricIncidentResolveEvt(Incident incident) { return createHistoricIncidentEvt(incident, HistoryEventTypes.INCIDENT_RESOLVE); } + @Override public HistoryEvent createHistoricIncidentDeleteEvt(Incident incident) { return createHistoricIncidentEvt(incident, HistoryEventTypes.INCIDENT_DELETE); } + @Override public HistoryEvent createHistoricIncidentMigrateEvt(Incident incident) { return createHistoricIncidentEvt(incident, HistoryEventTypes.INCIDENT_MIGRATE); } @@ -1078,10 +1096,12 @@ protected HistoryEvent createBatchEvent(BatchEntity batch, HistoryEventTypes eve // Job Log + @Override public HistoryEvent createHistoricJobLogCreateEvt(Job job) { return createHistoricJobLogEvt(job, HistoryEventTypes.JOB_CREATE); } + @Override public HistoryEvent createHistoricJobLogFailedEvt(Job job, Throwable exception) { HistoricJobLogEventEntity event = (HistoricJobLogEventEntity) createHistoricJobLogEvt(job, HistoryEventTypes.JOB_FAIL); @@ -1104,10 +1124,12 @@ public HistoryEvent createHistoricJobLogFailedEvt(Job job, Throwable exception) return event; } + @Override public HistoryEvent createHistoricJobLogSuccessfulEvt(Job job) { return createHistoricJobLogEvt(job, HistoryEventTypes.JOB_SUCCESS); } + @Override public HistoryEvent createHistoricJobLogDeleteEvt(Job job) { return createHistoricJobLogEvt(job, HistoryEventTypes.JOB_DELETE); } @@ -1124,6 +1146,8 @@ protected void initHistoricJobLogEvent(HistoricJobLogEventEntity evt, Job job, H JobEntity jobEntity = (JobEntity) job; evt.setJobId(jobEntity.getId()); + + System.out.println("In history id: "+ jobEntity.getId()); evt.setJobDueDate(jobEntity.getDuedate()); evt.setJobRetries(jobEntity.getRetries()); evt.setJobPriority(jobEntity.getPriority()); @@ -1169,6 +1193,7 @@ protected void initHistoricJobLogEvent(HistoricJobLogEventEntity evt, Job job, H evt.setFailedActivityId(jobEntity.getFailedActivityId()); evt.setExecutionId(jobEntity.getExecutionId()); evt.setProcessInstanceId(jobEntity.getProcessInstanceId()); + System.out.println("In history: "+ jobEntity.getProcessInstanceId()); evt.setProcessDefinitionId(jobEntity.getProcessDefinitionId()); evt.setProcessDefinitionKey(jobEntity.getProcessDefinitionKey()); evt.setDeploymentId(jobEntity.getDeploymentId()); diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/persistence/entity/JobEntity.java b/engine/src/main/java/org/camunda/bpm/engine/impl/persistence/entity/JobEntity.java index 922463aefaa..512488836b8 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/persistence/entity/JobEntity.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/persistence/entity/JobEntity.java @@ -231,6 +231,7 @@ public Object getPersistentState() { persistentState.put("exceptionMessage", exceptionMessage); persistentState.put("suspensionState", suspensionState); persistentState.put("processDefinitionId", processDefinitionId); +// persistentState.put("processInstanceId", processInstanceId); persistentState.put("jobDefinitionId", jobDefinitionId); persistentState.put("deploymentId", deploymentId); persistentState.put("jobHandlerConfiguration", jobHandlerConfiguration); diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/history/BatchHistoricDecisionInstanceDeletionTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/history/BatchHistoricDecisionInstanceDeletionTest.java index 14c9a8aca2c..89b2cb24dde 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/history/BatchHistoricDecisionInstanceDeletionTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/history/BatchHistoricDecisionInstanceDeletionTest.java @@ -48,7 +48,6 @@ import org.camunda.bpm.engine.test.ProcessEngineRule; import org.camunda.bpm.engine.test.RequiredHistoryLevel; import org.camunda.bpm.engine.test.api.runtime.BatchHelper; -import org.camunda.bpm.engine.test.util.AssertUtil; import org.camunda.bpm.engine.test.util.ProcessEngineTestRule; import org.camunda.bpm.engine.test.util.ProvidedProcessEngineRule; import org.camunda.bpm.engine.variable.VariableMap; @@ -666,6 +665,7 @@ public BatchDeletionHelper(ProcessEngineRule engineRule) { super(engineRule); } + @Override public JobDefinition getExecutionJobDefinition(Batch batch) { return engineRule.getManagementService().createJobDefinitionQuery() .jobDefinitionId(batch.getBatchJobDefinitionId()) diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/history/HistoryServiceAsyncOperationsTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/history/HistoryServiceAsyncOperationsTest.java index 30ba61fcc5b..3455c273c75 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/history/HistoryServiceAsyncOperationsTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/history/HistoryServiceAsyncOperationsTest.java @@ -16,6 +16,8 @@ */ package org.camunda.bpm.engine.test.api.history; +import static org.assertj.core.api.Assertions.assertThat; + import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.CoreMatchers.not; @@ -109,6 +111,21 @@ public void testDeleteHistoryProcessInstancesAsyncWithList() throws Exception { assertAllHistoricProcessInstancesAreDeleted(); } + @Test + public void testDeleteHistoryProcessInstances_shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations() { + //when + Batch batch = historyService.deleteHistoricProcessInstancesAsync(historicProcessInstances, TEST_REASON); + + completeSeedJobs(batch); + List executionJobs = managementService.createJobQuery().jobDefinitionId(batch.getBatchJobDefinitionId()).list(); + + // then + //Making sure that processInstanceId is set in execution jobs #4205 + assertThat(executionJobs) + .extracting("processInstanceId") + .containsExactlyInAnyOrder(historicProcessInstances.toArray()); + } + @Test public void testDeleteHistoryProcessInstancesAsyncWithListForDeletedDeployment() throws Exception { // given a second deployment diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/history/removaltime/batch/BatchSetRemovalTimeTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/history/removaltime/batch/BatchSetRemovalTimeTest.java index b66c814280b..5d166744697 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/history/removaltime/batch/BatchSetRemovalTimeTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/history/removaltime/batch/BatchSetRemovalTimeTest.java @@ -420,6 +420,34 @@ public void shouldSetRemovalTimeForBatch_MultipleInvocationsPerBatchJob() { assertThat(historicBatches.get(1).getRemovalTime()).isEqualTo(REMOVAL_TIME); } + @Test + public void testRemovalTimeProcess_shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations() { + // given + testRule.getProcessEngineConfiguration().setInvocationsPerBatchJob(1); + + String processInstanceIdOne = testRule.process().userTask().deploy().start(); + String processInstanceIdTwo = testRule.process().userTask().deploy().start(); + + // when + HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery(); + Batch batch = historyService.setRemovalTimeToHistoricProcessInstances() + .absoluteRemovalTime(REMOVAL_TIME) + .byQuery(query) + .executeAsync(); + + testRule.executeSeedJobs(batch); + + // then + //Making sure that processInstanceId is set in execution jobs #4205 + List executionJobs = testRule.getExecutionJobs(batch); + assertThat(executionJobs) + .extracting("processInstanceId") + .containsExactlyInAnyOrder(processInstanceIdOne, processInstanceIdTwo); + + // clear + managementService.deleteBatch(batch.getId(), true); + } + @Test public void shouldSetRemovalTime_SingleInvocationPerBatchJob() { // given @@ -2835,6 +2863,7 @@ public void shouldSetExecutionStartTimeInBatchAndHistoryForDecisions() { .putValue("temperature", 32) .putValue("dayType", "Weekend") ).evaluate(); + Batch batch = historyService.setRemovalTimeToHistoricDecisionInstances() .absoluteRemovalTime(CURRENT_DATE) .byQuery(historyService.createHistoricDecisionInstanceQuery()) diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/CorrelateAllMessageBatchTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/CorrelateAllMessageBatchTest.java index f33a254de9c..d6697110b99 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/CorrelateAllMessageBatchTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/CorrelateAllMessageBatchTest.java @@ -580,6 +580,7 @@ public void shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations() { rule.executeSeedJobs(batch); // then + //Making sure that processInstanceId is set in execution jobs #4205 List executionJobs = rule.getExecutionJobs(batch); assertThat(executionJobs) .extracting("processInstanceId") diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/ModificationExecutionAsyncTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/ModificationExecutionAsyncTest.java index 702ff0bbd03..8ddb91e18c0 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/ModificationExecutionAsyncTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/ModificationExecutionAsyncTest.java @@ -167,6 +167,13 @@ public void createBatchModification() { Batch batch = runtimeService.createModification(processDefinition.getId()).startAfterActivity("user2").processInstanceIds(processInstanceIds).executeAsync(); assertBatchCreated(batch, 2); + + //Making sure that processInstanceId is set in execution jobs #4205 + helper.executeSeedJob(batch); + List executionJobs = helper.getExecutionJobs(batch); + assertThat(executionJobs) + .extracting("processInstanceId") + .containsExactlyInAnyOrder(processInstanceIds.toArray()); } @Test @@ -312,7 +319,7 @@ public void createModificationJobs() { assertEquals(currentTime, modificationJob.getDuedate()); assertNull(modificationJob.getProcessDefinitionId()); assertNull(modificationJob.getProcessDefinitionKey()); - assertNull(modificationJob.getProcessInstanceId()); +// assertNull(modificationJob.getProcessInstanceId()); assertNull(modificationJob.getExecutionId()); } diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/RestartProcessInstanceAsyncTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/RestartProcessInstanceAsyncTest.java index 48c5e7100ae..5a7d374eb49 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/RestartProcessInstanceAsyncTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/RestartProcessInstanceAsyncTest.java @@ -42,6 +42,7 @@ import org.camunda.bpm.engine.batch.Batch; import org.camunda.bpm.engine.batch.history.HistoricBatch; import org.camunda.bpm.engine.delegate.ExecutionListener; +import org.camunda.bpm.engine.history.HistoricJobLog; import org.camunda.bpm.engine.history.HistoricProcessInstanceQuery; import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; import org.camunda.bpm.engine.impl.cfg.multitenancy.TenantIdProvider; @@ -1150,6 +1151,35 @@ public void shouldSetExecutionStartTimeInBatchAndHistory() { Assertions.assertThat(historicBatch.getExecutionStartTime()).isEqualToIgnoringMillis(TEST_DATE); } + @Test + public void shouldSetProcessInstanceAndDefinitionIdInHistoryJobLog() { + // given + + ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); + ProcessInstance processInstance = runtimeService.createProcessInstanceById(processDefinition.getId()) + .startBeforeActivity("userTask1") + .execute(); + runtimeService.deleteProcessInstance(processInstance.getId(), "test"); + Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()) + .startAfterActivity("userTask2") + .processInstanceIds(processInstance.getId()) + .executeAsync(); + helper.executeSeedJob(batch); + + Job executionJob = helper.getExecutionJobs(batch).get(0); + assertEquals(processInstance.getProcessDefinitionId(), executionJob.getProcessDefinitionId()); + assertEquals(processInstance.getRootProcessInstanceId(), executionJob.getProcessInstanceId()); + + // when + helper.executeJob(executionJob); + + // then + HistoricJobLog jobLog = historyService.createHistoricJobLogQuery().jobDefinitionType(Batch.TYPE_PROCESS_INSTANCE_RESTART).list().get(0); + + assertEquals(processInstance.getProcessDefinitionId(), jobLog.getProcessDefinitionId()); + assertEquals(processInstance.getRootProcessInstanceId(), jobLog.getProcessInstanceId()); + } + protected void assertBatchCreated(Batch batch, int processInstanceCount) { assertNotNull(batch); assertNotNull(batch.getId()); diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/RuntimeServiceAsyncOperationsTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/RuntimeServiceAsyncOperationsTest.java index fc8d6e5dbe1..e1a05f3fe2a 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/RuntimeServiceAsyncOperationsTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/RuntimeServiceAsyncOperationsTest.java @@ -93,6 +93,27 @@ public void testDeleteProcessInstancesAsyncWithList() throws Exception { assertProcessInstancesAreDeleted(); } + @Deployment(resources = { + "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) + @Test + public void testDeleteProcessInstances_shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations() { + // given + List processIds = startTestProcesses(2); + + // when + Batch batch = runtimeService.deleteProcessInstancesAsync(processIds, null, TESTING_INSTANCE_DELETE); + completeSeedJobs(batch); + + List executionJobs = managementService.createJobQuery().jobDefinitionId(batch.getBatchJobDefinitionId()).list(); + + // then + //Making sure that processInstanceId is set in execution jobs #4205 + assertThat(executionJobs) + .extracting("processInstanceId") + .containsExactlyInAnyOrder(processIds.toArray()); + } + + @Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) @Test diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/SetVariablesBatchTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/SetVariablesBatchTest.java index 2df88f1eacc..65781ceb227 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/SetVariablesBatchTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/SetVariablesBatchTest.java @@ -40,7 +40,6 @@ import org.camunda.bpm.engine.history.HistoricProcessInstanceQuery; import org.camunda.bpm.engine.history.UserOperationLogEntry; import org.camunda.bpm.engine.impl.util.ClockUtil; -import org.camunda.bpm.engine.management.JobDefinition; import org.camunda.bpm.engine.repository.Deployment; import org.camunda.bpm.engine.runtime.Job; import org.camunda.bpm.engine.runtime.ProcessInstanceQuery; @@ -685,6 +684,7 @@ public void shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations() { rule.executeSeedJobs(batch); // then + //Making sure that processInstanceId is set in execution jobs #4205 List executionJobs = rule.getExecutionJobs(batch); assertThat(executionJobs) .extracting("processInstanceId") diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/UpdateProcessInstancesSuspendStateAsyncTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/UpdateProcessInstancesSuspendStateAsyncTest.java index 7a9700ec3a9..966d3c1b1cc 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/UpdateProcessInstancesSuspendStateAsyncTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/UpdateProcessInstancesSuspendStateAsyncTest.java @@ -194,9 +194,20 @@ public void testBatchActivationById() { // when Batch suspendprocess = runtimeService.updateProcessInstanceSuspensionState().byProcessInstanceIds(Arrays.asList(processInstance1.getId(), processInstance2.getId())).suspendAsync(); helper.completeSeedJobs(suspendprocess); + + //Making sure that processInstanceId is set in execution jobs #4205 + assertThat(helper.getExecutionJobs(suspendprocess)) + .extracting("processInstanceId") + .containsExactlyInAnyOrder(processInstance1.getId(), processInstance2.getId()); + helper.executeJobs(suspendprocess); Batch activateprocess = runtimeService.updateProcessInstanceSuspensionState().byProcessInstanceIds(Arrays.asList(processInstance1.getId(), processInstance2.getId())).activateAsync(); helper.completeSeedJobs(activateprocess); + + //Making sure that processInstanceId is set in execution jobs #4205 + assertThat(helper.getExecutionJobs(activateprocess)) + .extracting("processInstanceId") + .containsExactlyInAnyOrder(processInstance1.getId(), processInstance2.getId()); helper.executeJobs(activateprocess); diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/migration/batch/BatchMigrationTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/migration/batch/BatchMigrationTest.java index 96a4cad1756..91e7ae3a93c 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/migration/batch/BatchMigrationTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/migration/batch/BatchMigrationTest.java @@ -943,6 +943,41 @@ public void shouldSetExecutionStartTimeInBatchAndHistory() { Assertions.assertThat(historicBatch.getExecutionStartTime()).isEqualToIgnoringMillis(TEST_DATE); } + @Test + public void shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations() { + RuntimeService runtimeService = engineRule.getRuntimeService(); + int processInstanceCount = 2; + + ProcessDefinition sourceProcessDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); + ProcessDefinition targetProcessDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); + + List processInstanceIds = new ArrayList<>(); + for (int i = 0; i < processInstanceCount; i++) { + processInstanceIds.add( + runtimeService.startProcessInstanceById(sourceProcessDefinition.getId()).getId() + ); + } + + MigrationPlan migrationPlan = engineRule.getRuntimeService() + .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) + .mapEqualActivities() + .build(); + + // when + Batch batch = runtimeService.newMigration(migrationPlan) + .processInstanceIds(processInstanceIds) + .executeAsync(); + + helper.executeSeedJob(batch); + List executionJobs = helper.getExecutionJobs(batch); + + // then + //Making sure that processInstanceId is set in execution jobs #4205 + assertThat(executionJobs) + .extracting("processInstanceId") + .containsExactlyInAnyOrder(processInstanceIds.toArray()); + } + protected void assertBatchCreated(Batch batch, int processInstanceCount) { assertNotNull(batch); assertNotNull(batch.getId());