Skip to content

Commit

Permalink
update docs and test for AsyncBefore, AsyncAfter or Compensation
Browse files Browse the repository at this point in the history
  • Loading branch information
venetrius committed Sep 20, 2024
1 parent 1f17efc commit 7fb55ec
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@
"activityIdIn": {
"type": "array",
"itemType": "string",
"desc": "Restrict to instances that have an active activity or failing activity with one of given ids. It works
similarly to the activityIdIn filter in the runtime query. ${listTypeDescription}"
"desc": "Restrict to instances that have an active activity or failing activity with one of given ids. It works
similarly to the activityIdIn filter in the runtime query. Difference is activities that follow
an asyncAfter activity or themselves are asyncBefore or boundary activities are not considered active until
the scheduler picked them up for execution. ${listTypeDescription}"
},

"executedActivityIdIn": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ public interface HistoricProcessInstanceQuery extends Query<HistoricProcessInsta
HistoricProcessInstanceQuery activeActivityIdIn(String... ids);

/**
* Only select historic process instances that have active activities or failing activities with given ids.
* Only select historic process instances that have active activities or failing activities with given ids.
* Activities that follow an asyncAfter activity or themselves are asyncBefore or boundary activities are not
* considered active until the scheduler picked them up for execution.
*/
HistoricProcessInstanceQuery activityIdIn(String... ids);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
Expand Down Expand Up @@ -1652,9 +1651,13 @@ public void testQueryByNonLeafActivityId() {
}

