Skip to content

Commit

Permalink
Added test for RewindInstanceHttpAPI and addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-gopalakrishna committed Mar 14, 2023
1 parent 54ec62d commit bc1954b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.functions;

import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
import com.microsoft.azure.functions.HttpRequestMessage;
import com.microsoft.azure.functions.HttpResponseMessage;
import com.microsoft.azure.functions.*;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.HttpTrigger;
Expand Down Expand Up @@ -82,4 +79,17 @@ public String rewindInstance(
client.rewindInstance(instanceId, reason);
return "Failed orchestration instance is scheduled for rewind.";
}

/**
* This HTTP-triggered function resets the approvalFlag variable for testing purposes.
*/
@FunctionName("ResetApproval")
public static HttpResponseMessage resetApproval(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
context.getLogger().info("ResetApproval function invoked.");
approvalFlag = 0;
return request.createResponseBuilder(HttpStatus.OK).body(approvalFlag).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,101 @@

@Tag("e2e")
public class EndToEndTests {
private static final String hostHealthPingPath = "/admin/host/ping";
private static final String startOrchestrationPath = "/api/StartOrchestration";
private static final String approvalWorkFlow = "/api/ApprovalWorkflowOrchestration";
private static final String rewindInstance = "/api/RewindInstance";
private static final String hostHealthPingUrl = "/admin/host/ping";
private static final String startOrchestrationUrl = "/api/StartOrchestration";
private static final String startApprovalWorkflowUrl = "/api/ApprovalWorkflowOrchestration";
private static final String rewindInstanceFunctionUrl = "/api/RewindInstance";
private static final String resetApprovalUrl = "/api/ResetApprovalFlag";

@Order(1)
@Test
public void setupHost() {
post(hostHealthPingPath).then().statusCode(200);
post(hostHealthPingUrl).then().statusCode(200);
}

@Test
public void basicChain() throws InterruptedException {
Response response = post(startOrchestrationPath);
JsonPath jsonPath = response.jsonPath();
String statusQueryGetUri = jsonPath.get("statusQueryGetUri");
String runTimeStatus = null;
Response response = post(startOrchestrationUrl);
JsonPath startOrchestrationResponseJson = response.jsonPath();
String statusQueryGetUri = startOrchestrationResponseJson.get("statusQueryGetUri");
String runtimeStatus = null;
for (int i = 0; i < 15; i++) {
Response statusResponse = get(statusQueryGetUri);
runTimeStatus = statusResponse.jsonPath().get("runtimeStatus");
if (!"Completed".equals(runTimeStatus)) {
runtimeStatus = statusResponse.jsonPath().get("runtimeStatus");
if (!"Completed".equals(runtimeStatus)) {
Thread.sleep(1000);
} else break;
}
assertEquals("Completed", runTimeStatus);
assertEquals("Completed", runtimeStatus);
}

@Order(2)
@Test
public void testRewindInstanceAPI() throws InterruptedException {
Response response = post(approvalWorkFlow);
JsonPath rewindTestJsonPath = response.jsonPath();
public void testRewindInstanceJavaAPI() throws InterruptedException {
Response response = post(startApprovalWorkflowUrl);
JsonPath startOrchestrationResponseJson = response.jsonPath();

// Wait for the ApprovalWorkflowOrchestration to fail
Thread.sleep(3000);

String instanceId = rewindTestJsonPath.get("id");
String statusQueryGetUri = rewindTestJsonPath.get("statusQueryGetUri");
String instanceId = startOrchestrationResponseJson.get("id");
String statusQueryGetUri = startOrchestrationResponseJson.get("statusQueryGetUri");
Response statusResponse = get(statusQueryGetUri);
String runTimeStatus = statusResponse.jsonPath().get("runtimeStatus");
assertEquals("Failed", runTimeStatus);
String runtimeStatus = statusResponse.jsonPath().get("runtimeStatus");
assertEquals("Failed", runtimeStatus);

// Rewind the instance
String rewindPostUri = rewindInstance + "?instanceId=" + instanceId;
response = post(rewindPostUri);
// Rewind the instance using Java API
String rewindInstanceUrl = rewindInstanceFunctionUrl + "?instanceId=" + instanceId;
response = post(rewindInstanceUrl);
assertEquals("Failed orchestration instance is scheduled for rewind.", response.toString());

// Wait for orchestration to rewind and complete
Thread.sleep(3000);

for (int i = 0; i < 5; i++) {
statusResponse = get(statusQueryGetUri);
runTimeStatus = statusResponse.jsonPath().get("runtimeStatus");
if (!"Completed".equals(runTimeStatus)) {
runtimeStatus = statusResponse.jsonPath().get("runtimeStatus");
if (!"Completed".equals(runtimeStatus)) {
Thread.sleep(1000);
} else break;
}
assertEquals("Completed", runTimeStatus);
assertEquals("Completed", runtimeStatus);

// Reset approval for other test cases
post(resetApprovalUrl);
}

@Order(3)
@Test
public void testRewindInstanceHttpAPI() throws InterruptedException {
Response response = post(startApprovalWorkflowUrl);
JsonPath startOrchestrationResponseJson = response.jsonPath();

// Wait for the ApprovalWorkflowOrchestration to fail
Thread.sleep(3000);

String statusQueryGetUri = startOrchestrationResponseJson.get("statusQueryGetUri");
Response statusResponse = get(statusQueryGetUri);
String runtimeStatus = statusResponse.jsonPath().get("runtimeStatus");
assertEquals("Failed", runtimeStatus);

// Rewind the instance using Http API
String rewindPostUri = startOrchestrationResponseJson.get("rewindPostUri");
post(rewindPostUri);

// Wait for orchestration to rewind and complete
Thread.sleep(3000);

for (int i = 0; i < 5; i++) {
statusResponse = get(statusQueryGetUri);
runtimeStatus = statusResponse.jsonPath().get("runtimeStatus");
if (!"Completed".equals(runtimeStatus)) {
Thread.sleep(1000);
} else break;
}
assertEquals("Completed", runtimeStatus);

// Reset approval for other test cases
post(resetApprovalUrl);
}
}

0 comments on commit bc1954b

Please sign in to comment.