Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17819: Improve DistributedDebugComponentTest.testTolerantSearch

Houston Putman17f318e2d7b9
diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
index 8ed448d5ebe..8e8c5ec88fd 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
@@ -409,29 +409,35 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
query.set("debug", "true");
query.set("distrib", "true");
query.setFields("id", "text");
- query.set("shards", shard1 + "," + shard2 + "," + badShard);
-
- // verify that the request would fail if shards.tolerant=false
- ignoreException("Server refused connection");
- expectThrows(SolrException.class, () -> collection1.query(query));
-
- query.set(ShardParams.SHARDS_TOLERANT, "true");
- QueryResponse response = collection1.query(query);
- assertTrue(
- (Boolean)
- response
- .getResponseHeader()
- .get(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY));
- @SuppressWarnings("unchecked")
- NamedList<String> badShardTrack =
- (((NamedList<NamedList<NamedList<String>>>) response.getDebugMap().get("track"))
- .get("EXECUTE_QUERY"))
- .get(badShard);
- assertEquals("Unexpected response size for shard", 1, badShardTrack.size());
- Entry<String, String> exception = badShardTrack.iterator().next();
- assertEquals("Expected key 'Exception' not found", "Exception", exception.getKey());
- assertNotNull("Exception message should not be null", exception.getValue());
- unIgnoreException("Server refused connection");
+ // When the badShard is placed first, we are more likely to hit errors
+ query.set("shards", badShard + "," + shard2 + "," + shard1);
+
+ // Submit the requests enough times to get failures when code is buggy
+ for (int i = 0; i < (TEST_NIGHTLY ? 500 : 200); i++) {
+ // verify that the request would fail if shards.tolerant=false
+ query.set(ShardParams.SHARDS_TOLERANT, "false");
+ ignoreException("Server refused connection");
+ expectThrows(SolrException.class, () -> collection1.query(query));
+
+ // verify that the request would succeed if shards.tolerant=true
+ query.set(ShardParams.SHARDS_TOLERANT, "true");
+ QueryResponse response = collection1.query(query);
+ assertTrue(
+ (Boolean)
+ response
+ .getResponseHeader()
+ .get(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY));
+ @SuppressWarnings("unchecked")
+ NamedList<String> badShardTrack =
+ (((NamedList<NamedList<NamedList<String>>>) response.getDebugMap().get("track"))
+ .get("EXECUTE_QUERY"))
+ .get(badShard);
+ assertEquals("Unexpected response size for shard", 1, badShardTrack.size());
+ Entry<String, String> exception = badShardTrack.iterator().next();
+ assertEquals("Expected key 'Exception' not found", "Exception", exception.getKey());
+ assertNotNull("Exception message should not be null", exception.getValue());
+ unIgnoreException("Server refused connection");
+ }
}
/** Compares the same section on the two query responses */