You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2017/07/06 16:38:18 UTC

[2/2] lucene-solr:branch_7_0: SOLR-11016: Fix TestCloudJSONFacetJoinDomain test-only bug

SOLR-11016: Fix TestCloudJSONFacetJoinDomain test-only bug

(cherry picked from commit d81daf54b4b567327c6ebde94b2b2eedacf19cd6)


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/4816a1cb
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/4816a1cb
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/4816a1cb

Branch: refs/heads/branch_7_0
Commit: 4816a1cb1b3d66c0537c9b77b86497408b5f01c8
Parents: 5e7fa4c
Author: Chris Hostetter <ho...@apache.org>
Authored: Thu Jul 6 09:33:20 2017 -0700
Committer: Chris Hostetter <ho...@apache.org>
Committed: Thu Jul 6 09:36:24 2017 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 +
 .../cloud/TestCloudJSONFacetJoinDomain.java     | 54 ++++++++++++++++----
 2 files changed, 45 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4816a1cb/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5a75c66..39c09a9 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -405,6 +405,8 @@ Other Changes
 * SOLR-10967: Cleanup the default configset. The changes involve some documentation corrections, removing the currency
   field from the examples and a few dynamic fields (Varun Thacker)
 
+* SOLR-11016: Fix TestCloudJSONFacetJoinDomain test-only bug (hossman)
+
 ==================  6.7.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4816a1cb/solr/core/src/test/org/apache/solr/cloud/TestCloudJSONFacetJoinDomain.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudJSONFacetJoinDomain.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudJSONFacetJoinDomain.java
index 1acf92e..e18312c 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestCloudJSONFacetJoinDomain.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudJSONFacetJoinDomain.java
@@ -23,6 +23,7 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -39,6 +40,7 @@ import org.apache.solr.client.solrj.impl.CloudSolrClient;
 import org.apache.solr.client.solrj.impl.HttpSolrClient;
 import org.apache.solr.client.solrj.request.CollectionAdminRequest;
 import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.params.ModifiableSolrParams;
@@ -243,7 +245,6 @@ public class TestCloudJSONFacetJoinDomain extends SolrCloudTestCase {
     }
   }
 
-  
   /** 
    * Test some small, hand crafted, but non-trivial queries that are
    * easier to trace/debug then a pure random monstrosity.
@@ -251,6 +252,30 @@ public class TestCloudJSONFacetJoinDomain extends SolrCloudTestCase {
    */
   public void testBespoke() throws Exception {
 
+    { // sanity check our test methods can handle a query matching no docs
+      Map<String,TermFacet> facets = new LinkedHashMap<>();
+      TermFacet top = new TermFacet(strfield(9), new JoinDomain(strfield(5), strfield(9), strfield(9)+":[* TO *]"));
+      top.subFacets.put("sub", new TermFacet(strfield(11), new JoinDomain(strfield(8), strfield(8), null)));
+      facets.put("empty_top", top);
+      assertFacetCountsAreCorrect(facets, strfield(7) + ":bogus");
+    }
+    
+    { // sanity check our test methods can handle a query where a facet filter prevents any doc from having terms
+      Map<String,TermFacet> facets = new LinkedHashMap<>();
+      TermFacet top = new TermFacet(strfield(9), new JoinDomain(null, null, "-*:*"));
+      top.subFacets.put("sub", new TermFacet(strfield(11), new JoinDomain(strfield(8), strfield(8), null)));
+      facets.put("filtered_top", top);
+      assertFacetCountsAreCorrect(facets, "*:*");
+    }
+    
+    { // sanity check our test methods can handle a query where a facet filter prevents any doc from having sub-terms
+      Map<String,TermFacet> facets = new LinkedHashMap<>();
+      TermFacet top = new TermFacet(strfield(9), new JoinDomain(strfield(8), strfield(8), null));
+      top.subFacets.put("sub", new TermFacet(strfield(11), new JoinDomain(null, null, "-*:*")));
+      facets.put("filtered_top", top);
+      assertFacetCountsAreCorrect(facets, "*:*");
+    }
+  
     { // strings
       Map<String,TermFacet> facets = new LinkedHashMap<>();
       TermFacet top = new TermFacet(strfield(9), new JoinDomain(strfield(5), strfield(9), strfield(9)+":[* TO *]"));
@@ -274,11 +299,8 @@ public class TestCloudJSONFacetJoinDomain extends SolrCloudTestCase {
       assertFacetCountsAreCorrect(facets, "("+strfield(7)+":6 OR "+strfield(9)+":6 OR "+strfield(6)+":19 OR "+strfield(0)+":11)");
 
     }
-
-    
   }
 
-  
   public void testRandom() throws Exception {
 
     final int numIters = atLeast(3);
@@ -320,21 +342,31 @@ public class TestCloudJSONFacetJoinDomain extends SolrCloudTestCase {
     final SolrParams initParams = SolrParams.wrapAppended(facetParams, baseParams);
     
     log.info("Doing full run: {}", initParams);
-    
-    NamedList topResponse = null;
+
+    QueryResponse rsp = null;
+    // JSON Facets not (currently) available from QueryResponse...
+    NamedList topNamedList = null;
     try {
-      topResponse = getRandClient(random()).request(new QueryRequest(initParams));
-      assertNotNull(initParams + " is null response?", topResponse);
+      rsp = (new QueryRequest(initParams)).process(getRandClient(random()));
+      assertNotNull(initParams + " is null rsp?", rsp);
+      topNamedList = rsp.getResponse();
+      assertNotNull(initParams + " is null topNamedList?", topNamedList);
     } catch (Exception e) {
       throw new RuntimeException("init query failed: " + initParams + ": " + 
                                  e.getMessage(), e);
     }
     try {
-      final NamedList facetResponse = (NamedList) topResponse.get("facets");
+      final NamedList facetResponse = (NamedList) topNamedList.get("facets");
       assertNotNull("null facet results?", facetResponse);
+      assertEquals("numFound mismatch with top count?",
+                   rsp.getResults().getNumFound(), ((Number)facetResponse.get("count")).longValue());
+      if (0 == rsp.getResults().getNumFound()) {
+        // when the query matches nothing, we should expect no top level facets
+        expected = Collections.emptyMap();
+      }
       assertFacetCountsAreCorrect(expected, baseParams, facetResponse);
     } catch (AssertionError e) {
-      throw new AssertionError(initParams + " ===> " + topResponse + " --> " + e.getMessage(), e);
+      throw new AssertionError(initParams + " ===> " + topNamedList + " --> " + e.getMessage(), e);
     } finally {
       log.info("Ending full run"); 
     }
@@ -373,7 +405,7 @@ public class TestCloudJSONFacetJoinDomain extends SolrCloudTestCase {
         }
       }
     }
-    assertTrue("facets have unexpeted keys left over: " + actualFacetResponse,
+    assertTrue("facets have unexpected keys left over: " + actualFacetResponse,
                // should alwasy be a count, maybe a 'val' if we're a subfacet
                (actualFacetResponse.size() == expected.size() + 1) ||
                (actualFacetResponse.size() == expected.size() + 2));