public void Resolve_SecondResolveOtherHostname_NotUseCache()
        {
            var sut = new HostnameResolverWithCache(TimeSpan.FromMinutes(1), testDnsResolver);

            sut.Resolve("hostname1");
            sut.Resolve("hostname2");
            Assert.That(testDnsResolver.CallCount, Is.EqualTo(2));
        }
        public void Resolve_SecondResolveSameHostname_SameResults()
        {
            var sut     = new HostnameResolverWithCache(TimeSpan.FromMinutes(1), testDnsResolver);
            var result1 = sut.Resolve("hostname");
            var result2 = sut.Resolve("hostname");

            Assert.AreEqual(result1, result2);
        }
        public void Resolve_SecondResolveWhenCacheDurationEnd_NotUseCache()
        {
            var sut = new HostnameResolverWithCache(TimeSpan.FromSeconds(1), testDnsResolver);

            sut.Resolve("hostname");
            sut.Resolve("hostname");

            Thread.Sleep(TimeSpan.FromMilliseconds(1500));
            sut.Resolve("hostname");
            Assert.That(testDnsResolver.CallCount, Is.EqualTo(2));
        }
        public void Resolve_UseResolverOnlyHostnameNotEmpty(string hostname, int expectedCallCount)
        {
            var sut = new HostnameResolverWithCache(TimeSpan.FromMinutes(1), testDnsResolver);

            sut.Resolve(hostname);
            Assert.That(testDnsResolver.CallCount, Is.EqualTo(expectedCallCount));
        }
        public void Resolve_ReturnsNotNullOnlyOnSuccess(string hostname, bool shouldEmptyResult)
        {
            testDnsResolver = new TestDnsResolver("correct");
            var sut       = new HostnameResolverWithCache(TimeSpan.FromMinutes(1), testDnsResolver);
            var ipAddress = sut.Resolve(hostname);

            Assert.AreEqual(ipAddress == null, shouldEmptyResult);
        }
Beispiel #6
0
        private void InitializePool([NotNull] DnsEndPoint graphiteEndPoint, GraphiteProtocol graphiteProtocol, [CanBeNull] string globalPathPrefix)
        {
            hostnameResolver = new HostnameResolverWithCache(TimeSpan.FromHours(1), new SimpleDnsResolver());
            switch (graphiteProtocol)
            {
            case GraphiteProtocol.Tcp:
                tcpPool = new Pool <GraphiteTcpClient>(x => new GraphiteTcpClient(hostnameResolver.Resolve(graphiteEndPoint.Host), graphiteEndPoint.Port, globalPathPrefix));
                break;

            case GraphiteProtocol.Udp:
                udpPool = new Pool <GraphiteUdpClient>(x => new GraphiteUdpClient(hostnameResolver.Resolve(graphiteEndPoint.Host), graphiteEndPoint.Port, globalPathPrefix));
                break;

            default:
                throw new ArgumentException($"Unknown graphite protocol: {graphiteProtocol}");
            }
        }
 public PooledStatsDClient([NotNull] IGraphiteClientSettings graphiteClientSettings)
 {
     pool        = null;
     innerClient = null;
     prefixes    = null;
     if (graphiteClientSettings.Enabled && graphiteClientSettings.StatsDEndPoint != null)
     {
         var hostnameResolver = new HostnameResolverWithCache(TimeSpan.FromHours(1), new SimpleDnsResolver());
         pool = new Pool <StatsDClient>(x => new StatsDClient(hostnameResolver.Resolve(graphiteClientSettings.StatsDEndPoint.Host), graphiteClientSettings.StatsDEndPoint.Port, graphiteClientSettings.GlobalPathPrefix));
     }
 }