Skip to content

Commit

Permalink
Fix issue with other than Exception type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tijsrademakers committed Oct 3, 2023
1 parent 50e6865 commit 6c178cc
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public void close() {
try {
try {
try {
executeCloseListenersClosing();
if (exception == null) {
executeCloseListenersClosing();
flushSessions();
}
} catch (Throwable exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public <T> T execute(CommandConfig config, Command<T> command, CommandExecutor c

return next.execute(config, command, commandExecutor);

} catch (Exception e) {
} catch (Throwable e) {

commandContext.exception(e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.flowable.engine.test.api.v6;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.data.MapEntry.entry;

import java.util.Collections;
Expand All @@ -26,6 +27,7 @@
import org.flowable.engine.impl.test.PluggableFlowableTestCase;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ActivityInstance;
import org.flowable.engine.runtime.Execution;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.job.api.Job;
Expand Down Expand Up @@ -78,6 +80,33 @@ public void testOneTaskProcessCleanupInMiddleOfProcess() {
assertThat(task.getName()).isEqualTo("The famous task");
assertThat(task.getAssignee()).isEqualTo("kermit");
}

@Test
@org.flowable.engine.test.Deployment
public void testProcessWithError() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processWithError");
assertThat(processInstance).isNotNull();
assertThat(processInstance.isEnded()).isFalse();

org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertThat(task).isNotNull();

assertThatThrownBy(() -> taskService.complete(task.getId()))
.isInstanceOf(Throwable.class);

org.flowable.task.api.Task updatedTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertThat(updatedTask).isNotNull();

List<ActivityInstance> activityInstances = runtimeService.createActivityInstanceQuery().processInstanceId(processInstance.getId()).list();
ActivityInstance serviceTaskActivityInstance = null;
for (ActivityInstance activityInstance : activityInstances) {
if ("serviceTask".equals(activityInstance.getActivityId())) {
serviceTaskActivityInstance = activityInstance;
}
}

assertThat(serviceTaskActivityInstance).isNull();
}

@Test
@org.flowable.engine.test.Deployment
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.engine.test.api.v6;

import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;

public class ServiceTaskErrorTestDelegate implements JavaDelegate {

@Override
public void execute(DelegateExecution execution) {
throw new Error();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:flowable="http://flowable.org/bpmn"
targetNamespace="Examples">

<process id="processWithError">

<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="theTask" />

<userTask id="theTask" name="The famous task" />
<sequenceFlow id="flow2" sourceRef="theTask" targetRef="serviceTask" />

<serviceTask id="serviceTask" flowable:class="org.flowable.engine.test.api.v6.ServiceTaskErrorTestDelegate" />

<sequenceFlow id="flow3" sourceRef="serviceTask" targetRef="theEnd" />

<endEvent id="theEnd" />

</process>

</definitions>

0 comments on commit 6c178cc

Please sign in to comment.