Skip to content

Commit

Permalink
test to verify the fix
Browse files Browse the repository at this point in the history
Signed-off-by: Anshu Agarwal <[email protected]>
  • Loading branch information
Anshu Agarwal committed Oct 7, 2022
1 parent 93818bf commit 9e22066
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,52 @@ public void testGetWeightedRouting_WeightsAreSet() throws IOException {
assertEquals(weightedRouting, weightedRoutingResponse.weights());
assertEquals("3.0", weightedRoutingResponse.getLocalNodeWeight());
}

public void testWeightedRoutingMetadataOnOSProcessRestart() throws IOException {
Settings commonSettings = Settings.builder()
.put("cluster.routing.allocation.awareness.attributes", "zone")
.put("cluster.routing.allocation.awareness.force.zone.values", "a,b,c")
.build();

internalCluster().startNodes(
Settings.builder().put(commonSettings).put("node.attr.zone", "a").build(),
Settings.builder().put(commonSettings).put("node.attr.zone", "b").build(),
Settings.builder().put(commonSettings).put("node.attr.zone", "c").build()
);

logger.info("--> waiting for nodes to form a cluster");
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("3").execute().actionGet();
assertThat(health.isTimedOut(), equalTo(false));

ensureGreen();

logger.info("--> setting shard routing weights for weighted round robin");
Map<String, Double> weights = Map.of("a", 1.0, "b", 2.0, "c", 3.0);
WeightedRouting weightedRouting = new WeightedRouting("zone", weights);
// put api call to set weights
ClusterPutWeightedRoutingResponse response = client().admin()
.cluster()
.prepareWeightedRouting()
.setWeightedRouting(weightedRouting)
.get();
assertEquals(response.isAcknowledged(), true);

ensureStableCluster(3);

// routing weights are set in cluster metadata
assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata());

ensureGreen();

// Restart a random data node and check that OS process comes healthy
try {
internalCluster().restartRandomDataNode();
} catch (Exception e) {
e.printStackTrace();
}

ensureGreen();

assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata());
}
}

0 comments on commit 9e22066

Please sign in to comment.