public async void DeleteStatusOverrideAsync_InvokesServer_ReturnsStatusCodeAndHeaders() { var startup = new TestConfigServerStartup("", 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()); var now = DateTime.UtcNow.Ticks; var javaTime = DateTimeConversions.ToJavaMillis(new DateTime(now, DateTimeKind.Utc)); EurekaHttpResponse resp = await client.DeleteStatusOverrideAsync("foo", "bar", new InstanceInfo() { LastDirtyTimestamp = now }); Assert.NotNull(resp); Assert.Equal(HttpStatusCode.OK, resp.StatusCode); Assert.NotNull(resp.Headers); Assert.Equal("DELETE", startup.LastRequest.Method); Assert.Equal("localhost:8888", startup.LastRequest.Host.Value); Assert.Equal("/apps/foo/bar/status", startup.LastRequest.Path.Value); Assert.Equal("?lastDirtyTimestamp=" + javaTime, startup.LastRequest.QueryString.Value); }
public async void SendHeartBeatAsync_InvokesServer_ReturnsStatusCodeAndHeaders() { var startup = new TestConfigServerStartup("", 200); var server = TestServer.Create(startup.Configure); var uri = "http://localhost:8888/"; server.BaseAddress = new Uri(uri); EurekaInstanceConfig config = new EurekaInstanceConfig() { AppName = "foo", InstanceId = "id1" }; InstanceInfo info = InstanceInfo.FromInstanceConfig(config); var cconfig = new EurekaClientConfig() { EurekaServerServiceUrls = uri }; var client = new EurekaHttpClient(cconfig, server.CreateClient()); EurekaHttpResponse <InstanceInfo> resp = await client.SendHeartBeatAsync("foo", "id1", info, InstanceStatus.UNKNOWN); Assert.NotNull(resp); Assert.Equal(HttpStatusCode.OK, resp.StatusCode); Assert.NotNull(resp.Headers); Assert.Equal("PUT", startup.LastRequest.Method); Assert.Equal("localhost:8888", startup.LastRequest.Host.Value); Assert.Equal("/apps/FOO/id1", startup.LastRequest.Path.Value); var time = DateTimeConversions.ToJavaMillis(new DateTime(info.LastDirtyTimestamp, DateTimeKind.Utc)); Assert.Equal("?status=STARTING&lastDirtyTimestamp=" + time, startup.LastRequest.QueryString.Value); }
public async void RenewAsync_ReturnsTrue_WhenOKStatusReturned() { var startup = new TestConfigServerStartup("", 200); var server = TestServer.Create(startup.Configure); var uri = "http://localhost:8888/"; server.BaseAddress = new Uri(uri); EurekaClientConfig config = new EurekaClientConfig() { ShouldFetchRegistry = false, ShouldRegisterWithEureka = false, EurekaServerServiceUrls = uri.ToString() }; InstanceInfo inst = new InstanceInfo() { InstanceId = "localhost:foo", HostName = "localhost", AppName = "FOO", IpAddr = "192.168.56.1", Status = InstanceStatus.STARTING }; ApplicationInfoManager.Instance.InstanceInfo = inst; var httpClient = new EurekaHttpClient(config, server.CreateClient()); DiscoveryClient client = new DiscoveryClient(config, httpClient); var result = await client.RenewAsync(); Assert.True(result); }
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 void RegisterAsync_InvokesServer_ReturnsStatusCodeAndHeaders() { var startup = new TestConfigServerStartup("", 204); var server = TestServer.Create(startup.Configure); var uri = "http://localhost:8888/"; server.BaseAddress = new Uri(uri); EurekaInstanceConfig config = new EurekaInstanceConfig(); InstanceInfo info = InstanceInfo.FromInstanceConfig(config); var cconfig = new EurekaClientConfig() { EurekaServerServiceUrls = uri }; var client = new EurekaHttpClient(cconfig, server.CreateClient()); EurekaHttpResponse resp = await client.RegisterAsync(info); Assert.NotNull(resp); Assert.Equal(HttpStatusCode.NoContent, resp.StatusCode); Assert.NotNull(resp.Headers); }
public async void CancelAsync_InvokesServer_ReturnsStatusCodeAndHeaders() { var startup = new TestConfigServerStartup("", 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 resp = await client.CancelAsync("foo", "bar"); Assert.NotNull(resp); Assert.Equal(HttpStatusCode.OK, resp.StatusCode); Assert.NotNull(resp.Headers); Assert.Equal("DELETE", startup.LastRequest.Method); Assert.Equal("localhost:8888", startup.LastRequest.Host.Value); Assert.Equal("/apps/foo/bar", startup.LastRequest.Path.Value); }
public async void RegisterAsync_SendsValidPOSTData() { var startup = new TestConfigServerStartup("", 204); var server = TestServer.Create(startup.Configure); var uri = "http://localhost:8888/"; server.BaseAddress = new Uri(uri); EurekaInstanceConfig config = new EurekaInstanceConfig() { AppName = "foobar" }; InstanceInfo info = InstanceInfo.FromInstanceConfig(config); var cconfig = new EurekaClientConfig() { EurekaServerServiceUrls = uri }; var client = new EurekaHttpClient(cconfig, server.CreateClient()); EurekaHttpResponse resp = await client.RegisterAsync(info); Assert.NotNull(startup.LastRequest); Assert.Equal("POST", startup.LastRequest.Method); Assert.Equal("localhost:8888", startup.LastRequest.Host.Value); Assert.Equal("/apps/FOOBAR", startup.LastRequest.Path.Value); // Check JSON payload JsonInstanceInfoRoot recvJson = JsonInstanceInfoRoot.Deserialize(startup.RequestBody); Assert.NotNull(recvJson); Assert.NotNull(recvJson.Instance); // Compare a few random values JsonInstanceInfo sentJsonObj = info.ToJsonInstance(); Assert.Equal(sentJsonObj.Actiontype, recvJson.Instance.Actiontype); Assert.Equal(sentJsonObj.AppName, recvJson.Instance.AppName); Assert.Equal(sentJsonObj.HostName, recvJson.Instance.HostName); }
public void FetchRegistryDeltaAsync_ReturnsNull_IfFetchCounterMismatch() { var startup = new TestConfigServerStartup("", 200); var server = TestServer.Create(startup.Configure); var uri = "http://localhost:8888/"; server.BaseAddress = new Uri(uri); EurekaClientConfig config = new EurekaClientConfig() { ShouldFetchRegistry = false, ShouldRegisterWithEureka = false, EurekaServerServiceUrls = uri.ToString() }; var httpClient = new EurekaHttpClient(config, server.CreateClient()); DiscoveryClient client = new DiscoveryClient(config, httpClient); var result = client.FetchRegistryDeltaAsync(); client.RegistryFetchCounter = 100; var apps = result.GetAwaiter().GetResult(); Assert.Null(apps); }
public async void RenewAsync_Registers_When404StatusReturned() { var startup = new TestConfigServerStartup("", 404); var server = TestServer.Create(startup.Configure); var uri = "http://localhost:8888/"; server.BaseAddress = new Uri(uri); EurekaClientConfig config = new EurekaClientConfig() { ShouldFetchRegistry = false, ShouldRegisterWithEureka = false, EurekaServerServiceUrls = uri.ToString() }; InstanceInfo inst = new InstanceInfo() { InstanceId = "localhost:foo", HostName = "localhost", AppName = "FOO", IpAddr = "192.168.56.1", Status = InstanceStatus.STARTING }; ApplicationInfoManager.Instance.InstanceInfo = inst; var httpClient = new EurekaHttpClient(config, server.CreateClient()); DiscoveryClient client = new DiscoveryClient(config, httpClient); var result = await client.RenewAsync(); // Verify Register done Assert.NotNull(startup.LastRequest); Assert.Equal("POST", startup.LastRequest.Method); Assert.Equal("localhost:8888", startup.LastRequest.Host.Value); Assert.Equal("/apps/FOO", startup.LastRequest.Path.Value); // Still false as register returns 404 still Assert.False(result); }
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' }] } }"; 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 <Application> resp = await client.GetApplicationAsync("foo"); 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("/apps/foo", startup.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); } }
public async void FetchFullRegistryAsync_InvokesServer_ReturnsValidResponse() { var json = @"{ 'applications': { 'versions__delta':'1', 'apps__hashcode':'UP_1_', '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':1457714988223,'lastRenewalTimestamp':1457716158319,'evictionTimestamp':0,'serviceUpTimestamp':1457714988223}, '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':'1457714988223', 'lastDirtyTimestamp':'1457714988172', 'actionType':'ADDED' }] }] } }"; var startup = new TestConfigServerStartup(json, 200); var server = TestServer.Create(startup.Configure); var uri = "http://localhost:8888/"; server.BaseAddress = new Uri(uri); EurekaClientConfig config = new EurekaClientConfig() { ShouldFetchRegistry = false, ShouldRegisterWithEureka = false, EurekaServerServiceUrls = uri.ToString() }; var httpClient = new EurekaHttpClient(config, server.CreateClient()); DiscoveryClient client = new DiscoveryClient(config, httpClient); var result = await client.FetchFullRegistryAsync(); Assert.NotNull(result); Assert.Equal(1, result.Version); Assert.Equal("UP_1_", result.AppsHashCode); var apps = result.GetRegisteredApplications(); Assert.NotNull(apps); Assert.Equal(1, apps.Count); Assert.Equal("FOO", apps[0].Name); }