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)); }
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); }
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); }
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); }
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); }
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); }