Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String, CtsReferenceExpr> 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<RowRecord> rows = resultRows(plan);
System.out.println(rows);
assertEquals("If the actual count is double the expected count, then joinDoc is erroneously pulling back " +
Expand All @@ -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);
}
}