@Override public void initialize() { writeBatcher = this.dataMovementManager.newWriteBatcher(); writeBatcher.withThreadCount(threadCount); writeBatcher.withBatchSize(batchSize); jobTicket = dataMovementManager.startJob(writeBatcher); }
.newWriteBatcher() .withJobName("Load jobs") .withBatchSize(50); JobTicket ticket = dmm.startJob(writer);
public static void setup() throws Exception { StringBuffer failures = new StringBuffer(); WriteBatcher writeBatcher = moveMgr.newWriteBatcher() .withBatchSize(10) .onBatchFailure((event, throwable) -> { throwable.printStackTrace(); failures.append("ERORR:[" + throwable.toString() + "]"); }); moveMgr.startJob(writeBatcher); // a collection so we're only looking at docs related to this test run DocumentMetadataHandle meta = new DocumentMetadataHandle().withCollections(collection); for ( int i=1; i <= numDocs; i++ ) { writeBatcher.addAs(collection + "/doc_" + i + ".txt", meta, "test contents"); } writeBatcher.flushAsync(); writeBatcher.awaitCompletion(); if ( failures.length() > 0 ) fail(failures.toString()); logger.info("Successfully wrote {} docs to collection {}", numDocs, collection); }
public void testExceptions(WriteBatcher writeBatcher, DocumentWriteSet docs, int expectedSuccesses, int expectedFailures) { final AtomicInteger successfulBatchCount = new AtomicInteger(0); final AtomicInteger failureBatchCount = new AtomicInteger(0); writeBatcher .withBatchSize(1) .onBatchSuccess( batch -> successfulBatchCount.incrementAndGet() ) .onBatchFailure( (batch, throwable) -> failureBatchCount.incrementAndGet() ); moveMgr.startJob(writeBatcher); for ( DocumentWriteOperation doc : docs ) { writeBatcher.add(doc.getUri(), doc.getContent()); } // while batchSize=1 means all batches are queued, we still need to wait for them to finish writeBatcher.flushAndWait(); moveMgr.stopJob(writeBatcher); assertEquals(expectedSuccesses, successfulBatchCount.get()); assertEquals(expectedFailures, failureBatchCount.get()); }
public OurJbossESBPlugin(DatabaseClient client) { moveMgr = client.newDataMovementManager(); batcher = moveMgr.newWriteBatcher() .withJobName("OurJbossESBPlugin") .withBatchSize(BATCH_SIZE) // every time a batch is full, write it to the database via mlcp // this is the default, only included here to make it obvious //.onBatchFull( new MlcpBatchFullListener() ) // log a summary report after each successful batch .onBatchSuccess( batch -> logger.info(getSummaryReport()) ) .onBatchFailure( (batch, throwable) -> { List<String> uris = new ArrayList<>(); for ( WriteEvent event : batch.getItems() ) { uris.add(event.getTargetUri()); } logger.warn("FAILURE on batch:" + uris + "\n", throwable); }); ticket = moveMgr.startJob(batcher); }
@Ignore public void testIssue646() throws Exception { WriteBatcher ihb2 = moveMgr.newWriteBatcher() .withBatchSize(10); ihb2.onBatchFailure( (batch, throwable) -> throwable.printStackTrace() ); for (int j =0 ;j < 21; j++){ String uri ="/local/string-"+ j; DocumentMetadataHandle meta6 = new DocumentMetadataHandle().withProperty("docMeta-1", "true"); ihb2.addAs(uri , meta6, "test"); } ihb2.flushAndWait(); }
.withBatchSize(1) .onBatchSuccess(new CloseBatchListener()) .onBatchFailure(new CloseFailureListener());
String query1 = "fn:count(fn:collection('" + collection + "'))"; WriteBatcher batcher = moveMgr.newWriteBatcher(); batcher.withBatchSize(120); batcher .onBatchSuccess( batch -> {
batcher.withBatchSize(1).withTransform(runFlow); batcher.onBatchSuccess(batch -> { }).onBatchFailure((batch, throwable) -> {
@Test public void testZeros() throws Exception { try { WriteBatcher batcher = moveMgr.newWriteBatcher() .withBatchSize(0); fail("should have thrown IllegalArgumentException because batchSize must be > 1"); } catch(IllegalArgumentException e) {} try { WriteBatcher batcher = moveMgr.newWriteBatcher() .withThreadCount(0); fail("should have thrown IllegalArgumentException because threadCount must be > 1"); } catch(IllegalArgumentException e) {} }
String query1 = "fn:count(fn:collection('" + collection + "'))"; WriteBatcher batcher = moveMgr.newWriteBatcher(); batcher.withBatchSize(100); batcher.onBatchSuccess( batch -> {
StringBuilder failureBatch = new StringBuilder(); WriteBatcher ihb1 = moveMgr.newWriteBatcher() .withBatchSize(1) .onBatchSuccess( batch -> {
.withBatchSize(10) .withForestConfig(ffg) .onBatchSuccess( batch -> {
String collection = whbTestCollection + ".testUndeclaredFormat_Issue60"; WriteBatcher batcher = moveMgr.newWriteBatcher(); batcher.withBatchSize(1); final AtomicInteger successfulCount = new AtomicInteger(0); batcher.onBatchSuccess(
.withBatchSize(100) .onBatchFailure((batch, throwable) -> throwable.printStackTrace()); JobTicket ticket1 = moveMgr.startJob( batcher1 );
.withBatchSize(100) .withThreadCount(4) .onBatchSuccess(batch -> installDocsFinished = true)
public static void setup() throws Exception { assertEquals( "Since the doc doesn't exist, documentManager.exists() should return null", null, client.newDocumentManager().exists(collection + "/doc_1.json") ); WriteBatcher writeBatcher = moveMgr.newWriteBatcher() .withBatchSize(100); moveMgr.startJob(writeBatcher); // a collection so we're only looking at docs related to this test DocumentMetadataHandle meta = new DocumentMetadataHandle() .withCollections(collection, qhbTestCollection); for ( int i=1; i <= numDocs; i++ ) { writeBatcher.addAs(collection + "/doc_" + i + ".json", meta, new StringHandle("{name:\"John Doe\",dept:\"HR\"}").withFormat(JSON)); } writeBatcher.flushAsync(); writeBatcher.awaitCompletion(); }
WriteBatcher batcher = dataMovementManager.newWriteBatcher(); batcher .withBatchSize(10) .withThreadCount(4) .withTransform(runFlow)
.withBatchSize(100) .withThreadCount(4) .onBatchSuccess(batch -> installDocsFinished = true)
@Test public void testWriteBatcher() { assertEquals(null, client.newDocumentManager().exists("doc1.txt")); assertEquals(null, client.newDocumentManager().exists("doc2.txt")); // begin copy from "Using WriteBatcher" in src/main/java/com/marklogic/datamovement/package-info.java WriteBatcher whb = dataMovementManager.newWriteBatcher() .withBatchSize(100) .withThreadCount(20) .onBatchSuccess(batch -> { logger.debug("batch # {}, so far: {}", batch.getJobBatchNumber(), batch.getJobWritesSoFar()); }) .onBatchFailure((batch,throwable) -> throwable.printStackTrace() ); JobTicket ticket = dataMovementManager.startJob(whb); // the add or addAs methods could be called in separate threads on the // single whb instance whb.add ("doc1.txt", new StringHandle("doc1 contents")); whb.addAs("doc2.txt", "doc2 contents"); whb.flushAndWait(); // send the two docs even though they're not a full batch dataMovementManager.stopJob(ticket); // end copy from "Using WriteBatcher" in src/main/java/com/marklogic/datamovement/package-info.java assertTrue(null != client.newDocumentManager().exists("doc1.txt")); assertTrue(null != client.newDocumentManager().exists("doc2.txt")); } }