From 6b52391dbdb3d0a7e11ecc5ae7f6d4f14c8cce92 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Mon, 28 Oct 2013 09:39:07 +0100 Subject: [PATCH] Added a ClusterHealthResponse.toString implementation for better error reporting in FullRollingRestartTests timeout failures. --- .../cluster/health/ClusterHealthResponse.java | 20 ++++++++++++++ .../recovery/FullRollingRestartTests.java | 27 +++++++++++++------ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java index 04fb2299008..ba6e8432754 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java @@ -181,4 +181,24 @@ public class ClusterHealthResponse extends ActionResponse implements Iterable indexEntry : indices.entrySet()) { + builder.append(" [").append(indexEntry.getKey()).append("][").append(indexEntry.getValue().status).append("]"); + } + return builder.toString(); + } } diff --git a/src/test/java/org/elasticsearch/recovery/FullRollingRestartTests.java b/src/test/java/org/elasticsearch/recovery/FullRollingRestartTests.java index 86ee4732e93..2907119f71f 100644 --- a/src/test/java/org/elasticsearch/recovery/FullRollingRestartTests.java +++ b/src/test/java/org/elasticsearch/recovery/FullRollingRestartTests.java @@ -20,6 +20,8 @@ package org.elasticsearch.recovery; import org.apache.lucene.util.LuceneTestCase.Slow; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.common.Priority; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.test.AbstractIntegrationTest; @@ -33,15 +35,24 @@ import static org.hamcrest.Matchers.equalTo; /** * */ -@ClusterScope(scope=Scope.TEST, numNodes = 0, transportClientRatio = 0.0) +@ClusterScope(scope = Scope.TEST, numNodes = 0, transportClientRatio = 0.0) public class FullRollingRestartTests extends AbstractIntegrationTest { + protected void assertTimeout(ClusterHealthRequestBuilder requestBuilder) { + ClusterHealthResponse clusterHealth = requestBuilder.get(); + if (clusterHealth.isTimedOut()) { + logger.info("cluster health request timed out:\n{}", clusterHealth); + fail("cluster health request timed out"); + } + + } + @Test @Slow public void testFullRollingRestart() throws Exception { cluster().startNode(); createIndex("test"); - + for (int i = 0; i < 1000; i++) { client().prepareIndex("test", "type1", Long.toString(i)) .setSource(MapBuilder.newMapBuilder().put("test", "value" + i).map()).execute().actionGet(); @@ -57,14 +68,14 @@ public class FullRollingRestartTests extends AbstractIntegrationTest { cluster().startNode(); // make sure the cluster state is green, and all has been recovered - assertThat(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForGreenStatus().setWaitForRelocatingShards(0).setWaitForNodes("3").execute().actionGet().isTimedOut(), equalTo(false)); + assertTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForGreenStatus().setWaitForRelocatingShards(0).setWaitForNodes("3")); // now start adding nodes cluster().startNode(); cluster().startNode(); // make sure the cluster state is green, and all has been recovered - assertThat(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForGreenStatus().setWaitForRelocatingShards(0).setWaitForNodes("5").execute().actionGet().isTimedOut(), equalTo(false)); + assertTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForGreenStatus().setWaitForRelocatingShards(0).setWaitForNodes("5")); client().admin().indices().prepareRefresh().execute().actionGet(); for (int i = 0; i < 10; i++) { @@ -74,10 +85,10 @@ public class FullRollingRestartTests extends AbstractIntegrationTest { // now start shutting nodes down cluster().stopRandomNode(); // make sure the cluster state is green, and all has been recovered - assertThat(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForGreenStatus().setWaitForRelocatingShards(0).setWaitForNodes("4").execute().actionGet().isTimedOut(), equalTo(false)); + assertTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForGreenStatus().setWaitForRelocatingShards(0).setWaitForNodes("4")); cluster().stopRandomNode(); // make sure the cluster state is green, and all has been recovered - assertThat(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForGreenStatus().setWaitForRelocatingShards(0).setWaitForNodes("3").execute().actionGet().isTimedOut(), equalTo(false)); + assertTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForGreenStatus().setWaitForRelocatingShards(0).setWaitForNodes("3")); client().admin().indices().prepareRefresh().execute().actionGet(); @@ -87,11 +98,11 @@ public class FullRollingRestartTests extends AbstractIntegrationTest { cluster().stopRandomNode(); // make sure the cluster state is green, and all has been recovered - assertThat(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForGreenStatus().setWaitForRelocatingShards(0).setWaitForNodes("2").execute().actionGet().isTimedOut(), equalTo(false)); + assertTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForGreenStatus().setWaitForRelocatingShards(0).setWaitForNodes("2")); cluster().stopRandomNode(); // make sure the cluster state is green, and all has been recovered - assertThat(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForYellowStatus().setWaitForRelocatingShards(0).setWaitForNodes("1").execute().actionGet().isTimedOut(), equalTo(false)); + assertTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("1m").setWaitForYellowStatus().setWaitForRelocatingShards(0).setWaitForNodes("1")); client().admin().indices().prepareRefresh().execute().actionGet(); for (int i = 0; i < 10; i++) {