Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-2847

James Dyer264eb5690a81
diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java
index b14b59a1bbe..fa53f9193a6 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java
@@ -17,9 +17,13 @@ package org.apache.solr.handler.component;
* limitations under the License.
*/
+import junit.framework.TestCase;
+
import org.apache.solr.BaseDistributedSearchTestCase;
import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.NamedList;
/**
* Test for SpellCheckComponent's distributed querying
@@ -45,7 +49,7 @@ public class DistributedSpellCheckComponentTest extends BaseDistributedSearchTes
// this test requires FSDir
saveProp = System.getProperty("solr.directoryFactory");
System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
- requestHandlerName = random.nextBoolean() ? "spellCheckCompRH" : "spellCheckCompRH_Direct";
+ requestHandlerName = random.nextBoolean() ? "spellCheckCompRH" : "spellCheckCompRH_Direct";
super.setUp();
}
@@ -74,6 +78,17 @@ public class DistributedSpellCheckComponentTest extends BaseDistributedSearchTes
client.query(params);
}
+ @Override
+ public void validateControlData(QueryResponse control) throws Exception
+ {
+ NamedList nl = control.getResponse();
+ NamedList sc = (NamedList) nl.get("spellcheck");
+ NamedList sug = (NamedList) sc.get("suggestions");
+ if(sug.size()==0) {
+ TestCase.fail("Control data did not return any suggestions.");
+ }
+ }
+
@Override
public void doTest() throws Exception {
del("*:*");
@@ -109,7 +124,7 @@ public class DistributedSpellCheckComponentTest extends BaseDistributedSearchTes
// we care only about the spellcheck results
handle.put("response", SKIP);
- q("q", "*:*", SpellCheckComponent.SPELLCHECK_BUILD, "true", "qt", "spellCheckCompRH", "shards.qt", "spellCheckCompRH");
+ q("q", "*:*", "spellcheck", "true", SpellCheckComponent.SPELLCHECK_BUILD, "true", "qt", "spellCheckCompRH", "shards.qt", "spellCheckCompRH");
query("q", "*:*", "fl", "id,lowerfilt", "spellcheck.q","toyata", "spellcheck", "true", "qt", requestHandlerName, "shards.qt", requestHandlerName);
query("q", "*:*", "fl", "id,lowerfilt", "spellcheck.q","toyata", "spellcheck", "true", "qt", requestHandlerName, "shards.qt", requestHandlerName, SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true");
diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
index 0120429d8f9..cf7518ab202 100644
--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
@@ -372,6 +372,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
// TODO: look into why passing true causes fails
params.set("distrib", "false");
final QueryResponse controlRsp = controlClient.query(params);
+ validateControlData(controlRsp);
params.remove("distrib");
setDistributedParams(params);
@@ -680,6 +681,19 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
return o;
}
+
+ /**
+ * Implementations can pre-test the control data for basic correctness before using it
+ * as a check for the shard data. This is useful, for instance, if a test bug is introduced
+ * causing a spelling index not to get built: both control & shard data would have no results
+ * but because they match the test would pass. This method gives us a chance to ensure something
+ * exists in the control data.
+ *
+ * @throws Exception
+ */
+ public void validateControlData(QueryResponse control) throws Exception {
+ /* no-op */
+ }
public static abstract class RandVal {
public static Random r = random;