コード例 #1
0
		public virtual void TestFetchRemoteCheckpointDoc()
		{
            var mockHttpClientFactory = new AlwaysFailingClientFactory();
            mockHttpClientFactory.GetHttpClient();

			Log.D("TEST", "testFetchRemoteCheckpointDoc() called");
			string dbUrlString = "http://fake.test-url.com:4984/fake/";
			Uri remote = new Uri(dbUrlString);
            database.SetLastSequence("1", dbUrlString, true);
			// otherwise fetchRemoteCheckpoint won't contact remote
            Assert.Fail();
			Replication replicator = new Pusher(database, remote, false, mockHttpClientFactory
                , manager.workExecutor);
			CountDownLatch doneSignal = new CountDownLatch(1);
			ReplicationTest.ReplicationObserver replicationObserver = new ReplicationTest.ReplicationObserver
				(this, doneSignal);
            replicator.Changed += replicationObserver.Changed;
			replicator.FetchRemoteCheckpointDoc();
			Log.D(Tag, "testFetchRemoteCheckpointDoc() Waiting for replicator to finish");
			try
			{
                bool succeeded = doneSignal.Await(TimeSpan.FromSeconds(3));
                NUnit.Framework.Assert.IsTrue(succeeded);
                Log.D(Tag, "testFetchRemoteCheckpointDoc() replicator finished");
			}
			catch (Exception e)
			{
				Sharpen.Runtime.PrintStackTrace(e);
			}
			string errorMessage = "Since we are passing in a mock http client that always throws "
				 + "errors, we expect the replicator to be in an error state";
            NUnit.Framework.Assert.IsNotNull(replicator.LastError, errorMessage);
		}
コード例 #2
0
		public virtual void TestRunReplicationWithError()
		{
            var mockHttpClientFactory = new AlwaysFailingClientFactory();
			var dbUrlString = "http://fake.test-url.com:4984/fake/";
            var remote = new Uri(dbUrlString);
            var continuous = false;
            var r1 = new Puller(database, remote, continuous, mockHttpClientFactory, manager.workExecutor);
			Assert.IsFalse(r1.Continuous);

            RunReplication(r1);

			// It should have failed with a 404:
            Assert.AreEqual(ReplicationStatus.Stopped, r1.Status);			
			Assert.AreEqual(0, r1.CompletedChangesCount);
			Assert.AreEqual(0, r1.ChangesCount);
			Assert.IsNotNull(r1.LastError);
		}