public void Deserialize_GoodJson() { var json = @"{ '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' }] }] }"; Stream stream = TestHelpers.StringToStream(json); var result = JsonApplications.Deserialize(stream); Assert.NotNull(result); Assert.Equal("UP_1_", result.AppsHashCode); Assert.Equal(1, result.VersionDelta); Assert.NotNull(result.Applications); Assert.Equal(1, result.Applications.Count); // Rest is validated by JsonApplicationTest }
public void Deserialize_GoodJson() { var json = @" { ""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 stream = TestHelpers.StringToStream(json); var result = JsonApplications.Deserialize(stream); Assert.NotNull(result); Assert.Equal("UP_1_", result.AppsHashCode); Assert.Equal(1, result.VersionDelta); Assert.NotNull(result.Applications); Assert.Equal(1, result.Applications.Count); // Rest is validated by JsonApplicationTest }
internal static Applications FromJsonApplications(JsonApplications japps) { Applications apps = new Applications(); if (japps != null) { apps.Version = japps.VersionDelta; apps.AppsHashCode = japps.AppsHashCode; if (japps.Applications != null) { foreach (var japp in japps.Applications) { var app = Application.FromJsonApplication(japp); apps.Add(app); } } } return(apps); }
public void FromJsonApplications_Correct() { JsonInstanceInfo jinfo = new JsonInstanceInfo() { InstanceId = "InstanceId", AppName = "myApp", AppGroupName = "AppGroupName", IpAddr = "IpAddr", Sid = "Sid", Port = new JsonInstanceInfo.JsonPortWrapper(true, 100), SecurePort = new JsonInstanceInfo.JsonPortWrapper(false, 100), HomePageUrl = "HomePageUrl", StatusPageUrl = "StatusPageUrl", HealthCheckUrl = "HealthCheckUrl", SecureHealthCheckUrl = "SecureHealthCheckUrl", VipAddress = "VipAddress", SecureVipAddress = "SecureVipAddress", CountryId = 1, DataCenterInfo = new JsonInstanceInfo.JsonDataCenterInfo(string.Empty, "MyOwn"), HostName = "HostName", Status = InstanceStatus.DOWN, OverriddenStatus = InstanceStatus.OUT_OF_SERVICE, LeaseInfo = new JsonLeaseInfo() { RenewalIntervalInSecs = 1, DurationInSecs = 2, RegistrationTimestamp = 1457973741708, LastRenewalTimestamp = 1457973741708, LastRenewalTimestampLegacy = 1457973741708, EvictionTimestamp = 1457973741708, ServiceUpTimestamp = 1457973741708 }, IsCoordinatingDiscoveryServer = false, Metadata = new Dictionary <string, string>() { { "@class", "java.util.Collections$EmptyMap" } }, LastUpdatedTimestamp = 1457973741708, LastDirtyTimestamp = 1457973741708, Actiontype = ActionType.ADDED, AsgName = "AsgName" }; JsonApplication japp = new JsonApplication() { Name = "myApp", Instances = new List <JsonInstanceInfo> { jinfo } }; JsonApplications japps = new JsonApplications() { AppsHashCode = "AppsHashCode", VersionDelta = 1L, Applications = new List <JsonApplication>() { japp } }; Applications apps = Applications.FromJsonApplications(japps); Assert.Equal("AppsHashCode", apps.AppsHashCode); Assert.Equal(1, apps.Version); Assert.NotNull(apps.ApplicationMap); Assert.Single(apps.ApplicationMap); Application app = apps.GetRegisteredApplication("myApp"); // Verify Assert.NotNull(app); Assert.Equal("myApp", app.Name); Assert.NotNull(app.Instances); Assert.Equal(1, app.Count); Assert.Equal(1, app.Instances.Count); Assert.NotNull(app.GetInstance("InstanceId")); InstanceInfo info = app.GetInstance("InstanceId"); Assert.Equal("InstanceId", info.InstanceId); Assert.Equal("myApp", info.AppName); Assert.Equal("AppGroupName", info.AppGroupName); Assert.Equal("IpAddr", info.IpAddr); Assert.Equal("Sid", info.Sid); Assert.Equal(100, info.Port); Assert.True(info.IsUnsecurePortEnabled); Assert.Equal(100, info.SecurePort); Assert.False(info.IsSecurePortEnabled); Assert.Equal("HomePageUrl", info.HomePageUrl); Assert.Equal("StatusPageUrl", info.StatusPageUrl); Assert.Equal("HealthCheckUrl", info.HealthCheckUrl); Assert.Equal("SecureHealthCheckUrl", info.SecureHealthCheckUrl); Assert.Equal("VipAddress", info.VipAddress); Assert.Equal("SecureVipAddress", info.SecureVipAddress); Assert.Equal(1, info.CountryId); Assert.Equal("MyOwn", info.DataCenterInfo.Name.ToString()); Assert.Equal("HostName", info.HostName); Assert.Equal(InstanceStatus.DOWN, info.Status); Assert.Equal(InstanceStatus.OUT_OF_SERVICE, info.OverriddenStatus); Assert.NotNull(info.LeaseInfo); Assert.Equal(1, info.LeaseInfo.RenewalIntervalInSecs); Assert.Equal(2, info.LeaseInfo.DurationInSecs); Assert.Equal(635935705417080000L, info.LeaseInfo.RegistrationTimestamp); Assert.Equal(635935705417080000L, info.LeaseInfo.LastRenewalTimestamp); Assert.Equal(635935705417080000L, info.LeaseInfo.LastRenewalTimestampLegacy); Assert.Equal(635935705417080000L, info.LeaseInfo.EvictionTimestamp); Assert.Equal(635935705417080000L, info.LeaseInfo.ServiceUpTimestamp); Assert.False(info.IsCoordinatingDiscoveryServer); Assert.NotNull(info.Metadata); Assert.Empty(info.Metadata); Assert.Equal(635935705417080000L, info.LastUpdatedTimestamp); Assert.Equal(635935705417080000L, info.LastDirtyTimestamp); Assert.Equal(ActionType.ADDED, info.Actiontype); Assert.Equal("AsgName", info.AsgName); }
public void FromJsonApplications_WithMissingInstanceId() { var jinfo = new JsonInstanceInfo() { // InstanceId = "InstanceId", AppName = "myApp", AppGroupName = "AppGroupName", IpAddr = "IpAddr", Sid = "Sid", Port = new JsonInstanceInfo.JsonPortWrapper(true, 100), SecurePort = new JsonInstanceInfo.JsonPortWrapper(false, 100), HomePageUrl = "HomePageUrl", StatusPageUrl = "StatusPageUrl", HealthCheckUrl = "HealthCheckUrl", SecureHealthCheckUrl = "SecureHealthCheckUrl", VipAddress = "VipAddress", SecureVipAddress = "SecureVipAddress", CountryId = 1, DataCenterInfo = new JsonInstanceInfo.JsonDataCenterInfo(string.Empty, "MyOwn"), HostName = "HostName", Status = InstanceStatus.DOWN, OverriddenStatus = InstanceStatus.OUT_OF_SERVICE, LeaseInfo = new JsonLeaseInfo() { RenewalIntervalInSecs = 1, DurationInSecs = 2, RegistrationTimestamp = 1457973741708, LastRenewalTimestamp = 1457973741708, LastRenewalTimestampLegacy = 1457973741708, EvictionTimestamp = 1457973741708, ServiceUpTimestamp = 1457973741708 }, IsCoordinatingDiscoveryServer = false, Metadata = new Dictionary <string, string>() { { "@class", "java.util.Collections$EmptyMap" } }, LastUpdatedTimestamp = 1457973741708, LastDirtyTimestamp = 1457973741708, Actiontype = ActionType.ADDED, AsgName = "AsgName" }; var japp = new JsonApplication() { Name = "myApp", Instances = new List <JsonInstanceInfo> { jinfo } }; var japps = new JsonApplications() { AppsHashCode = "AppsHashCode", VersionDelta = 1L, Applications = new List <JsonApplication>() { japp } }; var apps = Applications.FromJsonApplications(japps); Assert.Equal("AppsHashCode", apps.AppsHashCode); Assert.Equal(1, apps.Version); Assert.NotNull(apps.ApplicationMap); Assert.Single(apps.ApplicationMap); var app = apps.GetRegisteredApplication("myApp"); // Verify Assert.NotNull(app); Assert.Equal("myApp", app.Name); Assert.NotNull(app.Instances); Assert.Equal(1, app.Count); Assert.Equal(1, app.Instances.Count); Assert.Null(app.GetInstance("InstanceId")); }