예제 #1
0
        public void NullServiceThrowException()
        {
            var selector = new DnsServiceTargetSelectorReal(null, null, 0, null);
            var ex       = Assert.ThrowsAsync <ArgumentNullException>(async() => await selector.SelectHostAsync(null));

            selector = new DnsServiceTargetSelectorReal(null, null, 0, CreateLoggers.CreateILoggerFromNLog());
            ex       = Assert.ThrowsAsync <ArgumentNullException>(async() => await selector.SelectHostAsync(null));
            Assert.IsNotNull(ex);
        }
예제 #2
0
        public async Task LaunchErrorUseTheOriginalUriIfNoDnsServerWork()
        {
            var             logger  = CreateLoggers.CreateILoggerFromNLog();
            FakeHTTPHandler handler = new FakeHTTPHandler();

            handler.ReturnMessage        = "responseSuccess";
            handler.ReturnStatusCodeList = new List <HttpStatusCode>()
            {
                HttpStatusCode.InternalServerError
            };

            IDnsServiceExtractor extract = new DnsServiceExtractorFirstLabelConvention(ProtocolType.Tcp);

            FakeDnsSrvQuerier querier = new FakeDnsSrvQuerier();
            var dnsHandler            = new DnsServiceBalancingMessageHandler(extract.FromUri(new Uri("https://api.qarnot.com")), new DnsServiceTargetSelectorReal(querier, new DnsSrvSortResult(), 10, logger), new TargetQuarantinePolicyServerUnavailable(new TimeSpan(0, 0, 10)), logger);

            // add the fake handle
            dnsHandler.InnerHandler = handler;

            // wrapper used to send the chosen request
            using HandlerWrapper handlerWrapper = new HandlerWrapper();
            handlerWrapper.InnerHandler         = dnsHandler;

            // create the request
            using var requestMessage1 = new HttpRequestMessage(new HttpMethod("Get"), "https://hello.world.com");

            // get the result
            var result = await handlerWrapper.Send(requestMessage1, default(CancellationToken));

            var content = await result.Content.ReadAsStringAsync();

            Assert.AreEqual(result.StatusCode, HttpStatusCode.InternalServerError);
            Assert.AreEqual("hello.world.com", handler.UrlCall.Host);
            handler.ReturnStatusCodeList = new List <HttpStatusCode>()
            {
                HttpStatusCode.Accepted
            };
            using var requestMessage2 = new HttpRequestMessage(new HttpMethod("Get"), "https://hello.world.com");

            result = await handlerWrapper.Send(requestMessage2, default(CancellationToken));

            content = await result.Content.ReadAsStringAsync();

            Assert.AreEqual("responseSuccess", content);
            Assert.AreEqual(result.StatusCode, HttpStatusCode.Accepted);
            Assert.AreEqual("hello.world.com", handler.UrlCall.Host);
        }
예제 #3
0
        public async Task ResetShouldAllowToRecallTheDns()
        {
            var logger   = CreateLoggers.CreateILoggerFromNLog();
            var selector = new DnsServiceTargetSelectorReal(new FakeDnsSrvQuerier(), new DnsSrvSortResult(), 10, logger);
            var ret      = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));

            do
            {
                await selector.BlacklistHostForAsync(ret, new TimeSpan(1, 1, 1));

                ret = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));
            }while (ret != null);

            await selector.ResetAsync();

            ret = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));

            Assert.IsNotNull(ret);
        }
예제 #4
0
        public async Task LaunchASimpleRequestMustSuccess()
        {
            var logger = CreateLoggers.CreateILoggerFromNLog();
            IDnsServiceExtractor extract = new DnsServiceExtractorFirstLabelConvention(ProtocolType.Tcp);

            IDnsSrvQuerier querier    = new FakeDnsSrvQuerier();
            var            dnsHandler = new DnsServiceBalancingMessageHandler(extract.FromUri(new Uri("https://api.qarnot.com")), new DnsServiceTargetSelectorReal(querier, new DnsSrvSortResult(), 10), new TargetQuarantinePolicyServerUnavailable(), logger);

            using HandlerWrapper handlerWrapper = WrapDnsHandler(dnsHandler, "responseSuccess");

            // create the request
            using var requestMessage = new HttpRequestMessage(new HttpMethod("Get"), "https://hello.world.com");

            // get the result
            var result = await handlerWrapper.Send(requestMessage, default(CancellationToken));

            var content = await result.Content.ReadAsStringAsync();

            Assert.AreEqual(content, "responseSuccess");
        }
예제 #5
0
        public async Task ResetBlacklistForHostAfterAllHostPutInQuaranine()
        {
            var selector = new DnsServiceTargetSelectorReal(new FakeDnsSrvQuerier(), new DnsSrvSortResult(), 10, CreateLoggers.CreateILoggerFromNLog());
            var save     = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));

            var ret = save;

            do
            {
                await selector.BlacklistHostForAsync(ret, new TimeSpan(1, 1, 1));

                ret = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));
            }while (ret != null);

            ret = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));

            Assert.IsNull(ret);
            await selector.ResetBlacklistForHostAsync(save);

            ret = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));

            Assert.IsNotNull(ret);
        }
예제 #6
0
        public async Task ResetBlacklistForHostShouldNotFailNorThrowException()
        {
            var selector = new DnsServiceTargetSelectorReal(new FakeDnsSrvQuerier(), new DnsSrvSortResult(), 10, CreateLoggers.CreateILoggerFromNLog());
            var ret1     = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));

            await selector.ResetBlacklistForHostAsync(ret1);

            var ret2 = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));

            Assert.AreEqual(ret1, ret2);
        }
예제 #7
0
        public async Task BlacklistForShouldNotFail()
        {
            var selector = new DnsServiceTargetSelectorReal(new FakeDnsSrvQuerier(), new DnsSrvSortResult(), 10, CreateLoggers.CreateILoggerFromNLog());
            var ret1     = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));

            await selector.BlacklistHostForAsync(ret1, new TimeSpan(1, 1, 1));

            var ret2 = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));

            Assert.AreNotEqual(ret1, ret2);
        }
예제 #8
0
        public async Task BlacklistForShouldThrowExceptionIfNullValue()
        {
            var selector = new DnsServiceTargetSelectorReal(new FakeDnsSrvQuerier(), new DnsSrvSortResult(), 10, CreateLoggers.CreateILoggerFromNLog());
            var ret1     = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));

            var ex = Assert.ThrowsAsync <ArgumentNullException>(async() => await selector.BlacklistHostForAsync(null, new TimeSpan(1, 1, 1)));

            Assert.IsNotNull(ex);
        }
예제 #9
0
        public async Task ShouldNotFailWhenQueryServerReturnNoElement()
        {
            var selector = new DnsServiceTargetSelectorReal(new FakeDnsSrvQuerierEmpty(), new DnsSrvSortResult(), 10, CreateLoggers.CreateILoggerFromNLog());
            var ret      = await selector.SelectHostAsync(new DnsSrvServiceDescription("service", ProtocolType.Tcp, "domain"));

            Assert.IsNull(ret);
        }