/** * This implements the WriteFailureListener interface * * @param batch the batch of WriteEvents * @param throwable the exception */ public void processFailure(WriteBatch batch, Throwable throwable) { boolean isHostUnavailableException = processException(batch.getBatcher(), throwable, batch.getClient().getHost()); if ( isHostUnavailableException == true ) { try { logger.warn("Retrying failed batch: {}, results so far: {}, uris: {}", batch.getJobBatchNumber(), batch.getJobWritesSoFar(), Stream.of(batch.getItems()).map(event->event.getTargetUri()).collect(Collectors.toList())); batch.getBatcher().retryWithFailureListeners(batch); } catch (RuntimeException e) { logger.error("Exception during retry", e); processFailure(batch, e); } } }
logger.debug("[testStopBeforeFlush_Issue595] batch: " + batch.getJobBatchNumber() + ", items: " + batch.getItems().length + ", writes so far: " + batch.getJobWritesSoFar() + ", host: " + batch.getClient().getHost()); }) logger.debug("An expected InterruptedIOException occurred because the job was stopped prematurely" + ", batch: " + batch.getJobBatchNumber() + ", writes so far: " + batch.getJobWritesSoFar() + ", host: " + batch.getClient().getHost() + ", uris: " + ", writes so far: " + batch.getJobWritesSoFar() + ", host: " + batch.getClient().getHost() + ", uris: " +
@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")); } }