mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-25 06:16:40 +00:00
Improve stability of the testReusePeerRecovery test
This commit is contained in:
parent
b7f5295674
commit
ec3492c67c
@ -31,12 +31,9 @@ import org.elasticsearch.common.settings.Settings;
|
|||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.node.Node;
|
import org.elasticsearch.node.Node;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static com.google.common.collect.Maps.newHashMap;
|
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.Builder.EMPTY_SETTINGS;
|
||||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||||
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
|
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
|
||||||
@ -138,24 +135,6 @@ public abstract class AbstractNodesTests {
|
|||||||
nodes.clear();
|
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 {
|
public ImmutableSet<ClusterBlock> waitForNoBlocks(TimeValue timeout, String node) throws InterruptedException {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
ImmutableSet<ClusterBlock> blocks;
|
ImmutableSet<ClusterBlock> blocks;
|
||||||
|
@ -26,7 +26,6 @@ import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse;
|
|||||||
import org.elasticsearch.action.admin.indices.status.ShardStatus;
|
import org.elasticsearch.action.admin.indices.status.ShardStatus;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.gateway.Gateway;
|
import org.elasticsearch.gateway.Gateway;
|
||||||
import org.elasticsearch.index.query.FilterBuilders;
|
import org.elasticsearch.index.query.FilterBuilders;
|
||||||
@ -359,8 +358,12 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
|
|||||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||||
|
|
||||||
logger.info("--> shutting down the nodes");
|
logger.info("--> shutting down the nodes");
|
||||||
client("node1").admin().cluster().prepareNodesShutdown().setDelay("10ms").setExit(false).execute().actionGet();
|
// Disable allocations while we are closing nodes
|
||||||
assertThat(waitForNodesToShutdown(TimeValue.timeValueSeconds(30), "node1", "node2", "node3", "node4"), equalTo(true));
|
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");
|
logger.info("--> start the nodes back up");
|
||||||
startNode("node1", settings);
|
startNode("node1", settings);
|
||||||
startNode("node2", settings);
|
startNode("node2", settings);
|
||||||
@ -374,8 +377,11 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
|
|||||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||||
|
|
||||||
logger.info("--> shutting down the nodes");
|
logger.info("--> shutting down the nodes");
|
||||||
client("node1").admin().cluster().prepareNodesShutdown().setDelay("10ms").setExit(false).execute().actionGet();
|
// Disable allocations while we are closing nodes
|
||||||
assertThat(waitForNodesToShutdown(TimeValue.timeValueSeconds(30), "node1", "node2", "node3", "node4"), equalTo(true));
|
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");
|
logger.info("--> start the nodes back up");
|
||||||
startNode("node1", settings);
|
startNode("node1", settings);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user