Skip to content

Commit

Permalink
Change canCompleteSwap and completeSwapIfPossible to return json with…
Browse files Browse the repository at this point in the history
… kv pair for result of check or attempt to complete swap. (#2697)
  • Loading branch information
zpinto authored and Xiaoyuan Lu committed Dec 8, 2023
1 parent 8756712 commit e459692
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,11 @@ public Response updateInstance(@PathParam("clusterId") String clusterId,
admin.setInstanceOperation(clusterId, instanceName, state);
break;
case canCompleteSwap:
if (!admin.canCompleteSwap(clusterId, instanceName)) {
return badRequest("Swap is not ready to be completed!");
}
break;
return OK(OBJECT_MAPPER.writeValueAsString(
Map.of("successful", admin.canCompleteSwap(clusterId, instanceName))));
case completeSwapIfPossible:
if (!admin.completeSwapIfPossible(clusterId, instanceName)) {
return badRequest("Swap is not ready to be completed!");
}
break;
return OK(OBJECT_MAPPER.writeValueAsString(
Map.of("successful", admin.completeSwapIfPossible(clusterId, instanceName))));
case addInstanceTag:
if (!validInstance(node, instanceName)) {
return badRequest("Instance names are not match!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,26 @@ public void updateInstance() throws IOException {
instanceConfig = _configAccessor.getInstanceConfig(CLUSTER_NAME, INSTANCE_NAME);
Assert.assertEquals(
instanceConfig.getInstanceOperation(), "");

// test canCompleteSwap
Response canCompleteSwapResponse =
new JerseyUriRequestBuilder("clusters/{}/instances/{}?command=canCompleteSwap").format(
CLUSTER_NAME, INSTANCE_NAME).post(this, entity);
Assert.assertEquals(canCompleteSwapResponse.getStatus(), Response.Status.OK.getStatusCode());
Map<String, Object> responseMap =
OBJECT_MAPPER.readValue(canCompleteSwapResponse.readEntity(String.class), Map.class);
Assert.assertFalse((boolean) responseMap.get("successful"));

// test completeSwapIfPossible
Response completeSwapIfPossibleResponse = new JerseyUriRequestBuilder(
"clusters/{}/instances/{}?command=completeSwapIfPossible").format(CLUSTER_NAME,
INSTANCE_NAME).post(this, entity);
Assert.assertEquals(completeSwapIfPossibleResponse.getStatus(),
Response.Status.OK.getStatusCode());
responseMap =
OBJECT_MAPPER.readValue(completeSwapIfPossibleResponse.readEntity(String.class), Map.class);
Assert.assertFalse((boolean) responseMap.get("successful"));

System.out.println("End test :" + TestHelper.getTestMethodName());
}

Expand Down

0 comments on commit e459692

Please sign in to comment.