Added a timeout check to searchWhileCreatingIndex with cluster state dump on failure.

This commit is contained in:
Boaz Leskes 2013-08-14 20:19:53 +02:00
parent 594e03b695
commit 34442c8d0a
1 changed files with 44 additions and 9 deletions

View File

@ -19,8 +19,11 @@
package org.elasticsearch.test.integration.search.basic;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.cluster.service.PendingClusterTask;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.junit.Test;
@ -43,15 +46,47 @@ public class SearchWhileCreatingIndexTests extends AbstractSharedClusterTest {
* shards possibly not active at all (cause they haven't allocated) will still work.
*/
@Test
public void searchWhileCreatingIndex() {
for (int i = 0; i < 20; i++) {
prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 10));
client().prepareIndex("test", "type1", "id:" + i).setSource("field", "test").execute().actionGet();
RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").execute().actionGet();
assertThat(refreshResponse.getSuccessfulShards(), greaterThanOrEqualTo(1)); // at least one shard should be successful when refreshing
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
assertThat("found unexpected number of hits, shard_failures (we expected to potentially non active ones!):" + Arrays.toString(searchResponse.getShardFailures()) + " id: " + i, searchResponse.getHits().totalHits(), equalTo(1l));
wipeIndex("test");
public void searchWhileCreatingIndex() throws Throwable {
Thread backgroundThread;
final Throwable[] threadException = new Throwable[1];
backgroundThread = new Thread(new Runnable() {
@Override
public void run() {
try {
for (int i = 0; i < 20; i++) {
logger.info("Running iteration {}", i);
prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 10));
client().prepareIndex("test", "type1", "id:" + i).setSource("field", "test").execute().actionGet();
RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").execute().actionGet();
assertThat(refreshResponse.getSuccessfulShards(), greaterThanOrEqualTo(1)); // at least one shard should be successful when refreshing
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
assertThat("found unexpected number of hits, shard_failures (we expected to potentially non active ones!):" + Arrays.toString(searchResponse.getShardFailures()) + " id: " + i, searchResponse.getHits().totalHits(), equalTo(1l));
wipeIndex("test");
}
} catch (Throwable t) {
threadException[0] = t;
}
}
});
backgroundThread.setDaemon(true);
backgroundThread.start();
backgroundThread.join(30 * 60 * 1000);
if (threadException[0] != null) {
throw threadException[0];
}
if (backgroundThread.isAlive()) {
logger.error("Background thread hanged. Dumping cluster info");
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().get();
logger.info("ClusterState: {}", clusterStateResponse.getState());
PendingClusterTasksResponse pendingTasks = client().admin().cluster().preparePendingClusterTasks().get();
logger.info("Pending tasks:");
for (PendingClusterTask task : pendingTasks) {
logger.info("Task: priority: {} source: {} Time in queue (ms): {}", task.getPriority(), task.getSource(), task.timeInQueueInMillis());
}
fail("Background thread didn't finish within 30 minutes");
}
logger.info("done");
}
}