public async void GetInstanceAsync_Throws_IfIDNull()
        {
            var config = new EurekaClientConfig();
            var client = new EurekaHttpClient(config);
            var ex     = await Assert.ThrowsAsync <ArgumentException>(() => client.GetInstanceAsync(null));

            Assert.Contains("id", ex.Message);
        }
        public async System.Threading.Tasks.Task GetInstanceAsync_Throws_IfAppNameNotNullAndIDNull()
        {
            var config = new EurekaClientConfig();
            var client = new EurekaHttpClient(config);
            var ex     = await Assert.ThrowsAsync <ArgumentException>(() => client.GetInstanceAsync("appName", null));

            Assert.Contains("id", ex.Message);
        }
Exemple #3
0
        public async void GetInstanceAsync_InvokesServer_ReturnsExpectedInstances()
        {
            var json    = @"{ 
'instance':
    {
    'instanceId':'DESKTOP-GNQ5SUT',
    'app':'FOOBAR',
    'appGroupName':null,
    'ipAddr':'192.168.0.147',
    'sid':'na',
    'port':{'@enabled':true,'$':80},
    'securePort':{'@enabled':false,'$':443},
    'homePageUrl':'http://*****:*****@class':'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo','name':'MyOwn'},
    'hostName':'DESKTOP-GNQ5SUT',
    'status':'UP',
    'overriddenstatus':'UNKNOWN',
    'leaseInfo':{'renewalIntervalInSecs':30,'durationInSecs':90,'registrationTimestamp':0,'lastRenewalTimestamp':0,'renewalTimestamp':0,'evictionTimestamp':0,'serviceUpTimestamp':0},
    'isCoordinatingDiscoveryServer':false,
    'metadata':{'@class':'java.util.Collections$EmptyMap','metadata':null},
    'lastUpdatedTimestamp':1458116137663,
    'lastDirtyTimestamp':1458116137663,
    'actionType':'ADDED',
    'asgName':null
    }
}";
            var startup = new TestConfigServerStartup(json, 200);
            var server  = TestServer.Create(startup.Configure);
            var uri     = "http://localhost:8888/";

            server.BaseAddress = new Uri(uri);

            var cconfig = new EurekaClientConfig()
            {
                EurekaServerServiceUrls = uri
            };
            var client = new EurekaHttpClient(cconfig, server.CreateClient());
            EurekaHttpResponse <InstanceInfo> resp = await client.GetInstanceAsync("DESKTOP-GNQ5SUT");

            Assert.NotNull(resp);
            Assert.Equal(HttpStatusCode.OK, resp.StatusCode);
            Assert.Equal("GET", startup.LastRequest.Method);
            Assert.Equal("localhost:8888", startup.LastRequest.Host.Value);
            Assert.Equal("/instances/DESKTOP-GNQ5SUT", startup.LastRequest.Path.Value);
            Assert.NotNull(resp.Headers);
            Assert.NotNull(resp.Response);
            Assert.Equal("DESKTOP-GNQ5SUT", resp.Response.InstanceId);
            Assert.Equal("DESKTOP-GNQ5SUT:80", resp.Response.VipAddress);
            Assert.Equal("DESKTOP-GNQ5SUT", resp.Response.HostName);
            Assert.Equal("192.168.0.147", resp.Response.IpAddr);
            Assert.Equal(InstanceStatus.UP, resp.Response.Status);
        }
        public async System.Threading.Tasks.Task GetInstanceAsync_FirstServerFails_InvokesSecondServer_ReturnsExpectedInstances()
        {
            var json  = @"
                { 
                    ""instance"":{
                        ""instanceId"":""DESKTOP-GNQ5SUT"",
                        ""app"":""FOOBAR"",
                        ""appGroupName"":null,
                        ""ipAddr"":""192.168.0.147"",
                        ""sid"":""na"",
                        ""port"":{""@enabled"":true,""$"":80},
                        ""securePort"":{""@enabled"":false,""$"":443},
                        ""homePageUrl"":""http://*****:*****@class"":""com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo"",""name"":""MyOwn""},
                        ""hostName"":""DESKTOP-GNQ5SUT"",
                        ""status"":""UP"",
                        ""overriddenstatus"":""UNKNOWN"",
                        ""leaseInfo"":{""renewalIntervalInSecs"":30,""durationInSecs"":90,""registrationTimestamp"":0,""lastRenewalTimestamp"":0,""renewalTimestamp"":0,""evictionTimestamp"":0,""serviceUpTimestamp"":0},
                        ""isCoordinatingDiscoveryServer"":false,
                        ""metadata"":{""@class"":""java.util.Collections$EmptyMap"",""metadata"":null},
                        ""lastUpdatedTimestamp"":1458116137663,
                        ""lastDirtyTimestamp"":1458116137663,
                        ""actionType"":""ADDED"",
                        ""asgName"":null
                    }
                }";
            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.GetInstanceAsync("DESKTOP-GNQ5SUT");

            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("/instances/DESKTOP-GNQ5SUT", TestConfigServerStartup.LastRequest.Path.Value);
            Assert.NotNull(resp.Headers);
            Assert.NotNull(resp.Response);
            Assert.Equal("DESKTOP-GNQ5SUT", resp.Response.InstanceId);
            Assert.Equal("DESKTOP-GNQ5SUT:80", resp.Response.VipAddress);
            Assert.Equal("DESKTOP-GNQ5SUT", resp.Response.HostName);
            Assert.Equal("192.168.0.147", resp.Response.IpAddr);
            Assert.Equal(InstanceStatus.UP, resp.Response.Status);

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