public void DiscoverServerInstances_FailsFast()
        {
            var values = new Dictionary <string, string>()
            {
                { "spring:cloud:config:discovery:enabled", "True" },
                { "spring:cloud:config:failFast", "True" },
                { "eureka:client:eurekaServer:retryCount", "0" }
            };

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddInMemoryCollection(values)
                                           .Build();

            var settings = new ConfigServerClientSettings
            {
                Uri         = "http://localhost:8888/",
                Name        = "foo",
                Environment = "development",
                Timeout     = 10
            };
            var source   = new ConfigServerConfigurationSource(settings, configuration);
            var provider = new ConfigServerConfigurationProvider(source);
            var service  = new ConfigServerDiscoveryService(configuration, settings);

            Assert.Throws <ConfigServerException>(() => provider.DiscoverServerInstances(service));
        }
Exemplo n.º 2
0
        public void GetConfigServerInstancesCatchesDiscoveryExceptions()
        {
            var appSettings = new Dictionary <string, string> {
                { "testdiscovery:enabled", "true" }
            };
            var config  = new ConfigurationBuilder().AddInMemoryCollection(appSettings).Build();
            var service = new ConfigServerDiscoveryService(config, new ConfigServerClientSettings());

            // act - the test discovery client throws on GetInstances()
            var result = service.GetConfigServerInstances();

            Assert.Empty(result);
        }
Exemplo n.º 3
0
        public async Task ShutdownAsyncShutsDownOriginalDiscoveryClient()
        {
            // arrange a basic ConfigServerDiscoveryService w/o logging
            var appSettings = new Dictionary <string, string> {
                { "testdiscovery:enabled", "true" }
            };
            var config         = new ConfigurationBuilder().AddInMemoryCollection(appSettings).Build();
            var service        = new ConfigServerDiscoveryService(config, new ConfigServerClientSettings());
            var originalClient = service._discoveryClient as TestDiscoveryClient;

            // replace the bootstrapped eureka client with a test client
            await service.ShutdownAsync();

            Assert.True(originalClient.HasShutdown, "ShutdownAsync() called on original discovery client.");
        }
        public void FindGetInstancesMethod_FindsMethod()
        {
            var values = new Dictionary <string, string>()
            {
                { "eureka:client:serviceUrl", "http://localhost:8761/eureka/" }
            };
            var builder = new ConfigurationBuilder();

            builder.AddInMemoryCollection(values);
            var config   = builder.Build();
            var settings = new ConfigServerClientSettings();

            var service = new ConfigServerDiscoveryService(config, settings);

            Assert.NotNull(service.FindGetInstancesMethod());
        }
        public void GetConfigServerInstances_ReturnsExpected()
        {
            var values = new Dictionary <string, string>()
            {
                { "eureka:client:serviceUrl", "http://localhost:8761/eureka/" }
            };
            var builder = new ConfigurationBuilder();

            builder.AddInMemoryCollection(values);
            var config   = builder.Build();
            var settings = new ConfigServerClientSettings();

            var service = new ConfigServerDiscoveryService(config, settings);
            var result  = service.GetConfigServerInstances();

            Assert.Empty(result);
        }
Exemplo n.º 6
0
        public void ConfigServerDiscoveryService_FindsDiscoveryClient()
        {
            var values = new Dictionary <string, string>()
            {
                { "eureka:client:serviceUrl", "http://localhost:8761/eureka/" }
            };
            var builder = new ConfigurationBuilder();

            builder.AddInMemoryCollection(values);
            var config     = builder.Build();
            var settings   = new ConfigServerClientSettings();
            var logFactory = new LoggerFactory();

            var service = new ConfigServerDiscoveryService(config, settings, logFactory);

            Assert.NotNull(service._discoveryClient);
            Assert.IsType <EurekaDiscoveryClient>(service._discoveryClient);
        }
Exemplo n.º 7
0
        public void InvokeGetInstances_RetryEnabled_ReturnsExpected()
        {
            var values = new Dictionary <string, string>()
            {
                { "eureka:client:serviceUrl", "https://foo.bar:8761/eureka/" },
                { "eureka:client:eurekaServer:retryCount", "1" }
            };
            var config   = new ConfigurationBuilder().AddInMemoryCollection(values).Build();
            var settings = new ConfigServerClientSettings()
            {
                RetryEnabled  = true,
                Timeout       = 10,
                RetryAttempts = 1
            };
            var service = new ConfigServerDiscoveryService(config, settings);
            var result  = service.GetConfigServerInstances();

            Assert.Empty(result);
        }
Exemplo n.º 8
0
        public async Task RuntimeReplacementsCanBeProvided()
        {
            // arrange a basic ConfigServerDiscoveryService w/o logging
            var appSettings = new Dictionary <string, string> {
                { "eureka:client:anything", "true" }
            };
            var config = new ConfigurationBuilder().AddInMemoryCollection(appSettings).Build();
            var testDiscoveryClient = new TestDiscoveryClient();
            var logFactory          = new LoggerFactory();
            var service             = new ConfigServerDiscoveryService(config, new ConfigServerClientSettings());

            Assert.Null(service._logFactory);
            Assert.IsType <NullLogger>(service._logger);
            Assert.IsType <EurekaDiscoveryClient>(service._discoveryClient);

            // replace the bootstrapped eureka client with a test client
            await service.ProvideRuntimeReplacementsAsync(testDiscoveryClient, logFactory);

            Assert.NotNull(service._logFactory);
            Assert.IsAssignableFrom <ILogger <ConfigServerDiscoveryService> >(service._logger);
        }
        public void InvokeGetInstances_RetryEnabled_ReturnsExpected()
        {
            var values = new Dictionary <string, string>()
            {
                { "eureka:client:serviceUrl", "https://foo.bar:8761/eureka/" }
            };
            var builder = new ConfigurationBuilder();

            builder.AddInMemoryCollection(values);
            var config   = builder.Build();
            var settings = new ConfigServerClientSettings()
            {
                RetryEnabled = true
            };
            var service = new ConfigServerDiscoveryService(config, settings);
            var method  = service.FindGetInstancesMethod();

            var result = service.InvokeGetInstances(method);

            Assert.Empty(result);
        }