Improve stability of the testReusePeerRecovery test

This commit is contained in:
Igor Motov 2013-02-21 15:59:14 -05:00
parent b7f5295674
commit ec3492c67c
2 changed files with 11 additions and 26 deletions

View File

@ -31,12 +31,9 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.node.Node;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import static com.google.common.collect.Maps.newHashMap;
import static com.google.common.collect.Sets.newHashSet;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
@ -138,24 +135,6 @@ public abstract class AbstractNodesTests {
nodes.clear();
}
public boolean waitForNodesToShutdown(TimeValue timeout, String... nodes) throws InterruptedException {
long start = System.currentTimeMillis();
Set<String> activeNodes = newHashSet(nodes);
do {
Thread.sleep(100);
Iterator<String> nodeToCheck = activeNodes.iterator();
while (nodeToCheck.hasNext()) {
String id = nodeToCheck.next();
if (node(id).isClosed()) {
nodeToCheck.remove();
} else {
break;
}
}
} while (!activeNodes.isEmpty() && (System.currentTimeMillis() - start) < timeout.millis());
return activeNodes.isEmpty();
}
public ImmutableSet<ClusterBlock> waitForNoBlocks(TimeValue timeout, String node) throws InterruptedException {
long start = System.currentTimeMillis();
ImmutableSet<ClusterBlock> blocks;

View File

@ -26,7 +26,6 @@ import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse;
import org.elasticsearch.action.admin.indices.status.ShardStatus;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.index.query.FilterBuilders;
@ -359,8 +358,12 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
logger.info("--> shutting down the nodes");
client("node1").admin().cluster().prepareNodesShutdown().setDelay("10ms").setExit(false).execute().actionGet();
assertThat(waitForNodesToShutdown(TimeValue.timeValueSeconds(30), "node1", "node2", "node3", "node4"), equalTo(true));
// Disable allocations while we are closing nodes
client("node1").admin().cluster().prepareUpdateSettings().setTransientSettings(settingsBuilder().put("cluster.routing.allocation.disable_allocation", true)).execute().actionGet();
for (int i = 1; i < 5; i++) {
closeNode("node" + i);
}
logger.info("--> start the nodes back up");
startNode("node1", settings);
startNode("node2", settings);
@ -374,8 +377,11 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
logger.info("--> shutting down the nodes");
client("node1").admin().cluster().prepareNodesShutdown().setDelay("10ms").setExit(false).execute().actionGet();
assertThat(waitForNodesToShutdown(TimeValue.timeValueSeconds(30), "node1", "node2", "node3", "node4"), equalTo(true));
// Disable allocations while we are closing nodes
client("node1").admin().cluster().prepareUpdateSettings().setTransientSettings(settingsBuilder().put("cluster.routing.allocation.disable_allocation", true)).execute().actionGet();
for (int i = 1; i < 5; i++) {
closeNode("node" + i);
}
logger.info("--> start the nodes back up");
startNode("node1", settings);