You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2018/08/29 17:37:38 UTC

lucene-solr:branch_7x: SOLR-12519: fix testGrandChildFilterJSON Simplified differentiating random docs we don't care about from those we do by using IDs less than 0

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 9fcd4929d -> bcbdeedba


SOLR-12519: fix testGrandChildFilterJSON
Simplified differentiating random docs we don't care about from those we do by using IDs less than 0

(cherry picked from commit cae91b1eaf15d15f5cd6db792b33df5a26d6f2bc)


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

Branch: refs/heads/branch_7x
Commit: bcbdeedbad507c99ce5a8d8756ebda40de0779e8
Parents: 9fcd492
Author: David Smiley <ds...@apache.org>
Authored: Wed Aug 29 13:35:42 2018 -0400
Committer: David Smiley <ds...@apache.org>
Committed: Wed Aug 29 13:37:31 2018 -0400

----------------------------------------------------------------------
 .../TestChildDocTransformerHierarchy.java       | 31 ++++++++++----------
 1 file changed, 16 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bcbdeedb/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java b/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java
index f207166..b3d9372 100644
--- a/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java
+++ b/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java
@@ -30,6 +30,7 @@ import org.apache.solr.common.SolrException;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.response.BasicResultContext;
 import org.junit.After;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -43,14 +44,14 @@ public class TestChildDocTransformerHierarchy extends SolrTestCaseJ4 {
   private static final String[] fieldsToRemove = {"_nest_parent_", "_nest_path_", "_root_"};
   private static final int sumOfDocsPerNestedDocument = 8;
   private static final int numberOfDocsPerNestedTest = 10;
-  private static int firstTestedDocId = 0;
-  private static String fqToExcludeNonTestedDocs; // filter documents that were created for random segments to ensure the transformer works with multiple segments.
+  private static final String fqToExcludeNonTestedDocs = "{!frange l=0}id_i"; // filter documents that were created for random segments to ensure the transformer works with multiple segments.
 
   @BeforeClass
   public static void beforeClass() throws Exception {
     initCore("solrconfig-update-processor-chains.xml", "schema-nest.xml"); // use "nest" schema
-    final boolean useSegments = random().nextBoolean();
-    if(useSegments) {
+
+    if(random().nextBoolean()) {
+      idCounter.set(-100); // start docIDs at -100 for these random docs we don't care about (all less than 0)
       // create random segments
       final int numOfDocs = 10;
       for(int i = 0; i < numOfDocs; ++i) {
@@ -60,18 +61,18 @@ public class TestChildDocTransformerHierarchy extends SolrTestCaseJ4 {
         }
       }
       assertU(commit());
-      fqToExcludeNonTestedDocs = "{!frange l=" + firstTestedDocId + " incl=false}id_i";
-    } else {
-      fqToExcludeNonTestedDocs = "*:*";
     }
-    firstTestedDocId = idCounter.get();
+  }
+
+  @Before
+  public void before() {
+    idCounter.set(0); // reset idCounter
   }
 
   @After
   public void after() throws Exception {
     assertU(delQ(fqToExcludeNonTestedDocs));
     assertU(commit());
-    idCounter.set(firstTestedDocId); // reset idCounter
   }
 
   @Test
@@ -333,7 +334,7 @@ public class TestChildDocTransformerHierarchy extends SolrTestCaseJ4 {
   }
 
   private static String grandChildDocTemplate(int id) {
-    final int docNum = (id - firstTestedDocId) / sumOfDocsPerNestedDocument; // the index of docs sent to solr in the AddUpdateCommand. e.g. first doc is 0
+    final int docNum = id / sumOfDocsPerNestedDocument; // the index of docs sent to solr in the AddUpdateCommand. e.g. first doc is 0
     return
         "SolrDocument{id="+ id + ", type_s=" + types[docNum % types.length] + ", name_s=" + names[docNum % names.length] + ", " +
           "toppings=[" +
@@ -344,7 +345,7 @@ public class TestChildDocTransformerHierarchy extends SolrTestCaseJ4 {
   }
 
   private static String fullNestedDocTemplate(int id) {
-    final int docNum = (id - firstTestedDocId) / sumOfDocsPerNestedDocument; // the index of docs sent to solr in the AddUpdateCommand. e.g. first doc is 0
+    final int docNum = id / sumOfDocsPerNestedDocument; // the index of docs sent to solr in the AddUpdateCommand. e.g. first doc is 0
     boolean doubleIngredient = docNum % 2 == 0;
     String currIngredient = doubleIngredient ? ingredients[1]: ingredientsCycler.next();
     return
@@ -358,16 +359,16 @@ public class TestChildDocTransformerHierarchy extends SolrTestCaseJ4 {
               "ingredients=[SolrDocument{id=" + (id + 6) + ", name_s=cocoa}, SolrDocument{id=" + (id + 7) + ", name_s=cocoa}]}]}";
   }
 
-  private static String generateDocHierarchy(int i) {
-    boolean doubleIngredient = i % 2 == 0;
+  private static String generateDocHierarchy(int sequence) {
+    boolean doubleIngredient = sequence % 2 == 0;
     String currIngredient = doubleIngredient ? ingredients[1]: ingredientsCycler.next();
     return "{\n" +
               "\"add\": {\n" +
                 "\"doc\": {\n" +
                   "\"id\": " + id() + ", \n" +
-                  "\"type_s\": \"" + types[i % types.length] + "\", \n" +
+                  "\"type_s\": \"" + types[sequence % types.length] + "\", \n" +
                   "\"lonely\": {\"id\": " + id() + ", \"test_s\": \"testing\", \"lonelyGrandChild\": {\"id\": " + id() + ", \"test2_s\": \"secondTest\"}}, \n" +
-                  "\"name_s\": " + names[i % names.length] +
+                  "\"name_s\": " + names[sequence % names.length] +
                   "\"toppings\": [ \n" +
                     "{\"id\": " + id() + ", \"type_s\":\"Regular\"," +
                       "\"ingredients\": [{\"id\": " + id() + "," +