Exemplo n.º 1
0
        private void RunChangeTrackerTransientError(
            ChangeTrackerMode mode,
            Int32 errorCode,
            string statusMessage,
            Int32 numExpectedChangeCallbacks)
        {
            var changeTrackerFinishedSignal = new CountdownEvent(1);
            var changeReceivedSignal        = new CountdownEvent(numExpectedChangeCallbacks);
            var client = new ChangeTrackerTestClient(changeTrackerFinishedSignal, changeReceivedSignal);

            MockHttpRequestHandler.HttpResponseDelegate sentinal = RunChangeTrackerTransientErrorDefaultResponder();

            var responders = new List <MockHttpRequestHandler.HttpResponseDelegate>();

            responders.Add(RunChangeTrackerTransientErrorDefaultResponder());
            responders.Add(MockHttpRequestHandler.TransientErrorResponder(errorCode, statusMessage));

            MockHttpRequestHandler.HttpResponseDelegate chainResponder = (request) =>
            {
                if (responders.Count > 0)
                {
                    var responder = responders[0];
                    responders.RemoveAt(0);
                    return(responder(request));
                }

                return(sentinal(request));
            };

            var handler = client.HttpRequestHandler;

            handler.SetResponder("_changes", chainResponder);

            var testUrl       = GetReplicationURL();
            var scheduler     = new SingleTaskThreadpoolScheduler();
            var changeTracker = ChangeTrackerFactory.Create(new ChangeTrackerOptions {
                DatabaseUri      = testUrl,
                Mode             = mode,
                IncludeConflicts = false,
                Client           = client,
                RetryStrategy    = new ExponentialBackoffStrategy(2),
                WorkExecutor     = new TaskFactory(scheduler)
            });

            changeTracker.Start();

            var success = changeReceivedSignal.Wait(TimeSpan.FromSeconds(30));

            Assert.IsTrue(success);

            changeTracker.Stop();

            success = changeTrackerFinishedSignal.Wait(TimeSpan.FromSeconds(30));
            Assert.IsTrue(success);
        }
Exemplo n.º 2
0
        private void RunChangeTrackerTransientError(
            ChangeTrackerMode mode,
            Int32 errorCode,
            string statusMessage,
            Int32 numExpectedChangeCallbacks)
        {
            var changeTrackerFinishedSignal = new CountDownLatch(1);
            var changeReceivedSignal        = new CountDownLatch(numExpectedChangeCallbacks);
            var client = new ChangeTrackerTestClient(changeTrackerFinishedSignal, changeReceivedSignal);

            MockHttpRequestHandler.HttpResponseDelegate sentinal = RunChangeTrackerTransientErrorDefaultResponder();

            var responders = new List <MockHttpRequestHandler.HttpResponseDelegate>();

            responders.Add(RunChangeTrackerTransientErrorDefaultResponder());
            responders.Add(MockHttpRequestHandler.TransientErrorResponder(errorCode, statusMessage));

            MockHttpRequestHandler.HttpResponseDelegate chainResponder = (request) =>
            {
                if (responders.Count > 0)
                {
                    var responder = responders[0];
                    responders.RemoveAt(0);
                    return(responder(request));
                }

                return(sentinal(request));
            };

            var handler = client.HttpRequestHandler;

            handler.SetResponder("_changes", chainResponder);

            var testUrl       = GetReplicationURL();
            var scheduler     = new SingleTaskThreadpoolScheduler();
            var changeTracker = new ChangeTracker(testUrl, mode, 0, false, client, new TaskFactory(scheduler));

            changeTracker.UsePost = IsSyncGateway(testUrl);
            changeTracker.Start();

            var success = changeReceivedSignal.Await(TimeSpan.FromSeconds(30));

            Assert.IsTrue(success);

            changeTracker.Stop();

            success = changeTrackerFinishedSignal.Await(TimeSpan.FromSeconds(30));
            Assert.IsTrue(success);
        }