Github user dsmiley commented on a diff in the pull request: https://github.com/apache/lucene-solr/pull/455#discussion_r226709714 --- Diff: solr/core/src/test/org/apache/solr/update/processor/AtomicUpdateBlockTest.java --- @@ -59,39 +52,147 @@ public void before() { @Test public void testMergeChildDoc() throws Exception { - SolrInputDocument doc = new SolrInputDocument(); - doc.setField("id", "1"); - doc.setField("cat_ss", new String[]{"aaa", "ccc"}); - doc.setField("child", Collections.singletonList(sdoc("id", "2", "cat_ss", "child"))); + 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 testBlockAtomicQuantities() throws Exception { + SolrInputDocument doc = sdoc("id", "1", "string_s", "root"); addDoc(adoc(doc), "nested-rtg"); - BytesRef rootDocId = new BytesRef("1"); - SolrCore core = h.getCore(); - SolrInputDocument block = RealTimeGetComponent.getInputDocument(core, rootDocId, true); - // assert block doc has child docs - assertTrue(block.containsKey("child")); + 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")); - assertJQ(req("q","id:1") - ,"/response/numFound==0" + assertU(commit()); + + assertJQ(req("q", "_root_:1"), + "/response/numFound==11"); + + assertJQ(req("q", "string_s:child", "fl", "*", "rows", "1000000"), + "/response/numFound==10"); + + // ensure updates work when block has more than 10 children + for(int i = 10; i < 20; ++i) { + System.out.println("indexing " + 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()); + } + + assertJQ(req("q", "id:114", "fl", "*", "rows", "1000000"), --- End diff -- Why set the "fl" or "rows" in these queries? Your assertion only checks numFound and not the content of those that were found.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org