public void UpdateFromDelta_AddNewAppNewInstance_UpdatesCorrectly() { Application app1 = new Application("app1"); app1.Add(new InstanceInfo() { AppName = "app1", InstanceId = "id1", VipAddress = "vapp1", SecureVipAddress = "svapp1" }); app1.Add(new InstanceInfo() { AppName = "app1", InstanceId = "id2", VipAddress = "vapp1", SecureVipAddress = "svapp1" }); Application app2 = new Application("app2"); app2.Add(new InstanceInfo() { AppName = "app2", InstanceId = "id1", VipAddress = "vapp2", SecureVipAddress = "svapp2" }); app2.Add(new InstanceInfo() { AppName = "app2", InstanceId = "id2", VipAddress = "vapp2", SecureVipAddress = "svapp2" }); var apps = new Applications(); apps.Add(app1); apps.Add(app2); var delta = new Applications(); Application app3 = new Application("app3"); app3.Add(new InstanceInfo() { AppName = "app3", InstanceId = "id1", VipAddress = "vapp3", SecureVipAddress = "svapp3", Actiontype = ActionType.ADDED }); delta.Add(app3); apps.UpdateFromDelta(delta); var registered = apps.GetRegisteredApplication("app1"); Assert.NotNull(registered); Assert.Equal("app1", registered.Name); Assert.NotNull(registered.Instances); Assert.Equal(2, registered.Instances.Count); registered = apps.GetRegisteredApplication("app2"); Assert.NotNull(registered); Assert.Equal("app2", registered.Name); Assert.NotNull(registered.Instances); Assert.Equal(2, registered.Instances.Count); registered = apps.GetRegisteredApplication("app3"); Assert.NotNull(registered); Assert.Equal("app3", registered.Name); Assert.NotNull(registered.Instances); Assert.Equal(1, registered.Instances.Count); var result = apps.GetInstancesByVirtualHostName("vapp1"); Assert.NotNull(result); Assert.Equal(2, result.Count); Assert.True(result.Contains(app1.GetInstance("id1"))); Assert.True(result.Contains(app1.GetInstance("id2"))); result = apps.GetInstancesByVirtualHostName("vapp2"); Assert.NotNull(result); Assert.Equal(2, result.Count); Assert.True(result.Contains(app2.GetInstance("id1"))); Assert.True(result.Contains(app2.GetInstance("id2"))); result = apps.GetInstancesByVirtualHostName("vapp3"); Assert.NotNull(result); Assert.Equal(1, result.Count); Assert.True(result.Contains(app3.GetInstance("id1"))); result = apps.GetInstancesByVirtualHostName("foobar"); Assert.NotNull(result); Assert.Equal(0, result.Count); }
public void GetInstancesByVirtualHostName_ReturnsExpected() { Application app1 = new Application("app1"); app1.Add(new InstanceInfo() { InstanceId = "id1", VipAddress = "vapp1", SecureVipAddress = "svapp1" }); app1.Add(new InstanceInfo() { InstanceId = "id2", VipAddress = "vapp1", SecureVipAddress = "svapp1" }); Application app2 = new Application("app2"); app2.Add(new InstanceInfo() { InstanceId = "id1", VipAddress = "vapp2", SecureVipAddress = "svapp2" }); app2.Add(new InstanceInfo() { InstanceId = "id2", VipAddress = "vapp2", SecureVipAddress = "svapp2" }); var apps = new Applications(); apps.Add(app1); apps.Add(app2); var result = apps.GetInstancesByVirtualHostName("vapp1"); Assert.NotNull(result); Assert.Equal(2, result.Count); Assert.True(result.Contains(app1.GetInstance("id1"))); Assert.True(result.Contains(app1.GetInstance("id2"))); result = apps.GetInstancesByVirtualHostName("vapp2"); Assert.NotNull(result); Assert.Equal(2, result.Count); Assert.True(result.Contains(app2.GetInstance("id1"))); Assert.True(result.Contains(app2.GetInstance("id2"))); result = apps.GetInstancesByVirtualHostName("foobar"); Assert.NotNull(result); Assert.Equal(0, result.Count); }
public void UpdateFromDelta_ExistingAppWithRemovedInstance_UpdatesCorrectly() { Application app1 = new Application("app1"); app1.Add(new InstanceInfo() { AppName = "app1", InstanceId = "id1", VipAddress = "vapp1", SecureVipAddress = "svapp1" }); app1.Add(new InstanceInfo() { AppName = "app1", InstanceId = "id2", VipAddress = "vapp1", SecureVipAddress = "svapp1" }); Application app2 = new Application("app2"); app2.Add(new InstanceInfo() { AppName = "app2", InstanceId = "id1", VipAddress = "vapp2", SecureVipAddress = "svapp2", Status = InstanceStatus.UP }); app2.Add(new InstanceInfo() { AppName = "app2", InstanceId = "id2", VipAddress = "vapp2", SecureVipAddress = "svapp2", Status = InstanceStatus.DOWN }); var apps = new Applications(); apps.Add(app1); apps.Add(app2); var delta = new Applications(); Application deltaApp3 = new Application("app2"); deltaApp3.Add(new InstanceInfo() { AppName = "app2", InstanceId = "id2", VipAddress = "vapp2", SecureVipAddress = "svapp2", Actiontype = ActionType.DELETED }); delta.Add(deltaApp3); apps.UpdateFromDelta(delta); var registered = apps.GetRegisteredApplication("app1"); Assert.NotNull(registered); Assert.Equal("app1", registered.Name); Assert.NotNull(registered.Instances); Assert.Equal(2, registered.Instances.Count); registered = apps.GetRegisteredApplication("app2"); Assert.NotNull(registered); Assert.Equal("app2", registered.Name); Assert.NotNull(registered.Instances); Assert.Equal(1, registered.Instances.Count); foreach (var inst in registered.Instances) { Assert.Equal(InstanceStatus.UP, inst.Status); } var result = apps.GetInstancesByVirtualHostName("vapp1"); Assert.NotNull(result); Assert.Equal(2, result.Count); Assert.True(result.Contains(app1.GetInstance("id1"))); Assert.True(result.Contains(app1.GetInstance("id2"))); result = apps.GetInstancesByVirtualHostName("vapp2"); Assert.NotNull(result); Assert.Equal(1, result.Count); Assert.True(result.Contains(app2.GetInstance("id1"))); Assert.False(result.Contains(app2.GetInstance("id2"))); result = apps.GetInstancesByVirtualHostName("foobar"); Assert.NotNull(result); Assert.Equal(0, result.Count); }
public void GetInstancesByVirtualHostName_ThrowsIfAddressNull() { Applications apps = new Applications(); var ex = Assert.Throws <ArgumentException>(() => apps.GetInstancesByVirtualHostName(null)); Assert.Contains("virtualHostName", ex.Message); }
public void UpdateFromDelta_EmptyDelta_NoChange() { Application app1 = new Application("app1"); app1.Add(new InstanceInfo() { AppName = "app1", InstanceId = "id1", VipAddress = "vapp1", SecureVipAddress = "svapp1" }); app1.Add(new InstanceInfo() { AppName = "app1", InstanceId = "id2", VipAddress = "vapp1", SecureVipAddress = "svapp1" }); Application app2 = new Application("app2"); app2.Add(new InstanceInfo() { AppName = "app2", InstanceId = "id1", VipAddress = "vapp2", SecureVipAddress = "svapp2" }); app2.Add(new InstanceInfo() { AppName = "app2", InstanceId = "id2", VipAddress = "vapp2", SecureVipAddress = "svapp2" }); var apps = new Applications(); apps.Add(app1); apps.Add(app2); var delta = new Applications(); apps.UpdateFromDelta(delta); var registered = apps.GetRegisteredApplication("app1"); Assert.NotNull(registered); Assert.Equal("app1", registered.Name); Assert.NotNull(registered.Instances); Assert.Equal(2, registered.Instances.Count); registered = apps.GetRegisteredApplication("app2"); Assert.NotNull(registered); Assert.Equal("app2", registered.Name); Assert.NotNull(registered.Instances); Assert.Equal(2, registered.Instances.Count); var result = apps.GetInstancesByVirtualHostName("vapp1"); Assert.NotNull(result); Assert.Equal(2, result.Count); Assert.True(result.Contains(app1.GetInstance("id1"))); Assert.True(result.Contains(app1.GetInstance("id2"))); result = apps.GetInstancesByVirtualHostName("vapp2"); Assert.NotNull(result); Assert.Equal(2, result.Count); Assert.True(result.Contains(app2.GetInstance("id1"))); Assert.True(result.Contains(app2.GetInstance("id2"))); result = apps.GetInstancesByVirtualHostName("foobar"); Assert.NotNull(result); Assert.Equal(0, result.Count); }