Skip to content

Commit

Permalink
add test for delete metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Anshu Agarwal <anshukag@amazon.com>
  • Loading branch information
Anshu Agarwal committed Sep 22, 2022
1 parent e9d2b6e commit 3ce3c22
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.Before;
import org.opensearch.Version;
import org.opensearch.action.ActionListener;
import org.opensearch.action.admin.cluster.shards.routing.weighted.delete.ClusterDeleteWeightedRoutingRequest;
import org.opensearch.action.admin.cluster.shards.routing.weighted.put.ClusterPutWeightedRoutingAction;
import org.opensearch.action.admin.cluster.shards.routing.weighted.put.ClusterPutWeightedRoutingRequestBuilder;
import org.opensearch.client.node.NodeClient;
Expand Down Expand Up @@ -231,4 +232,30 @@ public void onFailure(Exception e) {
weightedRoutingService.registerWeightedRoutingMetadata(request.request(), listener);
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
}

public void testDeleteWeightedRoutingMetadata() throws InterruptedException {
Map<String, Double> weights = Map.of("zone_A", 1.0, "zone_B", 1.0, "zone_C", 1.0);
ClusterState state = clusterService.state();
state = setWeightedRoutingWeights(state, weights);
ClusterState.Builder builder = ClusterState.builder(state);
ClusterServiceUtils.setState(clusterService, builder);

ClusterDeleteWeightedRoutingRequest clusterDeleteWeightedRoutingRequest = new ClusterDeleteWeightedRoutingRequest();
final CountDownLatch countDownLatch = new CountDownLatch(1);
ActionListener<ClusterStateUpdateResponse> listener = new ActionListener<ClusterStateUpdateResponse>() {
@Override
public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) {
assertTrue(clusterStateUpdateResponse.isAcknowledged());
assertNull(clusterService.state().metadata().weightedRoutingMetadata());
countDownLatch.countDown();
}

@Override
public void onFailure(Exception e) {
fail("request should not fail");
}
};
weightedRoutingService.deleteWeightedRoutingMetadata(clusterDeleteWeightedRoutingRequest, listener);
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
}
}

0 comments on commit 3ce3c22

Please sign in to comment.