From d201cabd400d479b939b6301a7c89dfd0100e169 Mon Sep 17 00:00:00 2001 From: Rob Rudin Date: Fri, 18 Nov 2022 15:13:36 -0500 Subject: [PATCH] Enhanced test for bug 58069 --- .../client/test/rows/JoinDocTest.java | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/JoinDocTest.java b/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/JoinDocTest.java index 1cf58cc8a..d6d01a7e9 100644 --- a/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/JoinDocTest.java +++ b/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/JoinDocTest.java @@ -5,12 +5,18 @@ import com.marklogic.client.expression.PlanBuilder; import com.marklogic.client.row.RowRecord; import com.marklogic.client.test.Common; +import com.marklogic.client.type.CtsReferenceExpr; import org.junit.Test; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static org.junit.Assert.assertEquals; +/** + * Written for bug 58069; see that description for more information. + */ public class JoinDocTest extends AbstractOpticUpdateTest { @Test @@ -19,19 +25,32 @@ public void propertiesFragmentsShouldNotBeReturned() { return; } - final int docCount = 50; - - JSONDocumentManager mgr = Common.client.newJSONDocumentManager(); - DocumentWriteSet writeSet = mgr.newWriteSet(); - for (int i = 1; i <= docCount; i++) { - writeSet.add(newWriteOp("/acme/" + i + ".json", mapper.createObjectNode().put("hello", "world"))); - } - mgr.write(writeSet); - PlanBuilder.ModifyPlan plan = op .fromDocUris(op.cts.directoryQuery("/acme/")) .joinDoc(op.col("doc"), op.col("uri")); + verifyPropertiesFragmentsAreNotReturned(plan); + } + + /** + * Same as propertiesFragmentsShouldNotBeReturned, but uses fromLexicons so it can run against ML 10. + */ + @Test + public void propertiesFragmentShouldNotBeReturnedByFromLexicons() { + Map lexicons = new HashMap<>(); + lexicons.put("uri", op.cts.uriReference()); + + PlanBuilder.ModifyPlan plan = op.fromLexicons(lexicons, "", op.fragmentIdCol("fragmentId")) + .where(op.cts.directoryQuery("/acme/")) + .joinDoc(op.col("doc"), op.col("uri")); + + verifyPropertiesFragmentsAreNotReturned(plan); + } + + private void verifyPropertiesFragmentsAreNotReturned(PlanBuilder.ModifyPlan plan) { + final int docCount = 50; + writeDocs(docCount); + List rows = resultRows(plan); System.out.println(rows); assertEquals("If the actual count is double the expected count, then joinDoc is erroneously pulling back " + @@ -40,4 +59,13 @@ public void propertiesFragmentsShouldNotBeReturned() { "and we do not have a reliable way to reproduce it. Once it happens, it will happen reliably for awhile, " + "regardless of the number of URIs being returned by fromDocUris.", docCount, rows.size()); } + + private void writeDocs(int docCount) { + JSONDocumentManager mgr = Common.client.newJSONDocumentManager(); + DocumentWriteSet writeSet = mgr.newWriteSet(); + for (int i = 1; i <= docCount; i++) { + writeSet.add(newWriteOp("/acme/" + i + ".json", mapper.createObjectNode().put("hello", "world"))); + } + mgr.write(writeSet); + } }