Skip to content

Commit cdefa97

Browse files
committed
addressed PR feedback
1 parent c3c5e45 commit cdefa97

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

client/src/main/java/com/microsoft/durabletask/DurableTaskClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ public void rewindInstance(String instanceId) {
311311
* <p>
312312
* This method can only be used on orchestration instances that are in a <code>Failed</code> state.
313313
* When rewound, the orchestration instance will restart from the point of failure as if the failure
314-
* never occurred.
314+
* never occurred. It rewinds the orchestration by replaying any
315+
* Failed Activities and Failed suborchestrations that themselves have Failed Activities
315316
*
316317
* @param instanceId the ID of the orchestration instance to rewind
317318
* @param reason the reason for rewinding the orchestration instance

client/src/test/java/com/microsoft/durabletask/IntegrationTests.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ void subOrchestrationWithFailedActivity() throws TimeoutException {
419419
final String childOrchestratorName = "ChildOrchestration";
420420
final String activityName = "FailingActivity";
421421
final String failureMessage = "Simulated activity failure in sub-orchestration";
422+
final String expectedOutput = "Success after rewind";
423+
final AtomicBoolean shouldFail = new AtomicBoolean(true);
422424

423425
DurableTaskGrpcWorker worker = this.createWorkerBuilder()
424426
.addOrchestrator(parentOrchestratorName, ctx -> {
@@ -430,20 +432,34 @@ void subOrchestrationWithFailedActivity() throws TimeoutException {
430432
ctx.complete(result);
431433
})
432434
.addActivity(activityName, ctx -> {
433-
throw new RuntimeException(failureMessage);
435+
if (shouldFail.compareAndSet(true, false)) {
436+
throw new RuntimeException(failureMessage);
437+
}
438+
return expectedOutput;
434439
})
435440
.buildAndStart();
436441

437442
DurableTaskClient client = this.createClientBuilder().build();
438443
try (worker; client) {
439444
String instanceId = client.scheduleNewOrchestrationInstance(parentOrchestratorName);
445+
446+
// Wait for the orchestration to fail due to the activity failure in the sub-orchestration
440447
OrchestrationMetadata instance = client.waitForInstanceCompletion(instanceId, defaultTimeout, true);
441448
assertNotNull(instance);
442449
assertEquals(OrchestrationRuntimeStatus.FAILED, instance.getRuntimeStatus());
443450

444451
FailureDetails details = instance.getFailureDetails();
445452
assertNotNull(details);
446453
assertTrue(details.getErrorMessage().contains(failureMessage));
454+
455+
// Rewind the failed orchestration
456+
client.rewindInstance(instanceId, "Rewinding sub-orchestration with failed activity");
457+
458+
// Wait for the orchestration to complete after rewind
459+
instance = client.waitForInstanceCompletion(instanceId, defaultTimeout, true);
460+
assertNotNull(instance);
461+
assertEquals(OrchestrationRuntimeStatus.COMPLETED, instance.getRuntimeStatus());
462+
assertEquals(expectedOutput, instance.readOutputAs(String.class));
447463
}
448464
}
449465

0 commit comments

Comments
 (0)