Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-2521: TestJoin.testRandom fails, improve effective test coverage

Yonik Seeley66275ea88112
diff --git a/solr/src/java/org/apache/solr/search/JoinQParserPlugin.java b/solr/src/java/org/apache/solr/search/JoinQParserPlugin.java
index fbfac0788e8..da42a25859c 100644
--- a/solr/src/java/org/apache/solr/search/JoinQParserPlugin.java
+++ b/solr/src/java/org/apache/solr/search/JoinQParserPlugin.java
@@ -457,7 +457,7 @@ class JoinQuery extends Query {
return resultList.get(0);
}
- int sz = resultList.size();
+ int sz = 0;
for (DocSet set : resultList)
sz += set.size();
diff --git a/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
index dee2f2fab85..ce9f31abb1c 100644
--- a/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -811,7 +811,7 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
bitsSet += upto;
result = new BitDocSet(obs, bitsSet);
} else {
- result = new SortedIntDocSet(Arrays.copyOf(docs, upto));
+ result = upto==0 ? DocSet.EMPTY : new SortedIntDocSet(Arrays.copyOf(docs, upto));
}
if (useCache) {
diff --git a/solr/src/test/org/apache/solr/TestJoin.java b/solr/src/test/org/apache/solr/TestJoin.java
index 533d94d003f..590173ec565 100644
--- a/solr/src/test/org/apache/solr/TestJoin.java
+++ b/solr/src/test/org/apache/solr/TestJoin.java
@@ -101,6 +101,14 @@ public class TestJoin extends SolrTestCaseJ4 {
int indexIter=50 * RANDOM_MULTIPLIER;
int queryIter=50 * RANDOM_MULTIPLIER;
+ // groups of fields that have any chance of matching... used to
+ // increase test effectiveness by avoiding 0 resultsets much of the time.
+ String[][] compat = new String[][] {
+ {"small_s","small2_s","small2_ss","small3_ss"},
+ {"small_i","small2_i","small2_is","small3_is"}
+ };
+
+
while (--indexIter >= 0) {
int indexSize = random.nextInt(20 * RANDOM_MULTIPLIER);
@@ -121,8 +129,19 @@ public class TestJoin extends SolrTestCaseJ4 {
Map<String, Map<Comparable, Set<Comparable>>> pivots = new HashMap<String, Map<Comparable, Set<Comparable>>>();
for (int qiter=0; qiter<queryIter; qiter++) {
- String fromField = types.get(random.nextInt(types.size())).fname;
- String toField = types.get(random.nextInt(types.size())).fname;
+ String fromField;
+ String toField;
+ if (random.nextInt(100) < 5) {
+ // pick random fields 5% of the time
+ fromField = types.get(random.nextInt(types.size())).fname;
+ // pick the same field 50% of the time we pick a random field (since other fields won't match anything)
+ toField = (random.nextInt(100) < 50) ? fromField : types.get(random.nextInt(types.size())).fname;
+ } else {
+ // otherwise, pick compatible fields that have a chance of matching indexed tokens
+ String[] group = compat[random.nextInt(compat.length)];
+ fromField = group[random.nextInt(group.length)];
+ toField = group[random.nextInt(group.length)];
+ }
Map<Comparable, Set<Comparable>> pivot = pivots.get(fromField+"/"+toField);
if (pivot == null) {
@@ -146,7 +165,7 @@ public class TestJoin extends SolrTestCaseJ4 {
resultSet.put("start", 0);
resultSet.put("docs", sortedDocs);
- // todo: use filters
+ // todo: use different join queries for better coverage
SolrQueryRequest req = req("wt","json","indent","true", "echoParams","all",
"q","{!join from="+fromField+" to="+toField
@@ -159,7 +178,7 @@ public class TestJoin extends SolrTestCaseJ4 {
Object realResponse = ObjectBuilder.fromJSON(strResponse);
String err = JSONTestUtil.matchObj("/response", realResponse, resultSet);
if (err != null) {
- log.error("GROUPING MISMATCH: " + err
+ log.error("JOIN MISMATCH: " + err
+ "\n\trequest="+req
+ "\n\tresult="+strResponse
+ "\n\texpected="+ JSONUtil.toJSON(resultSet)