mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-19 19:35:02 +00:00
Added a timeout check to searchWhileCreatingIndex with cluster state dump on failure.
This commit is contained in:
parent
594e03b695
commit
34442c8d0a
@ -19,8 +19,11 @@
|
|||||||
|
|
||||||
package org.elasticsearch.test.integration.search.basic;
|
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.admin.indices.refresh.RefreshResponse;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
|
import org.elasticsearch.cluster.service.PendingClusterTask;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
|
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
|
||||||
import org.junit.Test;
|
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.
|
* shards possibly not active at all (cause they haven't allocated) will still work.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void searchWhileCreatingIndex() {
|
public void searchWhileCreatingIndex() throws Throwable {
|
||||||
for (int i = 0; i < 20; i++) {
|
Thread backgroundThread;
|
||||||
prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 10));
|
final Throwable[] threadException = new Throwable[1];
|
||||||
client().prepareIndex("test", "type1", "id:" + i).setSource("field", "test").execute().actionGet();
|
backgroundThread = new Thread(new Runnable() {
|
||||||
RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").execute().actionGet();
|
@Override
|
||||||
assertThat(refreshResponse.getSuccessfulShards(), greaterThanOrEqualTo(1)); // at least one shard should be successful when refreshing
|
public void run() {
|
||||||
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
|
try {
|
||||||
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));
|
for (int i = 0; i < 20; i++) {
|
||||||
wipeIndex("test");
|
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");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user