Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBPM-10185] Test for handling sla timer for processes #2984

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="Definition"
targetNamespace="http://www.example.org/MinimalExample"
typeLanguage="http://www.java.com/javaTypes"
expressionLanguage="http://www.mvel.org/2.0"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
xmlns:tns="http://www.jboss.org/drools">

<itemDefinition id="_sItem" structureRef="String" />
<process processType="Private" isExecutable="true" id="definition-project.SLAOnProcess" name="SLA On Process" >
<extensionElements>
<tns:metaData name="customSLADueDate">
<tns:metaValue>1h</tns:metaValue>
</tns:metaData>
</extensionElements>
<property id="s" itemSubjectRef="_sItem"/>
<!-- nodes -->
<startEvent id="_1" name="StartProcess" />
<userTask id="_2" name="Hello" >
<ioSpecification>
<inputSet>
</inputSet>
<outputSet>
</outputSet>
</ioSpecification>
<potentialOwner>
<resourceAssignmentExpression>
<formalExpression>yoda</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
</userTask>
<endEvent id="_3" name="EndProcess" >
<terminateEventDefinition/>
</endEvent>

<!-- connections -->
<sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2" />
<sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />

</process>

<bpmndi:BPMNDiagram>
<bpmndi:BPMNPlane bpmnElement="UserTask" >
<bpmndi:BPMNShape bpmnElement="_1" >
<dc:Bounds x="16" y="16" width="48" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_2" >
<dc:Bounds x="96" y="16" width="100" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_3" >
<dc:Bounds x="228" y="16" width="48" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="_1-_2" >
<di:waypoint x="40" y="40" />
<di:waypoint x="146" y="40" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_2-_3" >
<di:waypoint x="146" y="40" />
<di:waypoint x="252" y="40" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>

</definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public abstract class JbpmKieServerBaseIntegrationTest extends RestJmsSharedBase
protected static final String PROCESS_ID_USERTASK_WITH_ROLLBACK = "UserTaskWithRollback";
protected static final String PROCESS_ID_USERTASK_DIFF_POTUSERS = "usertask-project.usertask-diff-potusers";
protected static final String PROCESS_ID_USERTASK_SECURED = "secured-project.usertask";
protected static final String PROCESS_ID_SLA_ON_PROCESS = "definition-project.SLAOnProcess";
protected static final String PROCESS_ID_SIGNAL_PROCESS_SECURED = "secured-project.signalprocess";
protected static final String PROCESS_ID_WORKITEM_SECURED = "secured-project.workitem";
protected static final String PROCESS_ID_NOTIFICATION = "notification";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
package org.kie.server.integrationtests.jbpm;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.kie.api.runtime.process.ProcessInstance.SLA_MET;
import static org.kie.api.runtime.process.ProcessInstance.SLA_NA;
import static org.kie.api.runtime.process.ProcessInstance.SLA_PENDING;
import static org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED;
import static org.kie.api.runtime.process.ProcessInstance.STATE_ABORTED;
import static org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE;
import static org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED;

Expand All @@ -36,6 +39,7 @@
import org.kie.server.api.KieServerConstants;
import org.kie.server.api.model.KieServerConfigItem;
import org.kie.server.api.model.ReleaseId;
import org.kie.server.api.model.admin.TimerInstance;
import org.kie.server.api.model.instance.NodeInstance;
import org.kie.server.api.model.instance.ProcessInstance;
import org.kie.server.api.model.instance.TaskSummary;
Expand Down Expand Up @@ -196,14 +200,43 @@ public void testSLAonUserTaskMet() throws Exception {
assertProcessInstance(pid, STATE_COMPLETED, SLA_NA);

}

@Test(timeout = 60 * 1000)
public void testUpdateSLAOnProcess() throws Exception {
Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_SLA_ON_PROCESS, new HashMap<>());
// SLA on 1 hour
assertProcessInstance(processInstanceId, STATE_ACTIVE, SLA_PENDING, 3630*1000);

List<TimerInstance> timers = processAdminClient.getTimerInstances(CONTAINER_ID, processInstanceId);
assertNotNull(timers);
assertEquals(1, timers.size());

TimerInstance timerInstance = timers.get(0);
assertNotNull(timerInstance);
assertEquals("[SLA-Process] SLA On Process", timerInstance.getTimerName());

processAdminClient.updateTimer(CONTAINER_ID, processInstanceId, timerInstance.getId(), 5, 0, 0);
assertProcessInstance(processInstanceId, STATE_ACTIVE, SLA_PENDING, -1);

// Let's wait for SLA violation
KieServerSynchronization.waitForProcessInstanceSLAViolated(queryClient, processInstanceId, 10_000L);
assertProcessInstance(processInstanceId, STATE_ACTIVE, SLA_VIOLATED, -1);

processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
assertProcessInstance(processInstanceId, STATE_ABORTED, SLA_VIOLATED);
}

private void assertProcessInstance(Long pid, int processState, int slaStatus) {
assertProcessInstance(pid, processState, slaStatus, 30000);
}

private void assertProcessInstance(Long pid, int processState, int slaStatus, long deltaTime) {
assertThat(pid).isNotNull();
ProcessInstance pi = queryClient.findProcessInstanceById(pid);
assertThat(pi.getState()).isEqualTo(processState);
assertThat(pi.getSlaCompliance()).isEqualTo(slaStatus);
if (slaStatus != SLA_NA) {
assertThat(pi.getSlaDueDate()).isCloseTo(new Date(), 30000);
if (slaStatus != SLA_NA && deltaTime > 0) {
assertThat(pi.getSlaDueDate()).isCloseTo(new Date(), deltaTime);
}
}

Expand Down
Loading