55import com .marklogic .client .expression .PlanBuilder ;
66import com .marklogic .client .row .RowRecord ;
77import com .marklogic .client .test .Common ;
8+ import com .marklogic .client .type .CtsReferenceExpr ;
89import org .junit .Test ;
910
11+ import java .util .HashMap ;
1012import java .util .List ;
13+ import java .util .Map ;
1114
1215import static org .junit .Assert .assertEquals ;
1316
17+ /**
18+ * Written for bug 58069; see that description for more information.
19+ */
1420public class JoinDocTest extends AbstractOpticUpdateTest {
1521
1622 @ Test
@@ -19,19 +25,32 @@ public void propertiesFragmentsShouldNotBeReturned() {
1925 return ;
2026 }
2127
22- final int docCount = 50 ;
23-
24- JSONDocumentManager mgr = Common .client .newJSONDocumentManager ();
25- DocumentWriteSet writeSet = mgr .newWriteSet ();
26- for (int i = 1 ; i <= docCount ; i ++) {
27- writeSet .add (newWriteOp ("/acme/" + i + ".json" , mapper .createObjectNode ().put ("hello" , "world" )));
28- }
29- mgr .write (writeSet );
30-
3128 PlanBuilder .ModifyPlan plan = op
3229 .fromDocUris (op .cts .directoryQuery ("/acme/" ))
3330 .joinDoc (op .col ("doc" ), op .col ("uri" ));
3431
32+ verifyPropertiesFragmentsAreNotReturned (plan );
33+ }
34+
35+ /**
36+ * Same as propertiesFragmentsShouldNotBeReturned, but uses fromLexicons so it can run against ML 10.
37+ */
38+ @ Test
39+ public void propertiesFragmentShouldNotBeReturnedByFromLexicons () {
40+ Map <String , CtsReferenceExpr > lexicons = new HashMap <>();
41+ lexicons .put ("uri" , op .cts .uriReference ());
42+
43+ PlanBuilder .ModifyPlan plan = op .fromLexicons (lexicons , "" , op .fragmentIdCol ("fragmentId" ))
44+ .where (op .cts .directoryQuery ("/acme/" ))
45+ .joinDoc (op .col ("doc" ), op .col ("uri" ));
46+
47+ verifyPropertiesFragmentsAreNotReturned (plan );
48+ }
49+
50+ private void verifyPropertiesFragmentsAreNotReturned (PlanBuilder .ModifyPlan plan ) {
51+ final int docCount = 50 ;
52+ writeDocs (docCount );
53+
3554 List <RowRecord > rows = resultRows (plan );
3655 System .out .println (rows );
3756 assertEquals ("If the actual count is double the expected count, then joinDoc is erroneously pulling back " +
@@ -40,4 +59,13 @@ public void propertiesFragmentsShouldNotBeReturned() {
4059 "and we do not have a reliable way to reproduce it. Once it happens, it will happen reliably for awhile, " +
4160 "regardless of the number of URIs being returned by fromDocUris." , docCount , rows .size ());
4261 }
62+
63+ private void writeDocs (int docCount ) {
64+ JSONDocumentManager mgr = Common .client .newJSONDocumentManager ();
65+ DocumentWriteSet writeSet = mgr .newWriteSet ();
66+ for (int i = 1 ; i <= docCount ; i ++) {
67+ writeSet .add (newWriteOp ("/acme/" + i + ".json" , mapper .createObjectNode ().put ("hello" , "world" )));
68+ }
69+ mgr .write (writeSet );
70+ }
4371}
0 commit comments