Skip to content

Commit 183a74c

Browse files
committed
Improve stability of testSimpleAwareness test
1 parent 06fc9c7 commit 183a74c

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/test/java/org/elasticsearch/test/integration/cluster/allocation/AwarenessAllocationTests.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,28 @@ public void testSimpleAwareness() throws Exception {
6969
logger.info("--> starting 1 node on a different rack");
7070
startNode("node3", ImmutableSettings.settingsBuilder().put(commonSettings).put("node.rack_id", "rack_2"));
7171

72-
Thread.sleep(500);
72+
long start = System.currentTimeMillis();
73+
TObjectIntHashMap<String> counts;
74+
// On slow machines the initial relocation might be delayed
75+
do {
76+
Thread.sleep(100);
77+
logger.info("--> waiting for no relocation");
78+
health = client("node1").admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("3").setWaitForRelocatingShards(0).execute().actionGet();
79+
assertThat(health.isTimedOut(), equalTo(false));
7380

74-
health = client("node1").admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("3").setWaitForRelocatingShards(0).execute().actionGet();
75-
assertThat(health.isTimedOut(), equalTo(false));
76-
77-
ClusterState clusterState = client("node1").admin().cluster().prepareState().execute().actionGet().getState();
78-
//System.out.println(clusterState.routingTable().prettyPrint());
79-
// verify that we have 10 shards on node3
80-
TObjectIntHashMap<String> counts = new TObjectIntHashMap<String>();
81-
for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
82-
for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
83-
for (ShardRouting shardRouting : indexShardRoutingTable) {
84-
counts.adjustOrPutValue(clusterState.nodes().get(shardRouting.currentNodeId()).name(), 1, 1);
81+
logger.info("--> checking current state");
82+
ClusterState clusterState = client("node1").admin().cluster().prepareState().execute().actionGet().getState();
83+
//System.out.println(clusterState.routingTable().prettyPrint());
84+
// verify that we have 10 shards on node3
85+
counts = new TObjectIntHashMap<String>();
86+
for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
87+
for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
88+
for (ShardRouting shardRouting : indexShardRoutingTable) {
89+
counts.adjustOrPutValue(clusterState.nodes().get(shardRouting.currentNodeId()).name(), 1, 1);
90+
}
8591
}
8692
}
87-
}
93+
} while (counts.get("node3") != 10 && (System.currentTimeMillis() - start) < 10000);
8894
assertThat(counts.get("node3"), equalTo(10));
8995
}
9096
}

0 commit comments

Comments
 (0)