Test: RecoveryWhileUnderLoadTests.recoverWhileRelocating should report cluster state when failing to reach green

This commit is contained in:
Boaz Leskes 2014-09-21 20:11:56 +02:00
parent 41fd5d02f4
commit d17fd26f23
2 changed files with 15 additions and 3 deletions

View File

@ -29,6 +29,7 @@ import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.Priority; import org.elasticsearch.common.Priority;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.shard.DocsStats; import org.elasticsearch.index.shard.DocsStats;
import org.elasticsearch.test.BackgroundIndexer; import org.elasticsearch.test.BackgroundIndexer;
import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest;
@ -254,7 +255,7 @@ public class RecoveryWhileUnderLoadTests extends ElasticsearchIntegrationTest {
allowNodes = 2 / allowNodes; allowNodes = 2 / allowNodes;
allowNodes("test", allowNodes); allowNodes("test", allowNodes);
logger.info("--> waiting for GREEN health status ..."); logger.info("--> waiting for GREEN health status ...");
assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("5m").setWaitForGreenStatus()); ensureGreen(TimeValue.timeValueMinutes(5));
} }
logger.info("--> marking and waiting for indexing threads to stop ..."); logger.info("--> marking and waiting for indexing threads to stop ...");
@ -264,7 +265,7 @@ public class RecoveryWhileUnderLoadTests extends ElasticsearchIntegrationTest {
logger.info("--> bump up number of replicas to 1 and allow all nodes to hold the index"); logger.info("--> bump up number of replicas to 1 and allow all nodes to hold the index");
allowNodes("test", 3); allowNodes("test", 3);
assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put("number_of_replicas", 1)).get()); assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put("number_of_replicas", 1)).get());
assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("5m").setWaitForGreenStatus()); ensureGreen(TimeValue.timeValueMinutes(5));
logger.info("--> refreshing the index"); logger.info("--> refreshing the index");
refreshAndAssert(); refreshAndAssert();

View File

@ -917,8 +917,19 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
* are now allocated and started. * are now allocated and started.
*/ */
public ClusterHealthStatus ensureGreen(String... indices) { public ClusterHealthStatus ensureGreen(String... indices) {
return ensureGreen(TimeValue.timeValueSeconds(30), indices);
}
/**
* Ensures the cluster has a green state via the cluster health API. This method will also wait for relocations.
* It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating
* are now allocated and started.
*
* @param timeout time out value to set on {@link org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest}
*/
public ClusterHealthStatus ensureGreen(TimeValue timeout, String... indices) {
ClusterHealthResponse actionGet = client().admin().cluster() ClusterHealthResponse actionGet = client().admin().cluster()
.health(Requests.clusterHealthRequest(indices).waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet(); .health(Requests.clusterHealthRequest(indices).timeout(timeout).waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet();
if (actionGet.isTimedOut()) { if (actionGet.isTimedOut()) {
logger.info("ensureGreen timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState().prettyPrint(), client().admin().cluster().preparePendingClusterTasks().get().prettyPrint()); logger.info("ensureGreen timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState().prettyPrint(), client().admin().cluster().preparePendingClusterTasks().get().prettyPrint());
assertThat("timed out waiting for green state", actionGet.isTimedOut(), equalTo(false)); assertThat("timed out waiting for green state", actionGet.isTimedOut(), equalTo(false));