Esempio n. 1
0
        public async void ReconcileAsyncOnSetPlan()
        {
            var desiredModule       = new TestModule("desired", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null);
            var currentModule       = new TestModule("current", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null);
            var recordKeeper        = Option.Some(new TestPlanRecorder());
            var moduleExecutionList = new List <TestRecordType>
            {
                new TestRecordType(TestCommandType.TestCreate, desiredModule),
                new TestRecordType(TestCommandType.TestRemove, currentModule)
            };
            var commandList = new List <ICommand>
            {
                new TestCommand(TestCommandType.TestCreate, desiredModule, recordKeeper),
                new TestCommand(TestCommandType.TestRemove, currentModule, recordKeeper)
            };
            var testPlan = new Plan(commandList);

            var token = new CancellationToken();

            var runtimeInfo      = Mock.Of <IRuntimeInfo>();
            var deploymentConfig = new DeploymentConfig("1.0", runtimeInfo, new SystemModules(null, null), new Dictionary <string, IModule> {
                ["desired"] = desiredModule
            });
            var       deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig);
            ModuleSet desiredSet           = deploymentConfig.GetModuleSet();
            ModuleSet currentSet           = ModuleSet.Create(currentModule);

            var mockConfigSource = new Mock <IConfigSource>();
            var mockEnvironment  = new Mock <IEnvironment>();
            var mockPlanner      = new Mock <IPlanner>();
            var planRunner       = new OrderedPlanRunner();
            var mockReporter     = new Mock <IReporter>();
            var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>();
            var configStore             = Mock.Of <IEntityStore <string, string> >();
            var mockEnvironmentProvider = Mock.Of <IEnvironmentProvider>(m => m.Create(It.IsAny <DeploymentConfig>()) == mockEnvironment.Object);
            var serde = Mock.Of <ISerde <DeploymentConfigInfo> >();
            var encryptionDecryptionProvider = Mock.Of <IEncryptionProvider>();

            mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(deploymentConfigInfo);
            mockEnvironment.Setup(env => env.GetModulesAsync(token))
            .ReturnsAsync(currentSet);
            mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(desiredSet, currentSet))
            .ReturnsAsync(ImmutableDictionary <string, IModuleIdentity> .Empty);
            mockPlanner.Setup(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty))
            .Returns(Task.FromResult(testPlan));
            mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(It.IsAny <ModuleSet>(), currentSet))
            .Returns(Task.FromResult((IImmutableDictionary <string, IModuleIdentity>)ImmutableDictionary <string, IModuleIdentity> .Empty));
            mockReporter.Setup(r => r.ReportAsync(token, It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <long>(), Option.Some(DeploymentStatus.Success)))
            .Returns(Task.CompletedTask);

            var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider, mockPlanner.Object, planRunner, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider);

            await agent.ReconcileAsync(token);

            mockEnvironment.Verify(env => env.GetModulesAsync(token), Times.Exactly(1));
            mockPlanner.Verify(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty), Times.Once);
            mockReporter.VerifyAll();
            recordKeeper.ForEach(r => Assert.Equal(moduleExecutionList, r.ExecutionList));
        }
        public async void TestPlanFactoryCommands()
        {
            var factory             = new TestCommandFactory();
            var runtimeInfo         = Mock.Of <IRuntimeInfo>();
            var moduleExecutionList = new List <TestRecordType>
            {
                new TestRecordType(TestCommandType.TestCreate, new TestModule("module1", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image1"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestUpdate, new TestModule("module3", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image3"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestRemove, new TestModule("module4", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image4"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestStart, new TestModule("module5", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image5"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestStop, new TestModule("module6", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image6"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars)),
            };
            var identity    = new Mock <IModuleIdentity>();
            var commandList = new List <ICommand>
            {
                await factory.CreateAsync(new ModuleWithIdentity(moduleExecutionList[0].Module, identity.Object), runtimeInfo),
                await factory.UpdateAsync(moduleExecutionList[0].Module, new ModuleWithIdentity(moduleExecutionList[1].Module, identity.Object), runtimeInfo),
                await factory.RemoveAsync(moduleExecutionList[2].Module),
                await factory.StartAsync(moduleExecutionList[3].Module),
                await factory.StopAsync(moduleExecutionList[4].Module),
            };
            var plan1      = new Plan(commandList);
            var token      = new CancellationToken();
            var planRunner = new OrderedPlanRunner();
            await planRunner.ExecuteAsync(1, plan1, token);

            Assert.All(commandList,
                       command =>
            {
                var c = command as TestCommand;
                Assert.NotNull(c);
                Assert.True(c.CommandExecuted);
            });
            factory.Recorder.ForEach(r => Assert.Equal(moduleExecutionList, r.ExecutionList));
        }
Esempio n. 3
0
        public async void RestartPlannerAdd1StoppedModule()
        {
            var factory = new TestCommandFactory();

            IModule   stoppedModule = new TestModule("mod1", "version1", "test", ModuleStatus.Stopped, Config2, RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars);
            ModuleSet addStopped    = ModuleSet.Create(stoppedModule);

            IImmutableDictionary <string, IModuleIdentity> moduleIdentities = GetModuleIdentities(new List <IModule>()
            {
                stoppedModule
            });
            var planner = new RestartPlanner(factory);
            var token   = new CancellationToken();

            var addStoppedExecutionList = new List <TestRecordType>
            {
                new TestRecordType(TestCommandType.TestCreate, stoppedModule),
            };
            Plan addStoppedPlan = await planner.PlanAsync(addStopped, ModuleSet.Empty, RuntimeInfo, moduleIdentities);

            var planRunner = new OrderedPlanRunner();
            await planRunner.ExecuteAsync(1, addStoppedPlan, token);

            factory.Recorder.ForEach(r => Assert.Equal(addStoppedExecutionList, r.ExecutionList));
        }
Esempio n. 4
0
        public async void RestartPlannerUpdate1Module()
        {
            var factory = new TestCommandFactory();

            IModule currentModule = new TestModule("mod1", "version1", "test", ModuleStatus.Running, Config1, RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars);
            IModule desiredModule = new TestModule("mod1", "version1", "test", ModuleStatus.Running, Config2, RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars);

            IImmutableDictionary <string, IModuleIdentity> moduleIdentities = GetModuleIdentities(new List <IModule>()
            {
                desiredModule
            });
            var planner = new RestartPlanner(factory);
            var token   = new CancellationToken();

            ModuleSet currentSet          = ModuleSet.Create(currentModule);
            ModuleSet desiredSet          = ModuleSet.Create(desiredModule);
            var       updateExecutionList = new List <TestRecordType>
            {
                new TestRecordType(TestCommandType.TestStop, currentModule),
                new TestRecordType(TestCommandType.TestUpdate, desiredModule),
                new TestRecordType(TestCommandType.TestStart, desiredModule),
            };
            Plan addPlan = await planner.PlanAsync(desiredSet, currentSet, RuntimeInfo, moduleIdentities);

            var planRunner = new OrderedPlanRunner();
            await planRunner.ExecuteAsync(1, addPlan, token);

            factory.Recorder.ForEach(r => Assert.Equal(updateExecutionList, r.ExecutionList));
        }
Esempio n. 5
0
        public async void TestPlanContinueOnFailure()
        {
            var runtimeInfo         = Mock.Of <IRuntimeInfo>();
            var factory             = new TestCommandFactory();
            var failureFactory      = new TestCommandFailureFactory();
            var moduleExecutionList = new List <TestRecordType>
            {
                new TestRecordType(TestCommandType.TestCreate, new TestModule("module1", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image1"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, Constants.DefaultPriority, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestUpdate, new TestModule("module3", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image3"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, Constants.DefaultPriority, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestRemove, new TestModule("module4", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image4"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, Constants.DefaultPriority, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestStart, new TestModule("module5", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image5"), RestartPolicy.OnUnhealthy, ImagePullPolicy.Never, Constants.DefaultPriority, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestStop, new TestModule("module6", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image6"), RestartPolicy.OnUnhealthy, ImagePullPolicy.Never, Constants.DefaultPriority, DefaultConfigurationInfo, EnvVars)),
            };
            var identity    = new Mock <IModuleIdentity>();
            var commandList = new List <ICommand>
            {
                await failureFactory.CreateAsync(new ModuleWithIdentity(moduleExecutionList[0].Module, identity.Object), runtimeInfo),
                await factory.CreateAsync(new ModuleWithIdentity(moduleExecutionList[0].Module, identity.Object), runtimeInfo),
                await failureFactory.UpdateAsync(moduleExecutionList[0].Module, new ModuleWithIdentity(moduleExecutionList[1].Module, identity.Object), runtimeInfo),
                await factory.UpdateAsync(moduleExecutionList[0].Module, new ModuleWithIdentity(moduleExecutionList[1].Module, identity.Object), runtimeInfo),
                await failureFactory.RemoveAsync(moduleExecutionList[2].Module),
                await factory.RemoveAsync(moduleExecutionList[2].Module),
                await failureFactory.StartAsync(moduleExecutionList[3].Module),
                await factory.StartAsync(moduleExecutionList[3].Module),
                await failureFactory.StopAsync(moduleExecutionList[4].Module),
                await factory.StopAsync(moduleExecutionList[4].Module),
            };
            var plan1             = new Plan(commandList);
            var token             = default(CancellationToken);
            var planRunner        = new OrderedPlanRunner();
            AggregateException ex = await Assert.ThrowsAsync <AggregateException>(async() => await planRunner.ExecuteAsync(1, plan1, token));

            Assert.True(ex.InnerExceptions.Count == commandList.Count / 2);
            Assert.True(
                commandList.Where(
                    command =>
            {
                var c = command as TestCommand;
                Assert.NotNull(c);
                return(c.CommandExecuted);
            }).Count() == commandList.Count / 2);
            Assert.True(
                commandList.Where(
                    command =>
            {
                var c = command as TestCommand;
                Assert.NotNull(c);
                return(!c.CommandExecuted);
            }).Count() == commandList.Count / 2);

            factory.Recorder.ForEach(r => Assert.Equal(moduleExecutionList, r.ExecutionList));
        }
Esempio n. 6
0
        public async void RestartPlannerMinimalTest()
        {
            var factory = new TestCommandFactory();
            var planner = new RestartPlanner(factory);
            var token = new CancellationToken();

            var addExecutionList = new List<TestRecordType>();
            Plan addPlan = await planner.PlanAsync(ModuleSet.Empty, ModuleSet.Empty, RuntimeInfo, ImmutableDictionary<string, IModuleIdentity>.Empty);
            var planRunner = new OrderedPlanRunner();
            await planRunner.ExecuteAsync(1, addPlan, token);

            factory.Recorder.ForEach(r => Assert.Equal(addExecutionList, r.ExecutionList));
        }
Esempio n. 7
0
        public async void ReconcileAsyncWithNoDeploymentChange()
        {
            var desiredModule = new TestModule("CustomModule", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null);
            var currentModule = new TestModule("CustomModule", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null);

            var testPlan         = new Plan(new List <ICommand>());
            var token            = default(CancellationToken);
            var runtimeInfo      = Mock.Of <IRuntimeInfo>();
            var deploymentConfig = new DeploymentConfig("1.0", runtimeInfo, new SystemModules(null, null), new Dictionary <string, IModule> {
                ["CustomModule"] = desiredModule
            });
            var       deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig);
            ModuleSet desiredSet           = deploymentConfig.GetModuleSet();
            ModuleSet currentSet           = ModuleSet.Create(currentModule);

            var mockConfigSource = new Mock <IConfigSource>();
            var mockEnvironment  = new Mock <IEnvironment>();
            var mockPlanner      = new Mock <IPlanner>();
            var planRunner       = new OrderedPlanRunner();
            var mockReporter     = new Mock <IReporter>();
            var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>();
            var configStore             = Mock.Of <IEntityStore <string, string> >();
            var mockEnvironmentProvider = Mock.Of <IEnvironmentProvider>(m => m.Create(It.IsAny <DeploymentConfig>()) == mockEnvironment.Object);
            var serde = Mock.Of <ISerde <DeploymentConfigInfo> >();
            var encryptionDecryptionProvider = Mock.Of <IEncryptionProvider>();
            var availabilityMetric           = Mock.Of <IAvailabilityMetric>();

            mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(deploymentConfigInfo);
            mockEnvironment.Setup(env => env.GetModulesAsync(token))
            .ReturnsAsync(currentSet);
            mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(desiredSet, currentSet))
            .ReturnsAsync(ImmutableDictionary <string, IModuleIdentity> .Empty);
            mockPlanner.Setup(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty))
            .Returns(Task.FromResult(testPlan));
            mockReporter.Setup(r => r.ReportAsync(token, It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <long>(), DeploymentStatus.Success))
            .Returns(Task.CompletedTask);

            var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider, mockPlanner.Object, planRunner, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider, availabilityMetric);

            await agent.ReconcileAsync(token);

            mockEnvironment.Verify(env => env.GetModulesAsync(token), Times.Exactly(1));
            mockPlanner.Verify(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty), Times.Once);
            mockReporter.Verify(r => r.ReportAsync(token, It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <long>(), DeploymentStatus.Success), Times.Once);
        }
Esempio n. 8
0
        public async void RestartPlannerRemove1Module()
        {
            var factory = new TestCommandFactory();
            var planner = new RestartPlanner(factory);
            var token = new CancellationToken();

            IModule removeModule = new TestModule("mod1", "version1", "test", ModuleStatus.Running, Config1, RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars);
            ModuleSet removeRunning = ModuleSet.Create(removeModule);
            var removeExecutionList = new List<TestRecordType>
            {
                new TestRecordType(TestCommandType.TestStop, removeModule),
                new TestRecordType(TestCommandType.TestRemove, removeModule),
            };
            Plan addPlan = await planner.PlanAsync(ModuleSet.Empty, removeRunning, RuntimeInfo, ImmutableDictionary<string, IModuleIdentity>.Empty);
            var planRunner = new OrderedPlanRunner();
            await planRunner.ExecuteAsync(1, addPlan, token);

            factory.Recorder.ForEach(r => Assert.Equal(removeExecutionList, r.ExecutionList));
        }
Esempio n. 9
0
        public async void TestPlanExecution()
        {
            Option <TestPlanRecorder> recordKeeper = Option.Some(new TestPlanRecorder());
            var moduleExecutionList = new List <TestRecordType>
            {
                new TestRecordType(TestCommandType.TestCreate, new TestModule("module1", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image1"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, Constants.DefaultPriority, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestCreate, new TestModule("module2", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image2"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, Constants.DefaultPriority, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestCreate, new TestModule("module3", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image3"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, Constants.DefaultPriority, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestCreate, new TestModule("module4", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image4"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, Constants.DefaultPriority, DefaultConfigurationInfo, EnvVars)),
                new TestRecordType(TestCommandType.TestCreate, new TestModule("module5", "version1", "type1", ModuleStatus.Stopped, new TestConfig("image5"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, Constants.DefaultPriority, DefaultConfigurationInfo, EnvVars)),
            };
            var commandList = new List <ICommand>
            {
                new TestCommand(moduleExecutionList[0].TestType, moduleExecutionList[0].Module, recordKeeper),
                new TestCommand(moduleExecutionList[1].TestType, moduleExecutionList[1].Module, recordKeeper),
                new TestCommand(moduleExecutionList[2].TestType, moduleExecutionList[2].Module, recordKeeper),
                new TestCommand(moduleExecutionList[3].TestType, moduleExecutionList[3].Module, recordKeeper),
                new TestCommand(moduleExecutionList[4].TestType, moduleExecutionList[4].Module, recordKeeper)
            };

            var plan1 = new Plan(commandList);
            var plan2 = new Plan(new List <ICommand>());

            Assert.False(plan1.IsEmpty);
            Assert.True(Plan.Empty.IsEmpty);
            Assert.True(plan2.IsEmpty);

            var token = default(CancellationToken);

            var planRunner = new OrderedPlanRunner();
            await planRunner.ExecuteAsync(1, plan1, token);

            Assert.All(
                commandList,
                command =>
            {
                var c = command as TestCommand;
                Assert.NotNull(c);
                Assert.True(c.CommandExecuted);
            });
            recordKeeper.ForEach(r => Assert.Equal(moduleExecutionList, r.ExecutionList));
        }
Esempio n. 10
0
        public async void TestOrderedPlanRunnerCancellation()
        {
            // Arrange
            var cts = new CancellationTokenSource();

            Mock <ICommand>[] commands =
            {
                this.MakeMockCommand("c1"),
                this.MakeMockCommand("c2", () => cts.Cancel()),
                this.MakeMockCommand("c3"),
            };
            var plan       = new Plan(commands.Select(c => c.Object).ToList());
            var planRunner = new OrderedPlanRunner();

            // Act
            await planRunner.ExecuteAsync(1, plan, cts.Token);

            // Assert
            commands[0].Verify(m => m.ExecuteAsync(cts.Token), Times.Once());
            commands[1].Verify(m => m.ExecuteAsync(cts.Token), Times.Once());
            commands[2].Verify(m => m.ExecuteAsync(cts.Token), Times.Never());
        }
Esempio n. 11
0
        public async void RestartPlannerAddModulesWithPriority()
        {
            var factory = new TestCommandFactory();

            IModule module1        = new TestModule("mod1", "version1", "test", ModuleStatus.Running, Config1, RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, 3, DefaultConfigurationInfo, EnvVars);
            IModule updatedModule1 = new TestModule("mod1", "version1", "test", ModuleStatus.Running, Config2, RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, 3, DefaultConfigurationInfo, EnvVars);
            IModule addModule2     = new TestModule("mod2", "version1", "test", ModuleStatus.Running, Config1, RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, 2, DefaultConfigurationInfo, EnvVars);
            IModule addModule3     = new TestModule("mod3", "version1", "test", ModuleStatus.Running, Config1, RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, 1, DefaultConfigurationInfo, EnvVars);

            IImmutableDictionary <string, IModuleIdentity> moduleIdentities = GetModuleIdentities(new List <IModule>()
            {
                module1, addModule2, addModule3
            });

            var planner = new RestartPlanner(factory);
            var token   = default(CancellationToken);

            ModuleSet currentSet    = ModuleSet.Create(module1);
            ModuleSet desiredSet    = ModuleSet.Create(updatedModule1, addModule2, addModule3);
            var       executionList = new List <TestRecordType>
            {
                new TestRecordType(TestCommandType.TestCreate, addModule3),
                new TestRecordType(TestCommandType.TestStart, addModule3),
                new TestRecordType(TestCommandType.TestCreate, addModule2),
                new TestRecordType(TestCommandType.TestStart, addModule2),
                new TestRecordType(TestCommandType.TestStop, module1),
                new TestRecordType(TestCommandType.TestUpdate, updatedModule1),
                new TestRecordType(TestCommandType.TestStart, updatedModule1),
            };
            Plan addPlan = await planner.PlanAsync(desiredSet, currentSet, RuntimeInfo, moduleIdentities);

            var planRunner = new OrderedPlanRunner();
            await planRunner.ExecuteAsync(1, addPlan, token);

            factory.Recorder.ForEach(r => Assert.Equal(executionList, r.ExecutionList));
        }
Esempio n. 12
0
        public async void RestartPlannerAddRemoveUpdate()
        {
            var      factory       = new TestCommandFactory();
            var      token         = new CancellationToken();
            DateTime lastStartTime = DateTime.Parse("2017-08-04T17:52:13.0419502Z", null, DateTimeStyles.RoundtripKind);
            DateTime lastExitTime  = lastStartTime.AddDays(1);

            var currentModules = new List <IModule>
            {
                new TestRuntimeModule("UpdateMod1", "version1", RestartPolicy.OnUnhealthy, "test", ModuleStatus.Running, Config1, 0, "Running", lastStartTime, lastExitTime, 0, DateTime.MinValue, ModuleStatus.Running),
                new TestRuntimeModule("UpdateMod2", "version1", RestartPolicy.OnUnhealthy, "test", ModuleStatus.Running, Config1, 0, "Running", lastStartTime, lastExitTime, 0, DateTime.MinValue, ModuleStatus.Stopped),
                new TestRuntimeModule("RemoveMod1", "version1", RestartPolicy.OnUnhealthy, "test", ModuleStatus.Running, Config1, 0, "Running", lastStartTime, lastExitTime, 0, DateTime.MinValue, ModuleStatus.Running),
                new TestRuntimeModule("RemoveMod2", "version1", RestartPolicy.OnUnhealthy, "test", ModuleStatus.Running, Config1, 0, "Running", lastStartTime, lastExitTime, 0, DateTime.MinValue, ModuleStatus.Stopped)
            };
            var desiredModules = new List <IModule>
            {
                new TestModule("NewMod1", "version1", "test", ModuleStatus.Running, Config1, RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars),
                new TestModule("NewMod2", "version1", "test", ModuleStatus.Stopped, Config1, RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars),
                new TestModule("UpdateMod1", "version1", "test", ModuleStatus.Running, Config1, RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars),
                new TestModule("UpdateMod2", "version1", "test", ModuleStatus.Stopped, Config1, RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars)
            };

            IImmutableDictionary <string, IModuleIdentity> moduleIdentities = GetModuleIdentities(desiredModules);
            var planner = new RestartPlanner(factory);

            ModuleSet currentSet          = ModuleSet.Create(currentModules.ToArray());
            ModuleSet desiredSet          = ModuleSet.Create(desiredModules.ToArray());
            var       updateExecutionList = new List <TestRecordType>
            {
                new TestRecordType(TestCommandType.TestStop, currentModules[0]),
                new TestRecordType(TestCommandType.TestStop, currentModules[1]),
                new TestRecordType(TestCommandType.TestStop, currentModules[2]),
                new TestRecordType(TestCommandType.TestStop, currentModules[3]),
                new TestRecordType(TestCommandType.TestRemove, currentModules[2]),
                new TestRecordType(TestCommandType.TestRemove, currentModules[3]),
                new TestRecordType(TestCommandType.TestCreate, desiredModules[0]),
                new TestRecordType(TestCommandType.TestCreate, desiredModules[1]),
                new TestRecordType(TestCommandType.TestStart, desiredModules[0]),
                new TestRecordType(TestCommandType.TestStart, desiredModules[2]),
            };
            Plan addPlan = await planner.PlanAsync(desiredSet, currentSet, RuntimeInfo, moduleIdentities);

            var planRunner = new OrderedPlanRunner();
            await planRunner.ExecuteAsync(1, addPlan, token);

            //Weak confirmation: no assumed order.
            factory.Recorder.ForEach(recorder => Assert.All(updateExecutionList, r => Assert.True(recorder.ExecutionList.Contains(r))));
            factory.Recorder.ForEach(
                recorder =>
            {
                // One way to validate order
                // UpdateMod1
                Assert.True(recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[0])) < recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[8])));
                Assert.True(recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[6])) < recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[9])));
                // UpdateMod2
                Assert.True(recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[1])) < recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[9])));
                // RemoveMod1
                Assert.True(recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[3])) < recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[5])));
                // RemoveMod2
                Assert.True(recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[4])) < recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[6])));
                // AddMod1
                Assert.True(recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[6])) < recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[8])));
                // AddModTrue2
                Assert.True(recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[0])) < recorder.ExecutionList.FindIndex(r => r.Equals(updateExecutionList[6])));
            });
        }