Source:
<code>public void stopRunningReplication() throws Exception { int numDocs = 5000; Random r = new Random(); for (int i = 0; i < numDocs; i++) { Foo f = new Foo(); f.setId(i + CouchUtils.generateDocumentId()); f.setRevision(CouchUtils.getFirstRevisionId()); byte[] bytes = new byte[512]; r.nextBytes(bytes); f.setFoo("Foo " + i + " " + new String(bytes, "UTF-8")); remoteDb.create(f); } Replicator replicator = getPullBuilder().build(); replicator.start(); do { TimeUnit.MILLISECONDS.sleep(100); } while (replicator.getState() == Replicator.State.PENDING); Assert.assertEquals("The replicator should be started", Replicator.State.STARTED, replicator.getState()); <START> TimeUnit.MILLISECONDS.sleep(500); <END> replicator.stop(); do { TimeUnit.MILLISECONDS.sleep(100); } while (replicator.getState() == Replicator.State.STOPPING); Assert.assertEquals("The replicator should be stopped", Replicator.State.STOPPED, replicator.getState()); BasicPullStrategy pullStrategy = getPrivateField(BasicReplicator.class, "strategy", BasicPullStrategy.class, replicator); List<GetRevisionTaskThreaded> tasks = getPrivateField(BasicPullStrategy.class, "threadedTasks", List.class, pullStrategy); for (GetRevisionTaskThreaded task : tasks) { Collection jobs = getPrivateField(GetRevisionTaskThreaded.class, "submittedJobs", Collection.class, task); Assert.assertTrue("There should be no jobs left", jobs.isEmpty()); Collection responses = getPrivateField(GetRevisionTaskThreaded.class, "responses", Collection.class, task); Assert.assertTrue("There should be no responses left", responses.isEmpty()); } }</code><technical_language>Is assert/wait some jobs created? if this test complex reassuring job created</technical_language>

Target:
public void stopRunningReplication() throws Exception { int createBatches = 3; int numDocsPerBatch = 700; Random r = new Random(); for (int batch = 0; batch < createBatches; batch++) { List<Foo> docs = new ArrayList<Foo>(numDocsPerBatch); for (int i = 0; i < numDocsPerBatch; i++) { Foo f = new Foo(); String docPrefix = batch + "-" + i + "-"; f.setId(docPrefix + CouchUtils.generateDocumentId()); f.setRevision(CouchUtils.getFirstRevisionId()); byte[] bytes = new byte[512]; r.nextBytes(bytes); f.setFoo("Foo " + docPrefix + " " + new String(bytes, "UTF-8")); docs.add(f); } remoteDb.getCouchClient().bulkCreateDocs(docs); } Replicator replicator = getPullBuilder().build(); replicator.start(); do { TimeUnit.MILLISECONDS.sleep(100); } while (replicator.getState() == Replicator.State.PENDING); Assert.assertEquals("The replicator should be started", Replicator.State.STARTED, replicator.getState()); TimeUnit.MILLISECONDS.sleep(500); BasicPullStrategy pullStrategy = getPrivateField(BasicReplicator.class, "strategy", BasicPullStrategy.class, replicator); List<GetRevisionTaskThreaded> tasks = getPrivateField(BasicPullStrategy.class, "threadedTasks", List.class, pullStrategy); Assert.assertTrue("There should be at least one task created", tasks.size() >= 1); replicator.stop(); do { TimeUnit.MILLISECONDS.sleep(100); } while (replicator.getState() == Replicator.State.STOPPING); Assert.assertEquals("The replicator should be stopped", Replicator.State.STOPPED, replicator.getState()); for (GetRevisionTaskThreaded task : tasks) { Collection jobs = getPrivateField(GetRevisionTaskThreaded.class, "submittedJobs", Collection.class, task); Assert.assertTrue("There should be no jobs left", jobs.isEmpty()); Collection responses = getPrivateField(GetRevisionTaskThreaded.class, "responses", Collection.class, task); Assert.assertTrue("There should be no responses left", responses.isEmpty()); } }