コード例 #1
0
        public void GetQueryUri_PartiallyFailed_DoesntResetFailures()
        {
            // Arrange

            var context = ContextFactory.GetCouchbaseContext();
            var uri1    = new FailureCountingUri("http://uri1/");

            uri1.IncrementFailed();
            uri1.IncrementFailed();

            var uri2 = new FailureCountingUri("http://uri2/");

            context.QueryUris.Add(uri1);
            context.QueryUris.Add(uri2);

            // Act

            var uri = context.GetQueryUri(2);

            // Assert

            Assert.AreEqual(uri2, uri);
            Assert.AreEqual(2, uri1.FailedCount);
            Assert.AreEqual(0, uri2.FailedCount);
        }
コード例 #2
0
        public void GetQueryUri_PartiallyFailed_DoesntResetFailures()
        {
            // Arrange

            FailureCountingUri item;

            while (ConfigContextBase.QueryUris.TryTake(out item))
            {
                // Clear the list
            }

            var uri1 = new FailureCountingUri("http://uri1/");

            uri1.IncrementFailed();
            uri1.IncrementFailed();

            var uri2 = new FailureCountingUri("http://uri2/");

            ConfigContextBase.QueryUris.Add(uri1);
            ConfigContextBase.QueryUris.Add(uri2);

            // Act

            var uri = ConfigContextBase.GetQueryUri(2);

            // Assert

            Assert.AreEqual(uri2, uri);
            Assert.AreEqual(2, uri1.FailedCount);
            Assert.AreEqual(0, uri2.FailedCount);
        }
コード例 #3
0
        public void GetSearchUri_AllFailed_ResetsAll()
        {
            // Arrange

            var context = ContextFactory.GetCouchbaseContext();

            var uri1 = new FailureCountingUri("http://uri1/");
            var uri2 = new FailureCountingUri("http://uri2/");

            for (var i = 0; i < ConfigContextBase.SearchNodeFailureThreshold; i++)
            {
                uri1.IncrementFailed();
                uri2.IncrementFailed();
            }

            context.SearchUris.Add(uri1);
            context.SearchUris.Add(uri2);

            // Act

            var uri = context.GetSearchUri();

            // Assert

            Assert.NotNull(uri);
            Assert.AreEqual(0, uri1.FailedCount);
            Assert.AreEqual(0, uri2.FailedCount);
        }
コード例 #4
0
        public void GetSearchUri_AllFailed_ResetsAll()
        {
            // Arrange

            FailureCountingUri item;

            while (ConfigContextBase.SearchUris.TryTake(out item))
            {
                // Clear the list
            }

            var uri1 = new FailureCountingUri("http://uri1/");
            var uri2 = new FailureCountingUri("http://uri2/");

            for (var i = 0; i < ConfigContextBase.SearchNodeFailureThreshold; i++)
            {
                uri1.IncrementFailed();
                uri2.IncrementFailed();
            }

            ConfigContextBase.SearchUris.Add(uri1);
            ConfigContextBase.SearchUris.Add(uri2);

            // Act

            var uri = ConfigContextBase.GetSearchUri();

            // Assert

            Assert.NotNull(uri);
            Assert.AreEqual(0, uri1.FailedCount);
            Assert.AreEqual(0, uri2.FailedCount);
        }
コード例 #5
0
        public async Task UriTester_Failure_DoesNotChangeFailureCount()
        {
            // Arrange

            var log = new Mock <ILog>();

            var messageHandler = new Mock <HttpMessageHandler>();

            messageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.ServiceUnavailable
            }));

            var uriTester = new Mock <UriTesterBase>(new HttpClient(messageHandler.Object), log.Object)
            {
                CallBase = true
            };

            uriTester.Protected()
            .Setup <Uri>("GetPingUri", ItExpr.IsAny <FailureCountingUri>())
            .Returns((FailureCountingUri uri) => uri);

            var testUri = new FailureCountingUri("http://localhost:8091/");

            testUri.IncrementFailed();
            testUri.IncrementFailed();

            // Act

            await uriTester.Object.TestUri(testUri, CancellationToken.None);

            // Assert

            Assert.False(testUri.IsHealthy(2));
            Assert.True(testUri.IsHealthy(3));
        }