Skip to content

Commit f2e6fc2

Browse files
Simplified test and fixed review comments
1 parent 65ae95e commit f2e6fc2

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
@@ -24,7 +24,7 @@ public class EndToEndTests {
2424
private static final String hostHealthPingPath = "/admin/host/ping";
2525
private static final String startOrchestrationPath = "/api/StartOrchestration";
2626
private static final String approvalWorkFlow = "/api/ApprovalWorkflowOrchestration";
27-
private static JsonPath rewindTestJsonPath = null;
27+
private static final String rewindInstance = "/api/RewindInstance";
2828

2929
@Order(1)
3030
@Test
@@ -209,28 +209,29 @@ private boolean pollingCheck(String statusQueryGetUri,
209209

210210
@Order(2)
211211
@Test
212-
public void approvalWorkFlow() throws InterruptedException {
212+
public void testRewindInstanceAPI() throws InterruptedException {
213213
Response response = post(approvalWorkFlow);
214-
rewindTestJsonPath = response.jsonPath();
214+
JsonPath rewindTestJsonPath = response.jsonPath();
215+
216+
// Wait for the ApprovalWorkflowOrchestration to fail
215217
Thread.sleep(3000);
218+
219+
String instanceId = rewindTestJsonPath.get("id");
216220
String statusQueryGetUri = rewindTestJsonPath.get("statusQueryGetUri");
217221
Response statusResponse = get(statusQueryGetUri);
218222
String runTimeStatus = statusResponse.jsonPath().get("runtimeStatus");
219223
assertEquals("Failed", runTimeStatus);
220-
}
221224

222-
@Order(3)
223-
@Test
224-
public void rewindInstance() throws InterruptedException {
225-
String rewindPostUri = rewindTestJsonPath.get("rewindPostUri");
226-
Response response = post(rewindPostUri);
225+
// Rewind the instance
226+
String rewindPostUri = rewindInstance + "?instanceId=" + instanceId;
227+
response = post(rewindPostUri);
228+
assertEquals("Failed orchestration instance is scheduled for rewind.", response.toString());
227229

230+
// Wait for orchestration to rewind and complete
228231
Thread.sleep(3000);
229232

230-
String statusQueryGetUri = rewindTestJsonPath.get("statusQueryGetUri");
231-
String runTimeStatus = null;
232233
for (int i = 0; i < 5; i++) {
233-
Response statusResponse = get(statusQueryGetUri);
234+
statusResponse = get(statusQueryGetUri);
234235
runTimeStatus = statusResponse.jsonPath().get("runtimeStatus");
235236
if (!"Completed".equals(runTimeStatus)) {
236237
Thread.sleep(1000);

0 commit comments

Comments
 (0)