[TEST] Make SearchWhileRelocatingTests to handle known limitations gracefully
This commit is contained in:
parent
09e5ac98fa
commit
127371022d
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.elasticsearch.search.basic;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.annotations.Nightly;
|
||||
import com.carrotsearch.randomizedtesting.annotations.Repeat;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
|
@ -39,25 +41,34 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde
|
|||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class SearchWhileRelocatingTests extends ElasticsearchIntegrationTest {
|
||||
|
||||
@LuceneTestCase.AwaitsFix(bugUrl = "problem with search searching on 1 shard (no replica), " +
|
||||
"and between getting the cluster state to do the search, and executing it, " +
|
||||
"the shard has fully relocated (moved from started on one node, to fully started on another node")
|
||||
// @LuceneTestCase.AwaitsFix(bugUrl = "problem with search searching on 1 shard (no replica), " +
|
||||
// "and between getting the cluster state to do the search, and executing it, " +
|
||||
// "the shard has fully relocated (moved from started on one node, to fully started on another node")
|
||||
// ^^ the current impl of the test handles this case gracefully since it can happen with 1 replica as well
|
||||
// we just make sure if we get a partial result without a failure that the postsearch is ok!
|
||||
@Test
|
||||
@Nightly
|
||||
public void testSearchAndRelocateConcurrently0Replicas() throws Exception {
|
||||
testSearchAndRelocateConcurrently(0);
|
||||
}
|
||||
|
||||
@TestLogging("org.elasticsearch.action.search.type:TRACE")
|
||||
@Test
|
||||
@Nightly
|
||||
public void testSearchAndRelocateConcurrently1Replicas() throws Exception {
|
||||
testSearchAndRelocateConcurrently(1);
|
||||
}
|
||||
|
||||
private void testSearchAndRelocateConcurrently(int numberOfReplicas) throws Exception {
|
||||
final int numShards = between(10, 20);
|
||||
@Test
|
||||
public void testSearchAndRelocateConcurrentlyRanodmReplicas() throws Exception {
|
||||
testSearchAndRelocateConcurrently(randomIntBetween(0, 1));
|
||||
}
|
||||
|
||||
private void testSearchAndRelocateConcurrently(final int numberOfReplicas) throws Exception {
|
||||
final int numShards = between(1, 20);
|
||||
client().admin().indices().prepareCreate("test")
|
||||
.setSettings(settingsBuilder().put("index.number_of_shards", numShards).put("index.number_of_replicas", numberOfReplicas))
|
||||
.addMapping("type1", "loc", "type=geo_point", "test", "type=string").execute().actionGet();
|
||||
|
@ -72,24 +83,39 @@ public class SearchWhileRelocatingTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
indexRandom(true, indexBuilders.toArray(new IndexRequestBuilder[indexBuilders.size()]));
|
||||
assertHitCount(client().prepareSearch().get(), (long) (numDocs));
|
||||
final int numIters = scaledRandomIntBetween(10, 20);
|
||||
final int numIters = scaledRandomIntBetween(5, 20);
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
final AtomicBoolean stop = new AtomicBoolean(false);
|
||||
final List<Throwable> thrownExceptions = new CopyOnWriteArrayList<Throwable>();
|
||||
final List<Throwable> nonCriticalExceptions = new CopyOnWriteArrayList<Throwable>();
|
||||
|
||||
Thread[] threads = new Thread[scaledRandomIntBetween(1, 3)];
|
||||
for (int j = 0; j < threads.length; j++) {
|
||||
threads[j] = new Thread() {
|
||||
public void run() {
|
||||
boolean criticalException = true;
|
||||
try {
|
||||
while (!stop.get()) {
|
||||
SearchResponse sr = client().prepareSearch().setSize(numDocs).get();
|
||||
// if we did not search all shards but had no failures that is potentially fine
|
||||
// if only the hit-count is wrong. this can happen if the cluster-state is behind when the
|
||||
// request comes in. It's a small window but a known limitation.
|
||||
//
|
||||
criticalException = sr.getTotalShards() == sr.getSuccessfulShards() || sr.getFailedShards() > 0;
|
||||
assertHitCount(sr, (long) (numDocs));
|
||||
criticalException = true;
|
||||
final SearchHits sh = sr.getHits();
|
||||
assertThat("Expected hits to be the same size the actual hits array", sh.getTotalHits(),
|
||||
equalTo((long) (sh.getHits().length)));
|
||||
// this is the more critical but that we hit the actual hit array has a different size than the
|
||||
// actual number of hits.
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
thrownExceptions.add(t);
|
||||
if (!criticalException) {
|
||||
nonCriticalExceptions.add(t);
|
||||
} else {
|
||||
thrownExceptions.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -105,18 +131,21 @@ public class SearchWhileRelocatingTests extends ElasticsearchIntegrationTest {
|
|||
threads[j].join();
|
||||
}
|
||||
assertThat(resp.isTimedOut(), equalTo(false));
|
||||
|
||||
if (!thrownExceptions.isEmpty()) {
|
||||
if (!thrownExceptions.isEmpty() || !nonCriticalExceptions.isEmpty()) {
|
||||
Client client = client();
|
||||
boolean postSearchOK = true;
|
||||
String verified = "POST SEARCH OK";
|
||||
for (int j = 0; j < 10; j++) {
|
||||
if (client.prepareSearch().get().getHits().getTotalHits() != numDocs) {
|
||||
verified = "POST SEARCH FAIL";
|
||||
postSearchOK = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertThat("failed in iteration " + i + ", verification: " + verified, thrownExceptions, Matchers.emptyIterable());
|
||||
assertThat("numberOfReplicas: " + numberOfReplicas + " failed in iteration " + i + ", verification: " + verified, thrownExceptions, Matchers.emptyIterable());
|
||||
// if we hit only non-critical exceptions we only make sure that the post search works
|
||||
logger.info("Non-CriticalExceptions: " + nonCriticalExceptions.toString());
|
||||
assertThat("numberOfReplicas: " + numberOfReplicas + " failed in iteration " + i + ", verification: " + verified, postSearchOK, is(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue