SOLR-2847

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1244553 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Dyer 2012-02-15 15:52:32 +00:00
parent 4ae7fdf84f
commit 264eb5690a
2 changed files with 31 additions and 2 deletions

View File

@ -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
@ -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");

View File

@ -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);
@ -681,6 +682,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;
public static Set uniqueValues = new HashSet();