Skip to content

Commit 54ec62d

Browse files
Simplified test and fixed review comments
1 parent 42d7d5a commit 54ec62d

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

samples-azure-functions/src/main/java/com/functions/RewindInstance.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public int requestPrimaryApproval(
6464
public int requestSecondaryApproval(
6565
@DurableActivityTrigger(name = "name") int number,
6666
final ExecutionContext context) throws InterruptedException {
67-
System.out.println("Test RequestSecondaryApproval " + approvalFlag);
6867
return number / approvalFlag++;
6968
}
7069

@@ -80,12 +79,7 @@ public String rewindInstance(
8079
String reason = "Orchestrator failed and needs to be revived.";
8180

8281
DurableTaskClient client = durableContext.getClient();
83-
84-
try {
85-
client.rewindInstance(instanceId, reason);
86-
return "Failed orchestration instance is revived.";
87-
}catch (Exception e){
88-
return "Exception when rewinding orchestration instance";
89-
}
82+
client.rewindInstance(instanceId, reason);
83+
return "Failed orchestration instance is scheduled for rewind.";
9084
}
9185
}

samples-azure-functions/src/test/java/com/functions/EndToEndTests.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class EndToEndTests {
1515
private static final String hostHealthPingPath = "/admin/host/ping";
1616
private static final String startOrchestrationPath = "/api/StartOrchestration";
1717
private static final String approvalWorkFlow = "/api/ApprovalWorkflowOrchestration";
18-
private static JsonPath rewindTestJsonPath = null;
18+
private static final String rewindInstance = "/api/RewindInstance";
1919

2020
@Order(1)
2121
@Test
@@ -41,28 +41,29 @@ public void basicChain() throws InterruptedException {
4141

4242
@Order(2)
4343
@Test
44-
public void approvalWorkFlow() throws InterruptedException {
44+
public void testRewindInstanceAPI() throws InterruptedException {
4545
Response response = post(approvalWorkFlow);
46-
rewindTestJsonPath = response.jsonPath();
46+
JsonPath rewindTestJsonPath = response.jsonPath();
47+
48+
// Wait for the ApprovalWorkflowOrchestration to fail
4749
Thread.sleep(3000);
50+
51+
String instanceId = rewindTestJsonPath.get("id");
4852
String statusQueryGetUri = rewindTestJsonPath.get("statusQueryGetUri");
4953
Response statusResponse = get(statusQueryGetUri);
5054
String runTimeStatus = statusResponse.jsonPath().get("runtimeStatus");
5155
assertEquals("Failed", runTimeStatus);
52-
}
5356

54-
@Order(3)
55-
@Test
56-
public void rewindInstance() throws InterruptedException {
57-
String rewindPostUri = rewindTestJsonPath.get("rewindPostUri");
58-
Response response = post(rewindPostUri);
57+
// Rewind the instance
58+
String rewindPostUri = rewindInstance + "?instanceId=" + instanceId;
59+
response = post(rewindPostUri);
60+
assertEquals("Failed orchestration instance is scheduled for rewind.", response.toString());
5961

62+
// Wait for orchestration to rewind and complete
6063
Thread.sleep(3000);
6164

62-
String statusQueryGetUri = rewindTestJsonPath.get("statusQueryGetUri");
63-
String runTimeStatus = null;
6465
for (int i = 0; i < 5; i++) {
65-
Response statusResponse = get(statusQueryGetUri);
66+
statusResponse = get(statusQueryGetUri);
6667
runTimeStatus = statusResponse.jsonPath().get("runtimeStatus");
6768
if (!"Completed".equals(runTimeStatus)) {
6869
Thread.sleep(1000);

0 commit comments

Comments
 (0)