Program: 160291
Project: 160291
Buggy source:
/** 
 * Test goOffline() method in the context of a continuous pusher. - 1. Add a local document - 2. Kick off continuous push replication - 3. Wait for document to be pushed - 4. Call goOffline() - 6. Call goOnline() - 5. Add a 2nd local document - 7. Wait for 2nd document to be pushed
 * @throws Exception
 */
public void testGoOfflinePusher() throws Exception {
  int previous=RemoteRequestRetry.RETRY_DELAY_MS;
  RemoteRequestRetry.RETRY_DELAY_MS=5;
  try {
    Map<String,Object> properties=new HashMap<String,Object>();
    properties.put("String_Node_Str","String_Node_Str");
    Document doc1=createDocumentWithProperties(database,properties);
    MockDispatcher dispatcher=new MockDispatcher();
    MockWebServer server=new MockWebServer();
    server.setDispatcher(dispatcher);
    server.play();
    MockCheckpointPut mockCheckpointPut=new MockCheckpointPut();
    mockCheckpointPut.setSticky(true);
    dispatcher.enqueueResponse(MockHelper.PATH_REGEX_CHECKPOINT,mockCheckpointPut);
    MockRevsDiff mockRevsDiff=new MockRevsDiff();
    mockRevsDiff.setSticky(true);
    dispatcher.enqueueResponse(MockHelper.PATH_REGEX_REVS_DIFF,mockRevsDiff);
    MockBulkDocs mockBulkDocs=new MockBulkDocs();
    mockBulkDocs.setSticky(true);
    dispatcher.enqueueResponse(MockHelper.PATH_REGEX_BULK_DOCS,mockBulkDocs);
    Replication replicator=database.createPushReplication(server.getUrl("String_Node_Str"));
    replicator.setContinuous(true);
    CountDownLatch replicationIdleSignal=new CountDownLatch(1);
    ReplicationIdleObserver replicationIdleObserver=new ReplicationIdleObserver(replicationIdleSignal);
    replicator.addChangeListener(replicationIdleObserver);
    replicator.start();
    boolean successful=replicationIdleSignal.await(30,TimeUnit.SECONDS);
    assertTrue(successful);
    boolean foundCheckpointPut=false;
    String expectedLastSequence="String_Node_Str";
    while (!foundCheckpointPut) {
      RecordedRequest request=dispatcher.takeRequestBlocking(MockHelper.PATH_REGEX_CHECKPOINT);
      if (request.getMethod().equals("String_Node_Str")) {
        foundCheckpointPut=true;
        Assert.assertTrue(request.getUtf8Body().indexOf(expectedLastSequence) != -1);
        dispatcher.takeRecordedResponseBlocking(request);
      }
    }
    RecordedRequest bulkDocsRequest1=dispatcher.takeRequest(MockHelper.PATH_REGEX_BULK_DOCS);
    assertNotNull(bulkDocsRequest1);
    assertBulkDocJsonContainsDoc(bulkDocsRequest1,doc1);
    putReplicationOffline(replicator);
    dispatcher.clearQueuedResponse(MockHelper.PATH_REGEX_CHECKPOINT);
    dispatcher.clearQueuedResponse(MockHelper.PATH_REGEX_REVS_DIFF);
    dispatcher.clearQueuedResponse(MockHelper.PATH_REGEX_BULK_DOCS);
    properties=new HashMap<String,Object>();
    properties.put("String_Node_Str","String_Node_Str");
    Document doc2=createDocumentWithProperties(database,properties);
    try {
      Thread.sleep(5000 * 5);
    }
 catch (    Exception ex) {
    }
    RecordedRequest checkpointRequest=dispatcher.takeRequest(MockHelper.PATH_REGEX_CHECKPOINT);
    assertNull(checkpointRequest);
    RecordedRequest revsDiffRequest=dispatcher.takeRequest(MockHelper.PATH_REGEX_REVS_DIFF);
    assertNull(revsDiffRequest);
    RecordedRequest bulkDocsRequest=dispatcher.takeRequest(MockHelper.PATH_REGEX_BULK_DOCS);
    assertNull(bulkDocsRequest);
    putReplicationOnline(replicator);
    foundCheckpointPut=false;
    expectedLastSequence="String_Node_Str";
    while (!foundCheckpointPut) {
      RecordedRequest request=dispatcher.takeRequestBlocking(MockHelper.PATH_REGEX_CHECKPOINT);
      if (request.getMethod().equals("String_Node_Str")) {
        foundCheckpointPut=true;
        Assert.assertTrue(request.getUtf8Body().indexOf(expectedLastSequence) != -1);
        dispatcher.takeRecordedResponseBlocking(request);
      }
    }
    RecordedRequest bulkDocsRequest2=dispatcher.takeRequest(MockHelper.PATH_REGEX_BULK_DOCS);
    assertNotNull(bulkDocsRequest2);
    assertBulkDocJsonContainsDoc(bulkDocsRequest2,doc2);
    stopReplication(replicator);
    server.shutdown();
  }
  finally {
    RemoteRequestRetry.RETRY_DELAY_MS=previous;
  }
}

