Skip to content

Commit feb8cbe

Browse files
committed
Adding few changes for setMaxUris and in the unit test.
1 parent 97350f0 commit feb8cbe

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/QueryBatcherJobReportTest.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -714,10 +714,9 @@ public void run() {
714714
}
715715
}
716716

717-
JobTicket jobTicket = dmManager.startJob(qb);
717+
dmManager.startJob(qb);
718718

719-
Thread tMBStop;
720-
tMBStop = new Thread(new MaxBatchesThread());
719+
Thread tMBStop = new Thread(new MaxBatchesThread());
721720

722721
tMBStop.start();
723722
tMBStop.join();
@@ -735,7 +734,7 @@ public void run() {
735734
Collection<String> batchResults2 = new LinkedHashSet<String>();
736735
QueryBatcher qb2 = dmManager.newQueryBatcher(urisList.iterator())
737736
.withBatchSize(12)
738-
.withThreadCount(1)
737+
.withThreadCount(20)
739738
.withJobId("ListenerCompletionTest2")
740739
.onUrisReady((QueryBatch batch) -> {
741740

@@ -747,25 +746,32 @@ public void run() {
747746
.onQueryFailure(throwable-> {
748747
failedBatch2.addAndGet(1);
749748
});
750-
749+
qb2.setMaxBatches(203);
751750
class BatchesSoFarThread implements Runnable {
752751

753752
@Override
754753
public void run() {
755754
// Test 2
755+
try {
756+
Thread.sleep(1000);
757+
} catch (InterruptedException e) {
758+
e.printStackTrace();
759+
}
756760
qb2.setMaxBatches();
757761
}
758762
}
759763

760-
JobTicket jobTicket2 = dmManager.startJob(qb2);
761-
762-
Thread tMBStop2;
763-
tMBStop2 = new Thread(new BatchesSoFarThread());
764+
dmManager.startJob(qb2);
764765

766+
Thread tMBStop2 = new Thread(new BatchesSoFarThread());
767+
int initialUrisSize = batchResults2.size();
768+
765769
tMBStop2.start();
766-
tMBStop2.join();
767-
System.out.println("URI size so far is : " + batchResults2.size());
768-
assertTrue("Batches of URIs collected so far", batchResults.size() > 0);
770+
qb2.awaitCompletion();
771+
dmManager.stopJob(qb2);
772+
773+
assertTrue("Batches of URIs collected so far", batchResults2.size() > 0);
774+
assertTrue("Number of Uris collected does not fall in the range", (batchResults2.size()>initialUrisSize && batchResults2.size()< 50000));
769775
}
770776
catch (Exception ex) {
771777
ex.printStackTrace();

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/impl/QueryBatcherImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@ public long getMaxBatches() {
10531053
@Override
10541054
public void setMaxBatches() {
10551055
this.maxBatches = -1L;
1056-
1056+
if(isStarted())
1057+
setMaxUris(getMaxBatches());
10571058
}
10581059
}

0 commit comments

Comments
 (0)