From 192025401bf0b42821f07b21580df56ffbe8d571 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 1 Aug 2013 19:45:08 +0200 Subject: [PATCH] improve test to wait for nodes before getting the local node id --- .../IndexLifecycleActionTests.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/elasticsearch/test/integration/indexlifecycle/IndexLifecycleActionTests.java b/src/test/java/org/elasticsearch/test/integration/indexlifecycle/IndexLifecycleActionTests.java index 55f6e005ecf..4846590d1a6 100644 --- a/src/test/java/org/elasticsearch/test/integration/indexlifecycle/IndexLifecycleActionTests.java +++ b/src/test/java/org/elasticsearch/test/integration/indexlifecycle/IndexLifecycleActionTests.java @@ -91,8 +91,6 @@ public class IndexLifecycleActionTests extends AbstractNodesTests { logger.info("Starting server2"); // start another server startNode("server2", settings); - ClusterService clusterService2 = ((InternalNode) node("server2")).injector().getInstance(ClusterService.class); - String node2 = clusterService2.state().nodes().localNodeId(); // first wait for 2 nodes in the cluster logger.info("Running Cluster Health"); @@ -101,6 +99,9 @@ public class IndexLifecycleActionTests extends AbstractNodesTests { assertThat(clusterHealth.isTimedOut(), equalTo(false)); assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN)); + ClusterService clusterService2 = ((InternalNode) node("server2")).injector().getInstance(ClusterService.class); + String node2 = clusterService2.state().nodes().localNodeId(); + // explicitly call reroute, so shards will get relocated to the new node (we delay it in ES in case other nodes join) client("server1").admin().cluster().prepareReroute().execute().actionGet(); @@ -127,14 +128,15 @@ public class IndexLifecycleActionTests extends AbstractNodesTests { // start another server startNode("server3", settings); - ClusterService clusterService3 = ((InternalNode) node("server3")).injector().getInstance(ClusterService.class); - String node3 = clusterService3.state().nodes().localNodeId(); - // first wait for 3 nodes in the cluster clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("3")).actionGet(); assertThat(clusterHealth.isTimedOut(), equalTo(false)); assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN)); + + ClusterService clusterService3 = ((InternalNode) node("server3")).injector().getInstance(ClusterService.class); + String node3 = clusterService3.state().nodes().localNodeId(); + // explicitly call reroute, so shards will get relocated to the new node (we delay it in ES in case other nodes join) client("server1").admin().cluster().prepareReroute().execute().actionGet(); @@ -166,7 +168,6 @@ public class IndexLifecycleActionTests extends AbstractNodesTests { assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(7)); - logger.info("Closing server1"); // kill the first server closeNode("server1"); @@ -199,7 +200,6 @@ public class IndexLifecycleActionTests extends AbstractNodesTests { assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(11)); - logger.info("Deleting index [test]"); // last, lets delete the index DeleteIndexResponse deleteIndexResponse = client("server2").admin().indices().prepareDelete("test").execute().actionGet(); @@ -253,15 +253,14 @@ public class IndexLifecycleActionTests extends AbstractNodesTests { logger.info("Starting server2"); startNode("server2", settings); - ClusterService clusterService2 = ((InternalNode) node("server2")).injector().getInstance(ClusterService.class); - String node2 = clusterService2.state().nodes().localNodeId(); - - // first wait for 2 nodes in the cluster clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2")).actionGet(); assertThat(clusterHealth.isTimedOut(), equalTo(false)); assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN)); + ClusterService clusterService2 = ((InternalNode) node("server2")).injector().getInstance(ClusterService.class); + String node2 = clusterService2.state().nodes().localNodeId(); + // explicitly call reroute, so shards will get relocated to the new node (we delay it in ES in case other nodes join) client("server1").admin().cluster().prepareReroute().execute().actionGet(); @@ -289,14 +288,14 @@ public class IndexLifecycleActionTests extends AbstractNodesTests { logger.info("Starting server3"); startNode("server3"); - ClusterService clusterService3 = ((InternalNode) node("server3")).injector().getInstance(ClusterService.class); - String node3 = clusterService3.state().nodes().localNodeId(); - // first wait for 3 nodes in the cluster clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("3")).actionGet(); assertThat(clusterHealth.isTimedOut(), equalTo(false)); assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN)); + ClusterService clusterService3 = ((InternalNode) node("server3")).injector().getInstance(ClusterService.class); + String node3 = clusterService3.state().nodes().localNodeId(); + // explicitly call reroute, so shards will get relocated to the new node (we delay it in ES in case other nodes join) client("server1").admin().cluster().prepareReroute().execute().actionGet();