SUNILathulya commented on code in PR #4330:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/4330#discussion_r3628063237
##########
jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/SLAComplianceTest.java:
##########
@@ -85,17 +89,17 @@ public void afterSLAViolated(SLAViolatedEvent event) {
boolean slaViolated = latch.await(10, TimeUnit.SECONDS);
assertThat(slaViolated).as("SLA was not violated while it is
expected").isTrue();
- processInstance =
kruntime.getProcessInstance(processInstance.getStringId());
-
assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
+ processInstance =
processDefinition.instances().findById(processInstance.id()).orElse(null);
+ assertThat(processInstance).isNotNull();
+
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
- int slaCompliance =
getSLAComplianceForProcessInstance(processInstance);
-
assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED);
+ int slaCompliance = executeInWorkflowState(processInstance, p ->
p.getSlaCompliance());
+
assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED);
-
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(),
null);
- assertProcessInstanceFinished(processInstance, kruntime);
+ ProcessTestHelper.completeWorkItem(processInstance,
Collections.emptyMap(), "john");
+
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
- slaCompliance = getSLAComplianceForProcessInstance(processInstance);
-
assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED);
+
assertThat(processSlaCompliance.get()).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED);
Review Comment:
@martinweiler Thanks for review — the listener approach is necessary
specifically for asserting SLA compliance after the process completes.
In v9 with InMemoryProcessInstances, once a process reaches STATE_COMPLETED,
it is immediately removed from the instances store (via
MutableProcessInstances.remove()). At that point,
processDefinition.instances().findById(id) returns empty — the process instance
is no longer accessible.
The existing executeInWorkflowState(processInstance, p ->
p.getSlaCompliance()) on line 96 works because it is called while the process
is still ACTIVE (after SLA violation but before the work item is completed).
That's the same pattern as the old getSLAComplianceForProcessInstance() —
querying on a live instance.
However, for the assertion on line 102, we need the SLA compliance value
after completeWorkItem has been called (and the process has completed and been
removed from the store). The afterProcessCompleted listener fires while the
internal WorkflowProcessInstanceImpl still exists in memory — before the store
removes it — so it's the only reliable hook to capture the final SLA compliance
value post-completion.
Adapting getSLAComplianceForProcessInstance to the new style would face the
same limitation: it can only work on a live/active instance. For
post-completion assertions, the listener is the correct approach.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]