public virtual void Changed(Replication.ChangeEvent @event)
            {
                Replication replicator = @event.GetSource();

                if (!replicator.IsRunning())
                {
                    this.replicationFinished = true;
                    string msg = string.Format("myobserver.update called, set replicationFinished to: %b"
                                               , this.replicationFinished);
                    Log.D(ReplicationTest.Tag, msg);
                    this.doneSignal.CountDown();
                }
                else
                {
                    string msg = string.Format("myobserver.update called, but replicator still running, so ignore it"
                                               );
                    Log.D(ReplicationTest.Tag, msg);
                }
            }
        /// <exception cref="System.Exception"></exception>
        public virtual void TestGetReplicator()
        {
            IDictionary <string, object> properties = new Dictionary <string, object>();

            properties.Put("source", DefaultTestDb);
            properties.Put("target", GetReplicationURL().ToExternalForm());
            Replication replicator = manager.GetReplicator(properties);

            NUnit.Framework.Assert.IsNotNull(replicator);
            NUnit.Framework.Assert.AreEqual(GetReplicationURL().ToExternalForm(), replicator.
                                            GetRemoteUrl().ToExternalForm());
            NUnit.Framework.Assert.IsTrue(!replicator.IsPull());
            NUnit.Framework.Assert.IsFalse(replicator.IsContinuous());
            NUnit.Framework.Assert.IsFalse(replicator.IsRunning());
            // start the replicator
            replicator.Start();
            // now lets lookup existing replicator and stop it
            properties.Put("cancel", true);
            Replication activeReplicator = manager.GetReplicator(properties);

            activeReplicator.Stop();
            NUnit.Framework.Assert.IsFalse(activeReplicator.IsRunning());
        }
        /// <exception cref="System.Exception"></exception>
        public virtual void TestPusher()
        {
            CountDownLatch replicationDoneSignal = new CountDownLatch(1);
            Uri            remote         = GetReplicationURL();
            string         docIdTimestamp = System.Convert.ToString(Runtime.CurrentTimeMillis());
            // Create some documents:
            IDictionary <string, object> documentProperties = new Dictionary <string, object>();
            string doc1Id = string.Format("doc1-%s", docIdTimestamp);

            documentProperties.Put("_id", doc1Id);
            documentProperties.Put("foo", 1);
            documentProperties.Put("bar", false);
            Body             body   = new Body(documentProperties);
            RevisionInternal rev1   = new RevisionInternal(body, database);
            Status           status = new Status();

            rev1 = database.PutRevision(rev1, null, false, status);
            NUnit.Framework.Assert.AreEqual(Status.Created, status.GetCode());
            documentProperties.Put("_rev", rev1.GetRevId());
            documentProperties.Put("UPDATED", true);
            RevisionInternal rev2 = database.PutRevision(new RevisionInternal(documentProperties
                                                                              , database), rev1.GetRevId(), false, status);

            NUnit.Framework.Assert.AreEqual(Status.Created, status.GetCode());
            documentProperties = new Dictionary <string, object>();
            string doc2Id = string.Format("doc2-%s", docIdTimestamp);

            documentProperties.Put("_id", doc2Id);
            documentProperties.Put("baz", 666);
            documentProperties.Put("fnord", true);
            database.PutRevision(new RevisionInternal(documentProperties, database), null, false
                                 , status);
            NUnit.Framework.Assert.AreEqual(Status.Created, status.GetCode());
            bool        continuous = false;
            Replication repl       = database.CreatePushReplication(remote);

            repl.SetContinuous(continuous);
            repl.SetCreateTarget(true);
            // Check the replication's properties:
            NUnit.Framework.Assert.AreEqual(database, repl.GetLocalDatabase());
            NUnit.Framework.Assert.AreEqual(remote, repl.GetRemoteUrl());
            NUnit.Framework.Assert.IsFalse(repl.IsPull());
            NUnit.Framework.Assert.IsFalse(repl.IsContinuous());
            NUnit.Framework.Assert.IsTrue(repl.ShouldCreateTarget());
            NUnit.Framework.Assert.IsNull(repl.GetFilter());
            NUnit.Framework.Assert.IsNull(repl.GetFilterParams());
            // TODO: CAssertNil(r1.doc_ids);
            // TODO: CAssertNil(r1.headers);
            // Check that the replication hasn't started running:
            NUnit.Framework.Assert.IsFalse(repl.IsRunning());
            NUnit.Framework.Assert.AreEqual(Replication.ReplicationStatus.ReplicationStopped,
                                            repl.GetStatus());
            NUnit.Framework.Assert.AreEqual(0, repl.GetCompletedChangesCount());
            NUnit.Framework.Assert.AreEqual(0, repl.GetChangesCount());
            NUnit.Framework.Assert.IsNull(repl.GetLastError());
            RunReplication(repl);
            // make sure doc1 is there
            // TODO: make sure doc2 is there (refactoring needed)
            Uri replicationUrlTrailing = new Uri(string.Format("%s/", remote.ToExternalForm()
                                                               ));
            Uri pathToDoc = new Uri(replicationUrlTrailing, doc1Id);

            Log.D(Tag, "Send http request to " + pathToDoc);
            CountDownLatch httpRequestDoneSignal = new CountDownLatch(1);
            BackgroundTask getDocTask            = new _BackgroundTask_122(pathToDoc, doc1Id, httpRequestDoneSignal
                                                                           );

            //Closes the connection.
            getDocTask.Execute();
            Log.D(Tag, "Waiting for http request to finish");
            try
            {
                httpRequestDoneSignal.Await(300, TimeUnit.Seconds);
                Log.D(Tag, "http request finished");
            }
            catch (Exception e)
            {
                Sharpen.Runtime.PrintStackTrace(e);
            }
            Log.D(Tag, "testPusher() finished");
        }