public void WhenInstanceRunningAndMultiplePlacementWithStopsInBetweenRegistered_ThenInstanceContainsRightPlacements() { var b = InstanceHistoryBuilder.ForExistingInstance( 1, SampleReference, SampleImage, InstanceState.Running, new DateTime(2019, 12, 31), Tenancy.SoleTenant); b.OnSetPlacement("server-2", new DateTime(2019, 12, 30)); b.OnStop(new DateTime(2019, 12, 29), SampleReference); b.OnSetPlacement("server-1", new DateTime(2019, 12, 28)); var i = b.Build(); var placements = i.Placements.ToList(); Assert.AreEqual(2, i.Placements.Count()); Assert.AreEqual("server-1", placements[0].ServerId); Assert.AreEqual(new DateTime(2019, 12, 28), placements[0].From); Assert.AreEqual(new DateTime(2019, 12, 29), placements[0].To); Assert.AreEqual("server-2", placements[1].ServerId); Assert.AreEqual(new DateTime(2019, 12, 30), placements[1].From); Assert.AreEqual(new DateTime(2019, 12, 31), placements[1].To); }
public void WhenInstanceRunningAndMultiplePlacementsRegistered_ThenInstanceContainsRightPlacements() { var b = InstanceHistoryBuilder.ForExistingInstance( 1, SampleReference, SampleImage, InstanceState.Running, new DateTime(2019, 12, 31), Tenancies.SoleTenant, "server-2", null); b.OnSetPlacement("server-2", null, new DateTime(2019, 12, 30)); b.OnSetPlacement("server-1", SampleNodeType, new DateTime(2019, 12, 29)); var i = b.Build(new DateTime(2019, 12, 1)); var placements = i.Placements.ToList(); Assert.AreEqual(2, i.Placements.Count()); Assert.AreEqual("server-1", placements[0].ServerId); Assert.AreEqual(SampleNodeType, placements[0].NodeType); Assert.AreEqual(new DateTime(2019, 12, 29), placements[0].From); Assert.AreEqual(new DateTime(2019, 12, 30), placements[0].To); Assert.AreEqual("server-2", placements[1].ServerId); Assert.IsNull(placements[1].NodeType); Assert.AreEqual(new DateTime(2019, 12, 30), placements[1].From); Assert.AreEqual(new DateTime(2019, 12, 31), placements[1].To); }
public void WhenInstanceRunningAndSinglePlacementRegistered_ThenInstanceContainsRightPlacements() { var b = InstanceHistoryBuilder.ForExistingInstance( 1, SampleReference, SampleImage, InstanceState.Running, new DateTime(2019, 12, 31), Tenancies.SoleTenant, "server-1", null); b.OnSetPlacement("server-1", null, new DateTime(2019, 12, 30)); var i = b.Build(new DateTime(2019, 12, 1)); Assert.AreEqual(1, i.InstanceId); Assert.AreEqual(1, i.Placements.Count()); var placement = i.Placements.First(); Assert.AreEqual("server-1", placement.ServerId); Assert.AreEqual(new DateTime(2019, 12, 30), placement.From); Assert.AreEqual(new DateTime(2019, 12, 31), placement.To); }
public void WhenPlacementsWithDifferentServerIdsRegistered_ThenPlacementsAreKept() { var b = InstanceHistoryBuilder.ForExistingInstance( 1, SampleReference, SampleImage, InstanceState.Running, new DateTime(2019, 12, 31), Tenancies.SoleTenant, "server-1", SampleNodeType); b.OnSetPlacement("server-1", SampleNodeType, new DateTime(2019, 12, 30)); b.OnSetPlacement("server-2", null, new DateTime(2019, 12, 29)); var placements = b.Build().Placements.ToList(); Assert.AreEqual(2, placements.Count()); Assert.AreEqual("server-2", placements[0].ServerId); Assert.IsNull(placements[0].NodeType); Assert.AreEqual(new DateTime(2019, 12, 29), placements[0].From); Assert.AreEqual(new DateTime(2019, 12, 30), placements[0].To); Assert.AreEqual("server-1", placements[1].ServerId); Assert.AreEqual(SampleNodeType, placements[1].NodeType); Assert.AreEqual(new DateTime(2019, 12, 30), placements[1].From); Assert.AreEqual(new DateTime(2019, 12, 31), placements[1].To); }
public void WhenInstanceExists_ThenStateIsComplete() { var b = InstanceHistoryBuilder.ForExistingInstance( 1, SampleReference, SampleImage, InstanceState.Running, DateTime.Now, Tenancy.SoleTenant); Assert.AreEqual(InstanceHistoryState.Complete, b.State); }
public void WhenRedundantPlacementsRegistered_ThenSecondPlacementIsIgnored() { var b = InstanceHistoryBuilder.ForExistingInstance( 1, SampleReference, SampleImage, InstanceState.Terminated, new DateTime(2019, 12, 31), Tenancy.SoleTenant); b.OnSetPlacement("server-1", new DateTime(2019, 12, 30)); b.OnSetPlacement("server-1", new DateTime(2019, 12, 29)); var placements = b.Build().Placements.ToList(); Assert.AreEqual(1, placements.Count()); Assert.AreEqual(new DateTime(2019, 12, 29), placements[0].From); Assert.AreEqual(new DateTime(2019, 12, 31), placements[0].To); }
public void WhenPlacementsWithSameServerIdAfterStopRegistered_ThenPlacementsAreKept() { var b = InstanceHistoryBuilder.ForExistingInstance( 1, SampleReference, SampleImage, InstanceState.Running, new DateTime(2019, 12, 31), Tenancy.SoleTenant); b.OnSetPlacement("server-1", new DateTime(2019, 12, 30)); b.OnStop(new DateTime(2019, 12, 29), SampleReference); b.OnSetPlacement("server-1", new DateTime(2019, 12, 28)); var placements = b.Build().Placements.ToList(); Assert.AreEqual(2, placements.Count()); Assert.AreEqual(new DateTime(2019, 12, 28), placements[0].From); Assert.AreEqual(new DateTime(2019, 12, 29), placements[0].To); Assert.AreEqual(new DateTime(2019, 12, 30), placements[1].From); Assert.AreEqual(new DateTime(2019, 12, 31), placements[1].To); }
public void WhenInstanceRunningAndNoPlacementRegistered_ThenInstanceHasSyntheticPlacementSpanningEntirePeriod() { var reportStartDate = new DateTime(2019, 12, 1); var lastSeen = new DateTime(2019, 12, 31); var b = InstanceHistoryBuilder.ForExistingInstance( 1, SampleReference, SampleImage, InstanceState.Running, lastSeen, Tenancies.SoleTenant, "server-2", null); var i = b.Build(reportStartDate); var placements = i.Placements.ToList(); Assert.AreEqual(1, i.Placements.Count()); Assert.AreEqual("server-2", placements[0].ServerId); Assert.AreEqual(reportStartDate, placements[0].From); Assert.AreEqual(lastSeen, placements[0].To); }