예제 #1
0
		/// <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");
		}
        /// <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");
        }