Fixed version (ground truth):
/** 
 * Test goOffline() method in the context of a continuous pusher. - 1. Add a local document - 2. Kick off continuous push replication - 3. Wait for document to be pushed - 4. Call goOffline() - 6. Call goOnline() - 5. Add a 2nd local document - 7. Wait for 2nd document to be pushed
 * @throws Exception
 */
public void testGoOfflinePusher() throws Exception {
  int previous=RemoteRequestRetry.RETRY_DELAY_MS;
  RemoteRequestRetry.RETRY_DELAY_MS=5;
  try {
    Map<String,Object> properties=new HashMap<String,Object>();
    properties.put("String_Node_Str","String_Node_Str");
    Document doc1=createDocumentWithProperties(database,properties);
    MockDispatcher dispatcher=new MockDispatcher();
    MockWebServer server=new MockWebServer();
    server.setDispatcher(dispatcher);
    server.play();
    MockCheckpointPut mockCheckpointPut=new MockCheckpointPut();
    mockCheckpointPut.setSticky(true);
    dispatcher.enqueueResponse(MockHelper.PATH_REGEX_CHECKPOINT,mockCheckpointPut);
    MockRevsDiff mockRevsDiff=new MockRevsDiff();
    mockRevsDiff.setSticky(true);
    dispatcher.enqueueResponse(MockHelper.PATH_REGEX_REVS_DIFF,mockRevsDiff);
    MockBulkDocs mockBulkDocs=new MockBulkDocs();
    mockBulkDocs.setSticky(true);
    dispatcher.enqueueResponse(MockHelper.PATH_REGEX_BULK_DOCS,mockBulkDocs);
    Replication replicator=database.createPushReplication(server.getUrl("String_Node_Str"));
    replicator.setContinuous(true);
    CountDownLatch replicationIdleSignal=new CountDownLatch(1);
    ReplicationIdleObserver replicationIdleObserver=new ReplicationIdleObserver(replicationIdleSignal);
    replicator.addChangeListener(replicationIdleObserver);
    replicator.start();
    boolean successful=replicationIdleSignal.await(30,TimeUnit.SECONDS);
    assertTrue(successful);
    boolean foundCheckpointPut=false;
    String expectedLastSequence="String_Node_Str";
    while (!foundCheckpointPut) {
      RecordedRequest request=dispatcher.takeRequestBlocking(MockHelper.PATH_REGEX_CHECKPOINT);
      if (request.getMethod().equals("String_Node_Str")) {
        foundCheckpointPut=true;
        Assert.assertTrue(request.getUtf8Body().indexOf(expectedLastSequence) != -1);
        dispatcher.takeRecordedResponseBlocking(request);
      }
    }
    RecordedRequest bulkDocsRequest1=dispatcher.takeRequest(MockHelper.PATH_REGEX_BULK_DOCS);
    assertNotNull(bulkDocsRequest1);
    assertBulkDocJsonContainsDoc(bulkDocsRequest1,doc1);
    putReplicationOffline(replicator);
    properties=new HashMap<String,Object>();
    properties.put("String_Node_Str","String_Node_Str");
    Document doc2=createDocumentWithProperties(database,properties);
    try {
      Thread.sleep(1000 * 3);
    }
 catch (    Exception ex) {
    }
    RecordedRequest bulkDocsRequest=dispatcher.takeRequest(MockHelper.PATH_REGEX_BULK_DOCS);
    assertNull(bulkDocsRequest);
    putReplicationOnline(replicator);
    foundCheckpointPut=false;
    expectedLastSequence="String_Node_Str";
    while (!foundCheckpointPut) {
      RecordedRequest request=dispatcher.takeRequestBlocking(MockHelper.PATH_REGEX_CHECKPOINT);
      if (request.getMethod().equals("String_Node_Str")) {
        foundCheckpointPut=true;
        Assert.assertTrue(request.getUtf8Body().indexOf(expectedLastSequence) != -1);
        dispatcher.takeRecordedResponseBlocking(request);
      }
    }
    RecordedRequest bulkDocsRequest2=dispatcher.takeRequest(MockHelper.PATH_REGEX_BULK_DOCS);
    assertNotNull(bulkDocsRequest2);
    assertBulkDocJsonContainsDoc(bulkDocsRequest2,doc2);
    stopReplication(replicator);
    server.shutdown();
  }
  finally {
    RemoteRequestRetry.RETRY_DELAY_MS=previous;
  }
}