Пример #1
0
        public async void GetApplicationAsync_Throws_IfAppNameNull()
        {
            var config = new EurekaClientConfig();
            var client = new EurekaHttpClient(config);
            var ex     = await Assert.ThrowsAsync <ArgumentException>(() => client.GetApplicationAsync(null));

            Assert.Contains("appName", ex.Message);
        }
Пример #2
0
        public async void GetApplicationAsync_InvokesServer_ReturnsExpectedApplications()
        {
            var json = @"{
'application':
    {
    'name':'FOO',
    'instance':[
    {
        'instanceId':'localhost:foo',
        'hostName':'localhost',
        'app':'FOO',
        'ipAddr':'192.168.56.1',
        'status':'UP',
        'overriddenstatus':'UNKNOWN',
        'port':{'$':8080,'@enabled':'true'},
        'securePort':{'$':443,'@enabled':'false'},
        'countryId':1,
        'dataCenterInfo':{'@class':'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo','name':'MyOwn'},
        'leaseInfo':{'renewalIntervalInSecs':30,'durationInSecs':90,'registrationTimestamp':1458152330783,'lastRenewalTimestamp':1458243422342,'evictionTimestamp':0,'serviceUpTimestamp':1458152330783},
        'metadata':{'@class':'java.util.Collections$EmptyMap'},
        'homePageUrl':'http://localhost:8080/',
        'statusPageUrl':'http://localhost:8080/info',
        'healthCheckUrl':'http://localhost:8080/health',
        'vipAddress':'foo',
        'isCoordinatingDiscoveryServer':'false',
        'lastUpdatedTimestamp':'1458152330783',
        'lastDirtyTimestamp':'1458152330696',
        'actionType':'ADDED'
    }]
    }
}";
            IHostingEnvironment envir = new HostingEnvironment();

            TestConfigServerStartup.Response     = json;
            TestConfigServerStartup.ReturnStatus = 200;
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);

            var uri = "http://localhost:8888/";

            server.BaseAddress = new Uri(uri);


            var cconfig = new EurekaClientConfig()
            {
                EurekaServerServiceUrls = uri
            };
            var client = new EurekaHttpClient(cconfig, server.CreateClient());
            EurekaHttpResponse <Application> resp = await client.GetApplicationAsync("foo");

            Assert.NotNull(resp);
            Assert.Equal(HttpStatusCode.OK, resp.StatusCode);
            Assert.Equal("GET", TestConfigServerStartup.LastRequest.Method);
            Assert.Equal("localhost:8888", TestConfigServerStartup.LastRequest.Host.Value);
            Assert.Equal("/apps/foo", TestConfigServerStartup.LastRequest.Path.Value);
            Assert.NotNull(resp.Headers);
            Assert.NotNull(resp.Response);
            Assert.Equal("FOO", resp.Response.Name);

            var instances = resp.Response.Instances;

            Assert.NotNull(instances);
            Assert.Equal(1, instances.Count);
            foreach (var instance in instances)
            {
                Assert.Equal("localhost:foo", instance.InstanceId);
                Assert.Equal("foo", instance.VipAddress);
                Assert.Equal("localhost", instance.HostName);
                Assert.Equal("192.168.56.1", instance.IpAddr);
                Assert.Equal(InstanceStatus.UP, instance.Status);
            }
        }
Пример #3
0
        public async System.Threading.Tasks.Task GetApplicationAsync__FirstServerFails_InvokesSecondServer_ReturnsExpectedApplications()
        {
            var json  = @"
                {
                    ""application"": {
                        ""name"":""FOO"",
                        ""instance"":[{
                            ""instanceId"":""localhost:foo"",
                            ""hostName"":""localhost"",
                            ""app"":""FOO"",
                            ""ipAddr"":""192.168.56.1"",
                            ""status"":""UP"",
                            ""overriddenstatus"":""UNKNOWN"",
                            ""port"":{""$"":8080,""@enabled"":""true""},
                            ""securePort"":{""$"":443,""@enabled"":""false""},
                            ""countryId"":1,
                            ""dataCenterInfo"":{""@class"":""com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo"",""name"":""MyOwn""},
                            ""leaseInfo"":{""renewalIntervalInSecs"":30,""durationInSecs"":90,""registrationTimestamp"":1458152330783,""lastRenewalTimestamp"":1458243422342,""evictionTimestamp"":0,""serviceUpTimestamp"":1458152330783},
                            ""metadata"":{""@class"":""java.util.Collections$EmptyMap""},
                            ""homePageUrl"":""http://localhost:8080/"",
                            ""statusPageUrl"":""http://localhost:8080/info"",
                            ""healthCheckUrl"":""http://localhost:8080/health"",
                            ""vipAddress"":""foo"",
                            ""isCoordinatingDiscoveryServer"":""false"",
                            ""lastUpdatedTimestamp"":""1458152330783"",
                            ""lastDirtyTimestamp"":""1458152330696"",
                            ""actionType"":""ADDED""
                        }]
                    }
                }";
            var envir = HostingHelpers.GetHostingEnvironment();

            TestConfigServerStartup.Response     = json;
            TestConfigServerStartup.ReturnStatus = 200;
            TestConfigServerStartup.Host         = "localhost:8888";
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);

            var uri = "http://localhost:8888/";

            server.BaseAddress = new Uri(uri);

            var cconfig = new EurekaClientConfig()
            {
                EurekaServerServiceUrls = "https://bad.host:9999/," + uri
            };
            var client = new EurekaHttpClient(cconfig, server.CreateClient());
            var resp   = await client.GetApplicationAsync("foo");

            Assert.NotNull(resp);
            Assert.Equal(HttpStatusCode.OK, resp.StatusCode);
            Assert.Equal("GET", TestConfigServerStartup.LastRequest.Method);
            Assert.Equal("localhost:8888", TestConfigServerStartup.LastRequest.Host.Value);
            Assert.Equal("/apps/foo", TestConfigServerStartup.LastRequest.Path.Value);
            Assert.NotNull(resp.Headers);
            Assert.NotNull(resp.Response);
            Assert.Equal("FOO", resp.Response.Name);

            var instances = resp.Response.Instances;

            Assert.NotNull(instances);
            Assert.Equal(1, instances.Count);
            foreach (var instance in instances)
            {
                Assert.Equal("localhost:foo", instance.InstanceId);
                Assert.Equal("foo", instance.VipAddress);
                Assert.Equal("localhost", instance.HostName);
                Assert.Equal("192.168.56.1", instance.IpAddr);
                Assert.Equal(InstanceStatus.UP, instance.Status);
            }

            Assert.Equal("http://localhost:8888/", client._serviceUrl);
        }