dsmiley commented on a change in pull request #455: SOLR-12638
URL: https://github.com/apache/lucene-solr/pull/455#discussion_r270096287
 
 

 ##########
 File path: 
solr/core/src/test/org/apache/solr/update/processor/NestedAtomicUpdateTest.java
 ##########
 @@ -0,0 +1,659 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.update.processor;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import org.apache.lucene.util.BytesRef;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.SolrInputField;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.handler.component.RealTimeGetComponent;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class NestedAtomicUpdateTest extends SolrTestCaseJ4 {
+
+  private final static String VERSION = "_version_";
+
+  @BeforeClass
+  public static void beforeTests() throws Exception {
+    initCore("solrconfig-block-atomic-update.xml", "schema-nest.xml"); // use 
"nest" schema
+  }
+
+  @Before
+  public void before() {
+    clearIndex();
+    assertU(commit());
+  }
+
+  @Test
+  public void testMergeChildDoc() throws Exception {
+    SolrInputDocument newChildDoc = sdoc("id", "3", "cat_ss", "child");
+    SolrInputDocument addedDoc = sdoc("id", "1",
+        "cat_ss", Collections.singletonMap("add", "bbb"),
+        "child", Collections.singletonMap("add", sdocs(newChildDoc)));
+
+    SolrInputDocument dummyBlock = sdoc("id", "1",
+        "cat_ss", new ArrayList<>(Arrays.asList("aaa", "ccc")),
+        "_root_", "1", "child", new ArrayList<>(sdocs(addedDoc)));
+    dummyBlock.removeField(VERSION);
+
+    SolrInputDocument preMergeDoc = new SolrInputDocument(dummyBlock);
+    AtomicUpdateDocumentMerger docMerger = new 
AtomicUpdateDocumentMerger(req());
+    docMerger.merge(addedDoc, dummyBlock);
+    assertEquals("merged document should have the same id", 
preMergeDoc.getFieldValue("id"), dummyBlock.getFieldValue("id"));
+    assertDocContainsSubset(preMergeDoc, dummyBlock);
+    assertDocContainsSubset(addedDoc, dummyBlock);
+    assertDocContainsSubset(newChildDoc, (SolrInputDocument) ((List) 
dummyBlock.getFieldValues("child")).get(1));
+    assertEquals(dummyBlock.getFieldValue("id"), 
dummyBlock.getFieldValue("id"));
+  }
+
+  @Test
+  public void testBlockAtomicInplaceUpdates() throws Exception {
+    SolrInputDocument doc = sdoc("id", "1", "string_s", "root");
+    addDoc(adoc(doc), "nested-rtg");
+
+    assertU(commit());
+
+    assertQ(req("q", "id:1", "fl", "*"),
+        "//*[@numFound='1']",
+        "//doc[1]/str[@name='id']=1"
+    );
+
+    List<SolrInputDocument> docs = IntStream.range(10, 20).mapToObj(x -> 
sdoc("id", String.valueOf(x), "string_s",
+        "child", "inplace_updatable_int", "0")).collect(Collectors.toList());
+    doc = sdoc("id", "1", "children", Collections.singletonMap("add", docs));
+    addAndGetVersion(doc, params("update.chain", "nested-rtg", "wt", "json", 
"_route_", "1"));
+
+    assertU(commit());
+
+
+    assertQ(req("q", "_root_:1", "fl", "*", "rows", "11"),
+        "//*[@numFound='11']"
+    );
+
+    assertQ(req("q", "string_s:child", "fl", "*"),
+        "//*[@numFound='10']",
+        "*[count(//str[@name='string_s'][.='child'])=10]"
+    );
+
+    for(int i = 10; i < 20; ++i) {
+      doc = sdoc("id", String.valueOf(i), "inplace_updatable_int", 
Collections.singletonMap("inc", "1"));
+      addAndGetVersion(doc, params("update.chain", "nested-rtg", "wt", "json", 
"_route_", "1"));
+      assertU(commit());
+    }
+
+    for(int i = 10; i < 20; ++i) {
+      doc = sdoc("id", String.valueOf(i), "inplace_updatable_int", 
Collections.singletonMap("inc", "1"));
+      addAndGetVersion(doc, params("update.chain", "nested-rtg", "wt", "json", 
"_route_", "1"));
+      assertU(commit());
+    }
+
+    // ensure updates work when block has more than 10 children
+    for(int i = 10; i < 20; ++i) {
+      docs = IntStream.range(i * 10, (i * 10) + 5).mapToObj(x -> sdoc("id", 
String.valueOf(x), "string_s", "grandChild")).collect(Collectors.toList());
+      doc = sdoc("id", String.valueOf(i), "grandChildren", 
Collections.singletonMap("add", docs));
+      addAndGetVersion(doc, params("update.chain", "nested-rtg", "wt", "json", 
"_route_", "1"));
+      assertU(commit());
+    }
+
+    for(int i =10; i < 20; ++i) {
+      doc = sdoc("id", String.valueOf(i), "inplace_updatable_int", 
Collections.singletonMap("inc", "1"));
+      addAndGetVersion(doc, params("update.chain", "nested-rtg", "wt", "json", 
"_route_", "1"));
+      assertU(commit());
+    }
+
+    assertQ(req("q", "-_root_:*", "fl", "*"),
+        "//*[@numFound='0']"
+    );
+
+    assertQ(req("q", "string_s:grandChild", "fl", "*", "rows", "50"),
+        "//*[@numFound='50']"
+    );
+
+    assertQ(req("q", "string_s:child", "fl", "*"),
+        "//*[@numFound='10']",
+        "*[count(//str[@name='string_s'][.='child'])=10]");
+
+    assertJQ(req("q", "id:1", "fl", "*,[child limit=-1]"),
+        "/response/docs/[0]/id=='1'",
+        "/response/docs/[0]/children/[0]/id=='10'",
+        "/response/docs/[0]/children/[0]/inplace_updatable_int==3",
+        "/response/docs/[0]/children/[0]/grandChildren/[0]/id=='100'",
+        "/response/docs/[0]/children/[0]/grandChildren/[4]/id=='104'",
+        "/response/docs/[0]/children/[9]/id=='19'"
+    );
+
+  }
+
+  @Test
+  public void testBlockAtomicQuantities() throws Exception {
+    SolrInputDocument doc = sdoc("id", "1", "string_s", "root");
+    addDoc(adoc(doc), "nested-rtg");
+
+    assertU(commit());
+
+    assertQ(req("q", "id:1", "fl", "*"),
+        "//*[@numFound='1']",
+        "//doc[1]/str[@name='id']=1"
+    );
+
+    List<SolrInputDocument> docs = IntStream.range(10, 20).mapToObj(x -> 
sdoc("id", String.valueOf(x), "string_s", 
"child")).collect(Collectors.toList());
+    doc = sdoc("id", "1", "children", Collections.singletonMap("add", docs));
+    addAndGetVersion(doc, params("update.chain", "nested-rtg", "wt", "json"));
+
+    assertU(commit());
+
+
+    assertQ(req("q", "_root_:1", "fl", "*", "rows", "11"),
+        "//*[@numFound='11']",
+        "*[count(//str[@name='_root_'][.='1'])=11]"
+    );
+
+    assertQ(req("q", "string_s:child", "fl", "*"),
+        "//*[@numFound='10']",
+        "*[count(//str[@name='string_s'][.='child'])=10]"
+    );
+
+    // ensure updates work when block has more than 10 children
+    for(int i = 10; i < 20; ++i) {
+      docs = IntStream.range(i * 10, (i * 10) + 5).mapToObj(x -> sdoc("id", 
String.valueOf(x), "string_s", "grandChild")).collect(Collectors.toList());
+      doc = sdoc("id", String.valueOf(i), "grandChildren", 
Collections.singletonMap("add", docs));
+      addAndGetVersion(doc, params("update.chain", "nested-rtg", "wt", 
"json"));
+      assertU(commit());
+    }
+
+    assertQ(req("q", "string_s:grandChild", "fl", "*", "rows", "50"),
+        "//*[@numFound='50']",
+        "*[count(//str[@name='string_s'][.='grandChild'])=50]");
+
+    assertQ(req("q", "string_s:child", "fl", "*"),
+        "//*[@numFound='10']",
+        "*[count(//str[@name='string_s'][.='child'])=10]");
+  }
+
+  @Test
+  public void testBlockAtomicStack() throws Exception {
+    SolrInputDocument doc = sdoc("id", "1", "child1", sdocs(sdoc("id", "2", 
"child_s", "child")));
+    addDoc(adoc(doc), "nested-rtg");
+
+    assertU(commit());
+
+    assertJQ(req("q","id:1", "fl", "*, [child]"),
+        "/response/numFound==1",
+        "/response/docs/[0]/child1/[0]/id=='2'",
+        "/response/docs/[0]/child1/[0]/child_s=='child'"
+    );
+
+    doc = sdoc("id", "1", "child1", Collections.singletonMap("add", 
sdocs(sdoc("id", "3", "child_s", "child"))));
+    addAndGetVersion(doc, params("update.chain", "nested-rtg", "wt", "json"));
+
+    assertU(commit());
+
+    assertJQ(req("q","id:1", "fl", "*, [child]"),
+        "/response/numFound==1",
+        "/response/docs/[0]/child1/[0]/id=='2'",
+        "/response/docs/[0]/child1/[0]/child_s=='child'",
+        "/response/docs/[0]/child1/[1]/id=='3'",
+        "/response/docs/[0]/child1/[0]/child_s=='child'"
+    );
+
+    doc = sdoc("id", "2",
+        "grandChild", Collections.singletonMap("add", sdocs(sdoc("id", "4", 
"child_s", "grandChild"), sdoc("id", "5", "child_s", "grandChild"))));
+    addAndGetVersion(doc, params("update.chain", "nested-rtg", "wt", "json"));
+
+    assertU(commit());
+
+    assertJQ(req("q","id:1", "fl", "*, [child]", "sort", "id asc"),
+        "/response/numFound==1",
+        "/response/docs/[0]/id=='1'",
+        "/response/docs/[0]/child1/[0]/id=='2'",
+        "/response/docs/[0]/child1/[0]/child_s=='child'",
+        "/response/docs/[0]/child1/[1]/id=='3'",
+        "/response/docs/[0]/child1/[1]/child_s=='child'",
+        "/response/docs/[0]/child1/[0]/grandChild/[0]/id=='4'",
+        "/response/docs/[0]/child1/[0]/grandChild/[0]/child_s=='grandChild'"
+    );
+
+    doc = sdoc("id", "1",
+        "child2", Collections.singletonMap("add", sdocs(sdoc("id", "8", 
"child_s", "child"))));
+    addAndGetVersion(doc, params("update.chain", "nested-rtg", "wt", "json"));
+
+    assertU(commit());
+
+    assertJQ(req("q","id:1", "fl", "*, [child]", "sort", "id asc"),
+        "/response/numFound==1",
+        "/response/docs/[0]/id=='1'",
+        "/response/docs/[0]/child1/[0]/id=='2'",
+        "/response/docs/[0]/child1/[0]/child_s=='child'",
+        "/response/docs/[0]/child1/[1]/id=='3'",
+        "/response/docs/[0]/child1/[1]/child_s=='child'",
+        "/response/docs/[0]/child1/[0]/grandChild/[0]/id=='4'",
+        "/response/docs/[0]/child1/[0]/grandChild/[0]/child_s=='grandChild'",
+        "/response/docs/[0]/child2/[0]/id=='8'",
+        "/response/docs/[0]/child2/[0]/child_s=='child'"
+    );
+
+    doc = sdoc("id", "1",
+        "new_s", Collections.singletonMap("add", "new string"));
+    addAndGetVersion(doc, params("update.chain", "nested-rtg", "wt", "json"));
+
+    assertU(commit());
+
+    // ensure the whole block has been committed correctly to the index.
+    assertJQ(req("q","id:1", "fl", "*, [child]"),
+        "/response/numFound==1",
+        "/response/docs/[0]/id=='1'",
+        "/response/docs/[0]/child1/[0]/id=='2'",
+        "/response/docs/[0]/child1/[0]/child_s=='child'",
+        "/response/docs/[0]/child1/[1]/id=='3'",
+        "/response/docs/[0]/child1/[1]/child_s=='child'",
+        "/response/docs/[0]/child1/[0]/grandChild/[0]/id=='4'",
+        "/response/docs/[0]/child1/[0]/grandChild/[0]/child_s=='grandChild'",
+        "/response/docs/[0]/child1/[0]/grandChild/[1]/id=='5'",
+        "/response/docs/[0]/child1/[0]/grandChild/[1]/child_s=='grandChild'",
+        "/response/docs/[0]/new_s=='new string'",
+        "/response/docs/[0]/child2/[0]/id=='8'",
+        "/response/docs/[0]/child2/[0]/child_s=='child'"
+    );
+
+  }
+
+  @Test
+  public void testBlockAtomicAdd() throws Exception {
+
+    SolrInputDocument doc = sdoc("id", "1",
+        "cat_ss", new String[] {"aaa", "ccc"},
+        "child1", sdoc("id", "2", "cat_ss", "child")
+    );
+    addDoc(adoc(doc), "nested-rtg");
 
 Review comment:
   I believe this is outdated -- Nested URP is already in the default chain

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to