@Override public void initialize() { writeBatcher = this.dataMovementManager.newWriteBatcher(); writeBatcher.withThreadCount(threadCount); writeBatcher.withBatchSize(batchSize); jobTicket = dataMovementManager.startJob(writeBatcher); }
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); }
@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) {} }
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); }
@Test public void testIssue793() { WriteBatcher batcher = moveMgr.newWriteBatcher(); batcher.addAs("test.txt", "test"); moveMgr.startJob(batcher); moveMgr.stopJob(batcher); } }
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(); }
@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()); }
WriteBatcher writeBatcher = moveMgr.newWriteBatcher() .withBatchSize(1) .onBatchSuccess(new CloseBatchListener())
WriteBatcher batcher = stagingDataMovementManager.newWriteBatcher(); batcher.withBatchSize(1).withTransform(runFlow); batcher.onBatchSuccess(batch -> {
WriteBatcher ihb1 = moveMgr.newWriteBatcher() .withBatchSize(1) .onBatchSuccess(
WriteBatcher writeBatcher = moveMgr.newWriteBatcher() .withBatchSize(10) .withForestConfig(ffg)
@Test public void testUndeclaredFormat_Issue60() { String collection = whbTestCollection + ".testUndeclaredFormat_Issue60"; WriteBatcher batcher = moveMgr.newWriteBatcher(); batcher.withBatchSize(1); final AtomicInteger successfulCount = new AtomicInteger(0);
mgr = srcClient.newDataMovementManager(); WriteBatcher writeBatcher = mgr.newWriteBatcher() .withBatchSize(100) .withThreadCount(4)
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)
private void installDocs(DataFormat dataFormat, String collection, DatabaseClient srcClient, boolean useEs, int testSize) { DataMovementManager mgr = srcClient.newDataMovementManager(); WriteBatcher writeBatcher = mgr.newWriteBatcher() .withBatchSize(100) .withThreadCount(4)
@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")); } }
WriteBatcher writeBatcher = moveMgr.newWriteBatcher(); moveMgr.startJob(writeBatcher); String[] uris = new String[100];
public static void setup() throws Exception { WriteBatcher writeBatcher = moveMgr.newWriteBatcher(); moveMgr.startJob(writeBatcher); // a collection so we're only looking at docs related to this test DocumentMetadataHandle meta = new DocumentMetadataHandle() .withCollections(collection, qhbTestCollection); // all the docs are one-word text docs writeBatcher.addAs(uri1, meta, new StringHandle("{name:\"John Doe\", department:\"HR\"}").withFormat(JSON)); writeBatcher.addAs(uri2, meta, new StringHandle("{name:\"Jane Doe\", department:\"HR\"}").withFormat(JSON)); writeBatcher.addAs(uri3, meta, new StringHandle("{name:\"John Smith\", department:\"HR\"}").withFormat(JSON)); writeBatcher.addAs(uri4, meta, new StringHandle("{name:\"John Lennon\",department:\"HR\"}").withFormat(JSON)); writeBatcher.addAs(uri5, meta, new StringHandle("{name:\"John Man\", department:\"Engineering\"}").withFormat(JSON)); writeBatcher.flushAsync(); writeBatcher.awaitCompletion(); moveMgr.stopJob(writeBatcher); StringHandle options = new StringHandle( "<options xmlns='http://marklogic.com/appservices/search'>" + "<constraint name='dept'>" + "<value>" + "<json-property>department</json-property>" + "</value>" + "</constraint>" + "</options>") .withFormat(XML); QueryOptionsManager queryOptionsMgr = Common.connectAdmin().newServerConfigManager().newQueryOptionsManager(); queryOptionsMgr.writeOptions("employees", options); }