/// <exception cref="System.UriFormatException"></exception>
        public virtual void TestChannelsMore()
        {
            Database    db            = StartDatabase();
            Uri         fakeRemoteURL = new Uri("http://couchbase.com/no_such_db");
            Replication r1            = db.CreatePullReplication(fakeRemoteURL);

            NUnit.Framework.Assert.IsTrue(r1.GetChannels().IsEmpty());
            r1.SetFilter("foo/bar");
            NUnit.Framework.Assert.IsTrue(r1.GetChannels().IsEmpty());
            IDictionary <string, object> filterParams = new Dictionary <string, object>();

            filterParams.Put("a", "b");
            r1.SetFilterParams(filterParams);
            NUnit.Framework.Assert.IsTrue(r1.GetChannels().IsEmpty());
            r1.SetChannels(null);
            NUnit.Framework.Assert.AreEqual("foo/bar", r1.GetFilter());
            NUnit.Framework.Assert.AreEqual(filterParams, r1.GetFilterParams());
            IList <string> channels = new AList <string>();

            channels.AddItem("NBC");
            channels.AddItem("MTV");
            r1.SetChannels(channels);
            NUnit.Framework.Assert.AreEqual(channels, r1.GetChannels());
            NUnit.Framework.Assert.AreEqual("sync_gateway/bychannel", r1.GetFilter());
            filterParams = new Dictionary <string, object>();
            filterParams.Put("channels", "NBC,MTV");
            NUnit.Framework.Assert.AreEqual(filterParams, r1.GetFilterParams());
            r1.SetChannels(null);
            NUnit.Framework.Assert.AreEqual(r1.GetFilter(), null);
            NUnit.Framework.Assert.AreEqual(null, r1.GetFilterParams());
        }
        /// <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");
        }