Skip to content

Commit 66cccf0

Browse files
committed
[Fix #1414] Gonzalos comments
1 parent df68b6f commit 66cccf0

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

impl/core/src/main/java/io/serverlessworkflow/impl/executors/TryExecutor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,15 @@ protected TryExecutorBuilder(
7171
this.errorFilter = buildErrorFilter(catchInfo.getErrors());
7272
this.whenFilter = WorkflowUtils.optionalPredicate(application, catchInfo.getWhen());
7373
this.exceptFilter = WorkflowUtils.optionalPredicate(application, catchInfo.getExceptWhen());
74-
this.taskExecutor =
75-
TaskExecutorHelper.createExecutorList(position, task.getTry(), definition, "try");
7674
TryTaskCatch catchTask = task.getCatch();
7775
if (catchTask != null) {
7876
this.errorVariable = catchTask.getAs();
7977
List<TaskItem> catchTaskDo = catchTask.getDo();
8078
this.catchTaskExecutor =
8179
catchTaskDo != null && !catchTaskDo.isEmpty()
8280
? Optional.of(
83-
TaskExecutorHelper.createExecutorList(position.copy(), catchTaskDo, definition))
81+
TaskExecutorHelper.createExecutorList(
82+
position.copy().addProperty("catch"), catchTaskDo, definition))
8483
: Optional.empty();
8584

8685
Retry retry = catchTask.getRetry();
@@ -89,6 +88,8 @@ protected TryExecutorBuilder(
8988
this.catchTaskExecutor = Optional.empty();
9089
this.retryIntervalExecutor = Optional.empty();
9190
}
91+
this.taskExecutor =
92+
TaskExecutorHelper.createExecutorList(position, task.getTry(), definition, "try");
9293
}
9394

9495
private Optional<RetryExecutor> buildRetryInterval(Retry retry) {

impl/test/src/test/java/io/serverlessworkflow/impl/test/RetryTimeoutTest.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2121

2222
import com.fasterxml.jackson.databind.JsonNode;
23-
import io.serverlessworkflow.api.types.TryTask;
23+
import io.serverlessworkflow.impl.TaskContextData;
2424
import io.serverlessworkflow.impl.WorkflowApplication;
2525
import io.serverlessworkflow.impl.WorkflowException;
2626
import io.serverlessworkflow.impl.WorkflowModel;
2727
import io.serverlessworkflow.impl.jackson.JsonUtils;
2828
import io.serverlessworkflow.impl.lifecycle.TaskCompletedEvent;
29+
import io.serverlessworkflow.impl.lifecycle.TaskEvent;
2930
import io.serverlessworkflow.impl.lifecycle.TaskRetriedEvent;
3031
import io.serverlessworkflow.impl.lifecycle.WorkflowExecutionListener;
3132
import java.io.IOException;
@@ -65,17 +66,21 @@ void tearDown() throws IOException {
6566
private class RetryListener implements WorkflowExecutionListener {
6667

6768
private Map<String, Short> taskRetried = new ConcurrentHashMap<>();
68-
private Map<String, Short> tryTaskCompleted = new ConcurrentHashMap<>();
69+
private Map<String, Short> taskCompleted = new ConcurrentHashMap<>();
6970

71+
@Override
7072
public void onTaskRetried(TaskRetriedEvent ev) {
71-
taskRetried.put(ev.taskContext().position().jsonPointer(), ev.taskContext().retryAttempt());
73+
add2Map(taskRetried, ev);
7274
}
7375

76+
@Override
7477
public void onTaskCompleted(TaskCompletedEvent ev) {
75-
if (ev.taskContext().task() instanceof TryTask) {
76-
tryTaskCompleted.put(
77-
ev.taskContext().position().jsonPointer(), ev.taskContext().retryAttempt());
78-
}
78+
add2Map(taskCompleted, ev);
79+
}
80+
81+
private static void add2Map(Map<String, Short> map, TaskEvent ev) {
82+
TaskContextData taskContext = ev.taskContext();
83+
map.put(taskContext.position().jsonPointer(), taskContext.retryAttempt());
7984
}
8085
}
8186

@@ -103,7 +108,6 @@ void testRetry(String path) throws IOException {
103108
.until(() -> future.join().as(JsonNode.class).orElseThrow().equals(result));
104109
assertThat(retryListener.taskRetried).hasSize(1);
105110
assertThat(retryListener.taskRetried.get("do/0/tryGetPet/try/0/getPet")).isEqualTo((short) 2);
106-
assertThat(retryListener.tryTaskCompleted.values()).containsOnly((short) 0);
107111
}
108112

109113
@Test
@@ -136,9 +140,9 @@ void testNestedRetry() throws IOException {
136140
retryListener.taskRetried.get(
137141
"do/0/tryServerError/try/0/tryCommunication/try/0/getPet"))
138142
.isEqualTo((short) 5);
139-
assertThat(retryListener.tryTaskCompleted.get("do/0/tryServerError/try/0/tryCommunication/try"))
143+
assertThat(retryListener.taskCompleted.get("do/0/tryServerError/try/0/tryCommunication/try"))
140144
.isEqualTo((short) 2);
141-
assertThat(retryListener.tryTaskCompleted.get("do/0/tryServerError/try")).isEqualTo((short) 0);
145+
assertThat(retryListener.taskCompleted.get("do/0/tryServerError/try")).isEqualTo((short) 0);
142146
}
143147

144148
@Test
@@ -158,7 +162,9 @@ void testRetryDo() throws IOException {
158162
.orElseThrow()
159163
.equals(Map.of("setAfterFailingTask", "No problem")));
160164

161-
assertThat(retryListener.tryTaskCompleted.get("do/0/attemptTask/try")).isEqualTo((short) 0);
165+
assertThat(retryListener.taskCompleted.get("do/0/attemptTask/try")).isEqualTo((short) 0);
166+
assertThat(retryListener.taskCompleted)
167+
.containsKey("do/0/attemptTask/catch/do/0/executeAfterFailingTask");
162168
}
163169

164170
@Test

0 commit comments

Comments
 (0)