Apache Lucene open-source search software
SOLR-14595: add AwaitsFix test to TestJsonFacetRefinement demonstrating problem, and work around to randomized testing in TestCloudJSONFacetSKGEquiv
Chris Hostetterfea6c1b9daa2
diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.java b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.javaindex cab7df4bdce..276dcb9f7b0 100644--- a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.java+++ b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.java@@ -307,7 +307,7 @@ public class TestCloudJSONFacetSKGEquiv extends SolrCloudTestCase {}}-+/*** Test some small, hand crafted, but non-trivial queries that are* easier to trace/debug then a pure random monstrosity.@@ -717,7 +717,7 @@ public class TestCloudJSONFacetSKGEquiv extends SolrCloudTestCase {final String facetField = randomFacetField(random());return new TermFacet(facetField,map("limit", randomLimitParam(random()),- "overrequest", randomOverrequestParam(random()),+ "overrequest", randomOverrequestParam(random(), sort),"prefix", randomPrefixParam(random(), facetField),"perSeg", randomPerSegParam(random()),"sort", sort,@@ -896,11 +896,25 @@ public class TestCloudJSONFacetSKGEquiv extends SolrCloudTestCase {/*** picks a random value for the "overrequest" param, biased in favor of interesting test cases.+ * <p>+ * <b>NOTE:</b> due to variations in overrequest behavior betewen <code>metod:enum<code> and other+ * processors (see <a href="https://issues.apache.org/jira/browse/SOLR-14595">SOLR-14595</a>) this+ * method takes in the "sort" param and returns a constant value of <code>0</code> if the sort is+ * <code>index asc</code> to ensure that the set of candidate buckets considered during merging+ * (and refinement) is consistent regardless of what processor is used (and/or what sort is used+ * on the parent facet)+ * </p>** @return a number to specify in the request, or null to specify nothing (trigger default behavior)* @see #UNIQUE_FIELD_VALS+ * @see <a href="https://issues.apache.org/jira/browse/SOLR-14595">SOLR-14595</a>*/- public static Integer randomOverrequestParam(final Random r) {+ public static Integer randomOverrequestParam(final Random r, final String sort) {++ if ("index asc".equals(sort)) {+ return 0; // test work around for SOLR-14595+ }+switch(r.nextInt(10)) {case 0:case 1:diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetRefinement.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetRefinement.javaindex 1112f0b21a3..babc91c364c 100644--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetRefinement.java+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetRefinement.java@@ -1472,4 +1472,47 @@ public class TestJsonFacetRefinement extends SolrTestCaseHS {} // end method loop}+ @AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/SOLR-14595")+ public void testIndexAscRefineConsistency() throws Exception {+ initServers();+ final Client client = servers.getClient(random().nextInt());+ client.queryDefaults().set("shards", servers.getShards(), "debugQuery", Boolean.toString(random().nextBoolean()));++ List<SolrClient> clients = client.getClientProvider().all();+ assertTrue(clients.size() >= 3);+ final SolrClient c0 = clients.get(0);+ final SolrClient c1 = clients.get(1);+ final SolrClient c2 = clients.get(2);++ client.deleteByQuery("*:*", null);+ int id = 0;++ c0.add(sdoc("id", id++, "cat_s", "Z", "price_i", 10));++ c1.add(sdoc("id", id++, "cat_s", "Z", "price_i", -5000));+ c1.add(sdoc("id", id++, "cat_s", "X", "price_i", 2, "child_s", "A" ));++ c2.add(sdoc("id", id++, "cat_s", "X", "price_i", 2, "child_s", "B" ));+ c2.add(sdoc("id", id++, "cat_s", "X", "price_i", 2, "child_s", "C" ));++ client.commit();++ // TODO once SOLR-14595 is fixed, modify test to check full EnumSet, not just these two...+ for (String m : Arrays.asList("smart", "enum")) {+ client.testJQ(params("q", "*:*", "rows", "0", "json.facet", "{"+ + " cat : { type:terms, field:cat_s, limit:1, refine:true,"+ + " overrequest:0, " // to trigger parent refinement given small data set+ + " sort:'sum desc', "+ + " facet: { sum : 'sum(price_i)', "+ + " child_"+m+" : { "+ + " type:terms, field:child_s, limit:1, refine:true,"+ + " sort:'index asc', method:" + m + " } "+ + " }} }"+ )+ , "facets=={ count:5"+ + ", cat:{buckets:[ { val:X, count:3, sum:6.0, "+ + " child_"+m+":{buckets:[{val:A, count:1}]}}]}}"+ );+ }+ }}