@Test
@Ignore
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
public void testQueryByAsyncBeforeActivityId() {
// For a historic instance when AsyncBefore is used the historic activity is only created when the execution is scheduled
// For process instances that have a token just before a AsyncBefore activity
// In the runtimeInstanceQuery activityIdIn filter returns instances that are not scheduled yet
// In historicInstanceQuery activityIdIn filter does not return instances that are not scheduled yet

// given
ProcessDefinition testProcess = testHelper.deployAndGetDefinition(ProcessModels.newModel()
.startEvent("start").camundaAsyncBefore()
Expand All @@ -1681,23 +1684,35 @@ public void testQueryByAsyncBeforeActivityId() {
executeJobForProcessInstance(instanceBeforeEnd);

// then
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().activityIdIn("start");
assertReturnedProcessInstances(query, instanceBeforeStart);
HistoricProcessInstanceQuery historicQuery = historyService.createHistoricProcessInstanceQuery().activityIdIn("start");
assertNull(historicQuery.singleResult());
ProcessInstanceQuery runtimeQuery = runtimeService.createProcessInstanceQuery().activityIdIn("start");
assertEquals(instanceBeforeStart.getId(), runtimeQuery.singleResult().getProcessInstanceId());

query = historyService.createHistoricProcessInstanceQuery().activityIdIn("subProcess");
assertReturnedProcessInstances(query, instanceBeforeSubProcess);
historicQuery = historyService.createHistoricProcessInstanceQuery().activityIdIn("subProcess");
assertReturnedProcessInstances(historicQuery, instanceBeforeTask);
runtimeQuery = runtimeService.createProcessInstanceQuery().activityIdIn("subProcess");
assertEquals(instanceBeforeSubProcess.getId(), runtimeQuery.singleResult().getProcessInstanceId());

query = historyService.createHistoricProcessInstanceQuery().activityIdIn("task");
assertReturnedProcessInstances(query, instanceBeforeTask);
historicQuery = historyService.createHistoricProcessInstanceQuery().activityIdIn("task");
assertNull(historicQuery.singleResult());
runtimeQuery = runtimeService.createProcessInstanceQuery().activityIdIn("task");
assertEquals(instanceBeforeTask.getId(), runtimeQuery.singleResult().getProcessInstanceId());

query = historyService.createHistoricProcessInstanceQuery().activityIdIn("end");
assertReturnedProcessInstances(query, instanceBeforeEnd);
historicQuery = historyService.createHistoricProcessInstanceQuery().activityIdIn("end");
assertNull(historicQuery.singleResult());
runtimeQuery = runtimeService.createProcessInstanceQuery().activityIdIn("end");
assertEquals(instanceBeforeEnd.getId(), runtimeQuery.singleResult().getProcessInstanceId());
}

@Test
@Ignore
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
public void testQueryByAsyncAfterActivityId() {
// For a historic activity the end time is set after it is executed => the activity is not considered active anymore,
// this is not changed if AsyncAfter is used
// if the task is a subprocess end time will only be set after the subprocess is terminated
// For the runtime query the execution is still visible if AsyncAfter is used (I assume we delete the execution when scheduling next activity)

// given
ProcessDefinition testProcess = testHelper.deployAndGetDefinition(ProcessModels.newModel()
.startEvent("start").camundaAsyncAfter()
Expand All @@ -1723,18 +1738,25 @@ public void testQueryByAsyncAfterActivityId() {
executeJobForProcessInstance(instanceAfterEnd);
executeJobForProcessInstance(instanceAfterEnd);

// then
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().activityIdIn("start");
assertReturnedProcessInstances(query, instanceAfterStart);
HistoricProcessInstanceQuery historicQuery = historyService.createHistoricProcessInstanceQuery().activityIdIn("start");
assertNull(historicQuery.singleResult());
ProcessInstanceQuery runtimeQuery = runtimeService.createProcessInstanceQuery().activityIdIn("start");
assertEquals(instanceAfterStart.getId(), runtimeQuery.singleResult().getProcessInstanceId());

query = historyService.createHistoricProcessInstanceQuery().activityIdIn("task");
assertReturnedProcessInstances(query, instanceAfterTask);
historicQuery = historyService.createHistoricProcessInstanceQuery().activityIdIn("task");
assertNull(historicQuery.singleResult());
runtimeQuery = runtimeService.createProcessInstanceQuery().activityIdIn("task");
assertEquals(instanceAfterTask.getId(), runtimeQuery.singleResult().getProcessInstanceId());

query = historyService.createHistoricProcessInstanceQuery().activityIdIn("subProcess");
assertReturnedProcessInstances(query, instanceAfterSubProcess);
historicQuery = historyService.createHistoricProcessInstanceQuery().activityIdIn("subProcess");
assertReturnedProcessInstances(historicQuery, instanceAfterTask);
runtimeQuery = runtimeService.createProcessInstanceQuery().activityIdIn("subProcess");
assertEquals(instanceAfterSubProcess.getId(), runtimeQuery.singleResult().getProcessInstanceId());

query = historyService.createHistoricProcessInstanceQuery().activityIdIn("end");
assertReturnedProcessInstances(query, instanceAfterEnd);
historicQuery = historyService.createHistoricProcessInstanceQuery().activityIdIn("end");
assertNull(historicQuery.singleResult());
runtimeQuery = runtimeService.createProcessInstanceQuery().activityIdIn("end");
assertEquals(instanceAfterEnd.getId(), runtimeQuery.singleResult().getProcessInstanceId());
}

@Test
Expand All @@ -1753,9 +1775,11 @@ public void testQueryByActivityIdBeforeCompensation() {
assertEquals(0, query.list().size()); }

@Test
@Ignore
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
public void testQueryByActivityIdDuringCompensation() {
// After completing user task we are expecting "subProcess", "compensationEvent", "compensationHandler" to have an activity
// Based on historic data only "compensationEvent", "compensationHandler" have active events

// given
ProcessDefinition testProcess = testHelper.deployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);

Expand All @@ -1765,14 +1789,20 @@ public void testQueryByActivityIdDuringCompensation() {
testHelper.completeTask("userTask2");

// then
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().activityIdIn("subProcess");
assertReturnedProcessInstances(query, processInstance);

query = historyService.createHistoricProcessInstanceQuery().activityIdIn("compensationEvent");
assertReturnedProcessInstances(query, processInstance);

query = historyService.createHistoricProcessInstanceQuery().activityIdIn("compensationHandler");
assertReturnedProcessInstances(query, processInstance);
HistoricProcessInstanceQuery historicQuery = historyService.createHistoricProcessInstanceQuery().activityIdIn("subProcess");
assertNull(historicQuery.singleResult());
ProcessInstanceQuery runtimeQuery = runtimeService.createProcessInstanceQuery().activityIdIn("subProcess");
assertEquals(processInstance.getId(), runtimeQuery.singleResult().getProcessInstanceId());

historicQuery = historyService.createHistoricProcessInstanceQuery().activityIdIn("compensationEvent");
assertReturnedProcessInstances(historicQuery, processInstance);
runtimeQuery = runtimeService.createProcessInstanceQuery().activityIdIn("compensationEvent");
assertEquals(processInstance.getId(), runtimeQuery.singleResult().getProcessInstanceId());

historicQuery = historyService.createHistoricProcessInstanceQuery().activityIdIn("compensationHandler");
assertReturnedProcessInstances(historicQuery, processInstance);
runtimeQuery = runtimeService.createProcessInstanceQuery().activityIdIn("compensationEvent");
assertEquals(processInstance.getId(), runtimeQuery.singleResult().getProcessInstanceId());
}

@Test
Expand Down

0 comments on commit 7fb55ec

Please sign in to comment.