예제 #1
0
        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));
        }
예제 #2
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));
        }