public void testExceptions(DocumentWriteSet docs, int expectedSuccesses, int expectedFailures) { WriteBatcher batcher = moveMgr.newWriteBatcher() .onBatchSuccess( batch -> { throw new InternalError(errorMessage); } ) .onBatchFailure( (batch, throwable) -> { throw new InternalError(errorMessage); } ); testExceptions(batcher, docs, expectedSuccesses, expectedFailures); batcher = moveMgr.newWriteBatcher() .onBatchSuccess( batch -> { throw new RuntimeException(errorMessage); } ) .onBatchFailure( (batch, throwable) -> { throw new RuntimeException(errorMessage); } ); testExceptions(batcher, docs, expectedSuccesses, expectedFailures); cleanupDocs(docs); }
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());
@Test public void testCloseHandles() throws Exception { DocumentMetadataHandle meta = new DocumentMetadataHandle() .withCollections(whbTestCollection); final AtomicInteger failCount = new AtomicInteger(0); WriteBatcher batcher = moveMgr.newWriteBatcher() .onBatchFailure( (batch, throwable) -> { logger.error("Error in testCloseHandles", throwable); failCount.incrementAndGet(); } ); JobTicket ticket = moveMgr.startJob(batcher); AtomicBoolean closed = new AtomicBoolean(false); FileInputStream fileStream = new FileInputStream("src/test/resources/test.xml") { public void close() throws IOException { super.close(); closed.set(true); } }; batcher.add("test.xml", meta, new InputStreamHandle(fileStream)); // when we call flushAndWait, the WriteBatcher should write the batch the close all the handles batcher.flushAndWait(); assertEquals(true, closed.get()); moveMgr.stopJob(ticket); assertEquals(0, failCount.get()); }
.onBatchFailure( (batch, throwable) -> { throwable.printStackTrace(); System.out.println("Failure Batch size "+batch.getItems().length);
batcher.withBatchSize(1).withTransform(runFlow); batcher.onBatchSuccess(batch -> { }).onBatchFailure((batch, throwable) -> { throw new RuntimeException(throwable); });
batcher.onBatchFailure( (batch, throwable) -> { throwable.printStackTrace();
.onBatchFailure( (batch, throwable) -> { for(WriteEvent w: batch.getItems()){
.onBatchFailure( (batch, throwable) -> throwable.printStackTrace() ); for (int j =0 ;j < 10; j++){ String uri ="/testAgainstRealHosts/"+ j;
batcher.onBatchFailure( (batch, throwable) -> { throwable.printStackTrace();
.withThreadCount(8) .onBatchSuccess(batch -> installDocsFinished = true) .onBatchFailure((batch, failure) -> { failure.printStackTrace(); installDocError = failure.getMessage();
.onBatchFailure((batch, throwable) -> throwable.printStackTrace()); JobTicket ticket1 = moveMgr.startJob( batcher1 ); for ( int i=0; i < numDocs; i++) {
.withThreadCount(4) .onBatchSuccess(batch -> installDocsFinished = true) .onBatchFailure((batch, failure) -> { failure.printStackTrace(); installDocError = failure.getMessage();
.withThreadCount(4) .withTransform(runFlow) .onBatchFailure((batch, failure) -> { errorMessage = failure.getMessage(); runFlowFailed = true;
.withThreadCount(4) .onBatchSuccess(batch -> installDocsFinished = true) .onBatchFailure((batch, failure) -> { failure.printStackTrace(); installDocError = failure.getMessage();
@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")); } }
assertEquals(NoResponseListener.class, failureListeners[2].getClass()); batcher.onBatchFailure(failureListener); failureListeners = batcher.getBatchFailureListeners(); assertEquals(4, failureListeners.length);