Skip to content

Commit f502d3a

Browse files
authored
Don't swallow replay workflow exceptions (#304)
Allow Worker.replayWorkflowExecution to throw an exception if the workflow history replay fails due to event mismatch.
1 parent 2bef04f commit f502d3a

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

temporal-sdk/src/main/java/io/temporal/worker/Worker.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -384,16 +384,12 @@ public String toString() {
384384
* @throws Exception if replay failed for any reason
385385
*/
386386
public void replayWorkflowExecution(WorkflowExecutionHistory history) throws Exception {
387-
try {
388-
workflowWorker.queryWorkflowExecution(
389-
history,
390-
WorkflowClient.QUERY_TYPE_REPLAY_ONLY,
391-
String.class,
392-
String.class,
393-
new Object[] {});
394-
} catch (Exception e) {
395-
396-
}
387+
workflowWorker.queryWorkflowExecution(
388+
history,
389+
WorkflowClient.QUERY_TYPE_REPLAY_ONLY,
390+
String.class,
391+
String.class,
392+
new Object[] {});
397393
}
398394

399395
/**

temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,6 +3575,18 @@ public String execute(String taskQueue) {
35753575
}
35763576
}
35773577

3578+
public static class AlteredTestChildWorkflowRetryWorkflow
3579+
extends TestChildWorkflowAsyncRetryWorkflow {
3580+
3581+
public AlteredTestChildWorkflowRetryWorkflow() {}
3582+
3583+
@Override
3584+
public String execute(String taskQueue) {
3585+
Workflow.sleep(Duration.ofMinutes(1));
3586+
return super.execute(taskQueue);
3587+
}
3588+
}
3589+
35783590
@ActivityInterface
35793591
public interface AngryChildActivity {
35803592

@@ -3659,6 +3671,15 @@ public void testChildWorkflowRetryReplay() throws Exception {
36593671
"testChildWorkflowRetryHistory.json", TestChildWorkflowRetryWorkflow.class);
36603672
}
36613673

3674+
/** Tests that WorkflowReplayer fails if replay does not match workflow run. */
3675+
@Test(expected = RuntimeException.class)
3676+
public void testAlteredWorkflowReplayFailure() throws Exception {
3677+
Assume.assumeFalse("skipping for docker tests", useExternalService);
3678+
3679+
WorkflowReplayer.replayWorkflowExecutionFromResource(
3680+
"testChildWorkflowRetryHistory.json", AlteredTestChildWorkflowRetryWorkflow.class);
3681+
}
3682+
36623683
public static class TestChildWorkflowExecutionPromiseHandler implements TestWorkflow1 {
36633684

36643685
private ITestNamedChild child;

temporal-sdk/src/test/resources/testAsyncActivityRetryHistory.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"input": {
1717
"payloads": [{
1818
"metadata": {
19-
"encoding": "anNvbg=="
19+
"encoding": "anNvbi9wbGFpbg=="
2020
},
2121
"data": "IldvcmtmbG93VGVzdC10ZXN0QXN5bmNBY3Rpdml0eVJldHJ5LTYxNzI0YTU2LTgyOTktNDJlYy1hOThkLWYxODAwMDBlODc4NCI="
2222
}]
@@ -25,9 +25,9 @@
2525
"workflowRunTimeout": "108000s",
2626
"workflowTaskTimeout": "5s",
2727
"initiator": "CONTINUE_AS_NEW_INITIATOR_WORKFLOW",
28-
"originalExecutionRunId": "825ddcc7-0511-46a2-83ab-462c7731a927",
28+
"originalExecutionRunId": "abdb8767-2b5c-4b1d-bda5-c40581f9eeb5",
2929
"identity": "unknown-mac",
30-
"firstExecutionRunId": "825ddcc7-0511-46a2-83ab-462c7731a927"
30+
"firstExecutionRunId": "abdb8767-2b5c-4b1d-bda5-c40581f9eeb5"
3131
}
3232
}, {
3333
"eventId": "2",
@@ -70,7 +70,7 @@
7070
"version": "-24",
7171
"taskId": "1051015",
7272
"activityTaskScheduledEventAttributes": {
73-
"activityId": "0",
73+
"activityId": "ec1557a9-20ec-3436-b765-f9f4e14fe8a8",
7474
"activityType": {
7575
"name": "HeartbeatAndThrowIO"
7676
},
@@ -187,12 +187,12 @@
187187
"activityType": {
188188
"name": "HeartbeatAndThrowIO"
189189
},
190-
"activityId": "0",
190+
"activityId": "ec1557a9-20ec-3436-b765-f9f4e14fe8a8",
191191
"retryState": "RETRY_STATE_TIMEOUT"
192192
}
193193
},
194194
"retryState": "RETRY_STATE_RETRY_POLICY_NOT_SET",
195195
"workflowTaskCompletedEventId": "10"
196196
}
197197
}]
198-
}
198+
}

temporal-sdk/src/test/resources/testChildWorkflowRetryHistory.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"input": {
1717
"payloads": [{
1818
"metadata": {
19-
"encoding": "anNvbg=="
19+
"encoding": "anNvbi9wbGFpbg=="
2020
},
2121
"data": "IldvcmtmbG93VGVzdC10ZXN0Q2hpbGRXb3JrZmxvd1JldHJ5LWM1YzU5OGNkLTA1ZDYtNDc5MC1iNDNlLWViZjE0OWFlZTY1YiI="
2222
}]
@@ -80,12 +80,12 @@
8080
"input": {
8181
"payloads": [{
8282
"metadata": {
83-
"encoding": "anNvbg=="
83+
"encoding": "anNvbi9wbGFpbg=="
8484
},
8585
"data": "IldvcmtmbG93VGVzdC10ZXN0Q2hpbGRXb3JrZmxvd1JldHJ5LWM1YzU5OGNkLTA1ZDYtNDc5MC1iNDNlLWViZjE0OWFlZTY1YiI="
8686
}, {
8787
"metadata": {
88-
"encoding": "anNvbg=="
88+
"encoding": "anNvbi9wbGFpbg=="
8989
},
9090
"data": "MA=="
9191
}]
@@ -246,4 +246,4 @@
246246
"workflowTaskCompletedEventId": "13"
247247
}
248248
}]
249-
}
249+
}

0 commit comments

Comments
 (0)