Skip to content

Commit 2cb737a

Browse files
georgeajitgeorgeajit
authored andcommitted
Git #690 #752 - JobId tests on QueryManager Jobs.
1 parent d9aa45d commit 2cb737a

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

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

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.marklogic.client.datamovement.functionaltests;
22

3-
import static org.junit.Assert.assertEquals;
3+
import static org.junit.Assert.*;
44

55
import java.io.File;
66
import java.io.IOException;
@@ -13,6 +13,7 @@
1313
import java.util.List;
1414
import java.util.Map;
1515
import java.util.Set;
16+
import java.util.UUID;
1617
import java.util.concurrent.TimeUnit;
1718
import java.util.concurrent.atomic.AtomicBoolean;
1819
import java.util.concurrent.atomic.AtomicInteger;
@@ -197,7 +198,11 @@ public void jobReport() throws Exception {
197198
AtomicLong count1 = new AtomicLong(0);
198199
AtomicLong count2 = new AtomicLong(0);
199200
AtomicLong count3 = new AtomicLong(0);
200-
QueryBatcher batcher = dmManager.newQueryBatcher(new StructuredQueryBuilder().collection("XmlTransform")).withBatchSize(500).withThreadCount(20);
201+
String jobId = UUID.randomUUID().toString();
202+
203+
QueryBatcher batcher = dmManager.newQueryBatcher(new StructuredQueryBuilder().collection("XmlTransform")).withBatchSize(500).withThreadCount(20)
204+
.withJobId(jobId).withJobName("XmlTransform");
205+
201206
batcher.onUrisReady(batch -> {
202207
System.out.println("Yes");
203208
if (dmManager.getJobReport(queryTicket).getSuccessBatchesCount() == batchCount.incrementAndGet()) {
@@ -206,6 +211,8 @@ public void jobReport() throws Exception {
206211
});
207212
batcher.onQueryFailure(throwable -> throwable.printStackTrace());
208213
queryTicket = dmManager.startJob(batcher);
214+
Assert.assertTrue("Job Id incorrect", jobId.equalsIgnoreCase(queryTicket.getJobId()));
215+
Assert.assertTrue("Job Name incorrect", batcher.getJobName().trim().equalsIgnoreCase("XmlTransform"));
209216
batcher.awaitCompletion(Long.MAX_VALUE, TimeUnit.DAYS);
210217
dmManager.stopJob(queryTicket);
211218

@@ -408,6 +415,52 @@ public void jobReportStopJob() throws Exception {
408415
Assert.assertTrue(batchCount.get() == dmManager.getJobReport(queryTicket).getSuccessBatchesCount());
409416

410417
}
418+
419+
// Making sure we can stop jobs based on the JobId.
420+
@Test
421+
public void stopJobUsingJobId() throws Exception {
422+
423+
String jobId = UUID.randomUUID().toString();
424+
425+
QueryBatcher batcher = dmManager.newQueryBatcher(new StructuredQueryBuilder().collection("XmlTransform"))
426+
.withBatchSize(20)
427+
.withThreadCount(20)
428+
.withJobId(jobId);
429+
430+
AtomicInteger batchCount = new AtomicInteger(0);
431+
432+
Set<String> uris = Collections.synchronizedSet(new HashSet<String>());
433+
434+
batcher.onUrisReady(batch -> {
435+
uris.addAll(Arrays.asList(batch.getItems()));
436+
batchCount.incrementAndGet();
437+
if (dmManager.getJobReport(queryTicket).getSuccessEventsCount() > 40) {
438+
// Using JobId here to stop Job
439+
dmManager.stopJob(dmManager.getActiveJob(jobId));
440+
}
441+
442+
});
443+
batcher.onQueryFailure(throwable -> throwable.printStackTrace());
444+
445+
queryTicket = dmManager.startJob(batcher);
446+
batcher.awaitCompletion(Long.MAX_VALUE, TimeUnit.DAYS);
447+
448+
queryTicket = dmManager.startJob(batcher);
449+
batcher.awaitCompletion(Long.MAX_VALUE, TimeUnit.DAYS);
450+
451+
System.out.println("Success event: " + dmManager.getJobReport(queryTicket).getSuccessEventsCount());
452+
System.out.println("Success batch: " + dmManager.getJobReport(queryTicket).getSuccessBatchesCount());
453+
System.out.println("Failure event: " + dmManager.getJobReport(queryTicket).getFailureEventsCount());
454+
System.out.println("Failure batch: " + dmManager.getJobReport(queryTicket).getFailureBatchesCount());
455+
456+
Assert.assertTrue(dmManager.getJobReport(queryTicket).getSuccessEventsCount() > 40);
457+
Assert.assertTrue(dmManager.getJobReport(queryTicket).getSuccessEventsCount() < 1000);
458+
Assert.assertTrue(dmManager.getJobReport(queryTicket).getFailureEventsCount() == 0);
459+
Assert.assertTrue(dmManager.getJobReport(queryTicket).getFailureBatchesCount() == 0);
460+
461+
Assert.assertTrue(batchCount.get() == dmManager.getJobReport(queryTicket).getSuccessBatchesCount());
462+
463+
}
411464

412465
@Test
413466
public void jsMasstransformReplace() throws Exception {

0 commit comments

Comments
 (0)