Skip to content

Commit ec3492c

Browse files
committed
Improve stability of the testReusePeerRecovery test
1 parent b7f5295 commit ec3492c

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

src/test/java/org/elasticsearch/test/integration/AbstractNodesTests.java

-21
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@
3131
import org.elasticsearch.common.unit.TimeValue;
3232
import org.elasticsearch.node.Node;
3333

34-
import java.util.Iterator;
3534
import java.util.Map;
36-
import java.util.Set;
3735

3836
import static com.google.common.collect.Maps.newHashMap;
39-
import static com.google.common.collect.Sets.newHashSet;
4037
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
4138
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
4239
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
@@ -138,24 +135,6 @@ public void closeAllNodes() {
138135
nodes.clear();
139136
}
140137

141-
public boolean waitForNodesToShutdown(TimeValue timeout, String... nodes) throws InterruptedException {
142-
long start = System.currentTimeMillis();
143-
Set<String> activeNodes = newHashSet(nodes);
144-
do {
145-
Thread.sleep(100);
146-
Iterator<String> nodeToCheck = activeNodes.iterator();
147-
while (nodeToCheck.hasNext()) {
148-
String id = nodeToCheck.next();
149-
if (node(id).isClosed()) {
150-
nodeToCheck.remove();
151-
} else {
152-
break;
153-
}
154-
}
155-
} while (!activeNodes.isEmpty() && (System.currentTimeMillis() - start) < timeout.millis());
156-
return activeNodes.isEmpty();
157-
}
158-
159138
public ImmutableSet<ClusterBlock> waitForNoBlocks(TimeValue timeout, String node) throws InterruptedException {
160139
long start = System.currentTimeMillis();
161140
ImmutableSet<ClusterBlock> blocks;

src/test/java/org/elasticsearch/test/integration/gateway/local/SimpleRecoveryLocalGatewayTests.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.elasticsearch.action.admin.indices.status.ShardStatus;
2727
import org.elasticsearch.cluster.ClusterState;
2828
import org.elasticsearch.common.settings.ImmutableSettings;
29-
import org.elasticsearch.common.unit.TimeValue;
3029
import org.elasticsearch.common.xcontent.XContentFactory;
3130
import org.elasticsearch.gateway.Gateway;
3231
import org.elasticsearch.index.query.FilterBuilders;
@@ -359,8 +358,12 @@ public void testReusePeerRecovery() throws Exception {
359358
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
360359

361360
logger.info("--> shutting down the nodes");
362-
client("node1").admin().cluster().prepareNodesShutdown().setDelay("10ms").setExit(false).execute().actionGet();
363-
assertThat(waitForNodesToShutdown(TimeValue.timeValueSeconds(30), "node1", "node2", "node3", "node4"), equalTo(true));
361+
// Disable allocations while we are closing nodes
362+
client("node1").admin().cluster().prepareUpdateSettings().setTransientSettings(settingsBuilder().put("cluster.routing.allocation.disable_allocation", true)).execute().actionGet();
363+
for (int i = 1; i < 5; i++) {
364+
closeNode("node" + i);
365+
}
366+
364367
logger.info("--> start the nodes back up");
365368
startNode("node1", settings);
366369
startNode("node2", settings);
@@ -374,8 +377,11 @@ public void testReusePeerRecovery() throws Exception {
374377
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
375378

376379
logger.info("--> shutting down the nodes");
377-
client("node1").admin().cluster().prepareNodesShutdown().setDelay("10ms").setExit(false).execute().actionGet();
378-
assertThat(waitForNodesToShutdown(TimeValue.timeValueSeconds(30), "node1", "node2", "node3", "node4"), equalTo(true));
380+
// Disable allocations while we are closing nodes
381+
client("node1").admin().cluster().prepareUpdateSettings().setTransientSettings(settingsBuilder().put("cluster.routing.allocation.disable_allocation", true)).execute().actionGet();
382+
for (int i = 1; i < 5; i++) {
383+
closeNode("node" + i);
384+
}
379385

380386
logger.info("--> start the nodes back up");
381387
startNode("node1", settings);

0 commit comments

Comments
 (0)