Ejemplo n.º 1
0
        public void Should_Execute_IPlugin()
        {
            IExecutionManager     manager    = new ExecutionManager( new PluginManager() );
            IAllocationDefinition definition = new AllocationDefinition( 2 );
            IExecutionSlot        slot       = new ExecutionSlot(definition);

            definition.Add( DTO.NewPluginInfoTestPlugin );

            manager.PluginManager.Install( definition );
            manager.Add( slot );

            IPlugin completedPlugin = null;
            TestPlugin testPlugin = new TestPlugin(100);

            manager.ExecuteCompleted += delegate(object sender, ObjectEventArgs<IPlugin> eventArgs)
                                            {
                                                completedPlugin = eventArgs.EventObject;
                                            };
            manager.Execute( testPlugin );

            Assert.AreEqual( slot, manager[ definition ] );
            Assert.AreEqual( 1, manager[ definition ].UsedSlots );

            Timing.WaitWhile(() => completedPlugin == null, 1000);

            Assert.AreEqual( testPlugin, completedPlugin );
            Assert.AreEqual( 0, manager[ definition ].UsedSlots );
            Assert.AreEqual( PluginStatus.Executed, testPlugin.Status );
        }
Ejemplo n.º 2
0
        public void Should_Commit_Plugin()
        {
            IAllocationDefinition definition = new AllocationDefinition(1);
            definition.Add(DTO.NewPluginInfoTestPlugin);

            TestPlugin plugin = new TestPlugin(50);

            IExecutionSlot slot = new ExecutionSlot(definition);
            slot.Commit( plugin );

            Timing.WaitUntil(() => plugin.Status == PluginStatus.Committed, 1000);

            Assert.AreEqual( PluginStatus.Committed, plugin.Status );
        }
Ejemplo n.º 3
0
        public void Should_Execute_Plugin()
        {
            IAllocationDefinition definition = new AllocationDefinition(1);
            definition.Add(DTO.NewPluginInfoTestPlugin);

            TestPlugin plugin = new TestPlugin(100);

            IExecutionSlot slot = new ExecutionSlot(definition);
            slot.Execute( plugin );

            Assert.AreEqual( 1, slot.UsedSlots );

            plugin.EndCurrentOperation();

            Timing.WaitUntil(() => plugin.Status == PluginStatus.Executed, 1000);

            Assert.AreEqual( 1.0, plugin.OperationProgress );
            Assert.AreEqual( 0, slot.UsedSlots );
            Assert.AreEqual( PluginStatus.Executed, plugin.Status );
        }
Ejemplo n.º 4
0
        public void Should_Commit_Plugin()
        {
            IAgentEngine engine = new AgentEngine();
            IPlugin plugin = new TestPlugin();
            IAllocationDefinition definition = new AllocationDefinition(2);

            definition.Add(DTO.NewPluginInfoTestPlugin);

            engine.AddDefinition(definition);

            IPlugin outPlugin = null;
            engine.ExecutionManager.CommitCompleted += delegate(object sender, ObjectEventArgs<IPlugin> eventArgs)
                                                            {
                                                                outPlugin = eventArgs.EventObject;
                                                            };
            engine.Commit(plugin);

            Timing.WaitWhile(() => outPlugin == null, 1000);

            Assert.AreEqual(plugin, outPlugin);
            Assert.AreEqual(PluginStatus.Committed, outPlugin.Status);
        }
Ejemplo n.º 5
0
        public void Should_Return_False_If_Plugin_Isnt_Added()
        {
            IAgentEngine engine = new AgentEngine();
            IPlugin plugin = new TestPlugin();

            Assert.IsFalse(engine.ContainsPlugin(plugin.UniqueIdentifier));
        }
Ejemplo n.º 6
0
        public void Should_Return_False_If_Plugin_Doesnt_Have_AvailableSlots()
        {
            IAgentEngine engine = new AgentEngine();
            IPlugin      plugin = new TestPlugin();

            Assert.IsFalse(engine.HasAvailableSlots(plugin.PluginIdentifier));
        }
Ejemplo n.º 7
0
        public void Should_Return_Runable_Plugins_In_Reverse_Order_When_Rolling_Back()
        {
            IJob job = new Job(DTO.JobData);
            var errorPlugin = new TestPlugin(true,false,false);
            var hasFailed = false;

            job[job.Count - 1].Clear();
            job[job.Count - 1].Add(errorPlugin); //Error plugin added to the end

            job.JobExecuteFailed += (sender, eventArgs) => hasFailed = true;

            foreach (IPlugin plugin in job.GetAllPlugins())
            {
                plugin.BeginExecute();
            }

            Timing.WaitUntil(() => hasFailed, 2000);

            IList<IPlugin> plugins = job.GetRunablePlugins().ToList();

            Assert.AreEqual(JobCommand.Rollback, job.CurrentCommand);
            Assert.AreEqual(plugins.First(), errorPlugin);
            Assert.AreEqual(1, plugins.Count);

            foreach (var list in plugins)
            {
                list.BeginRollback();
            }

            IList<IPlugin> plugins2 = job.GetRunablePlugins().ToList();

            Assert.AreEqual(7, plugins2.Count);

            foreach (IPlugin list in plugins2)
            {
                list.BeginRollback();
            }

            IList<IPlugin> plugins3 = job.GetRunablePlugins().ToList();

            Assert.AreEqual(1, plugins3.Count);

            foreach (IPlugin list in plugins3)
            {
                list.BeginRollback();
            }

            IList<IPlugin> plugins4 = job.GetRunablePlugins().ToList();

            Assert.AreEqual(2, plugins4.Count);

            Assert.IsTrue(hasFailed);
        }
Ejemplo n.º 8
0
        public void Should_Fail_Commit_Plugin()
        {
            IAllocationDefinition definition = new AllocationDefinition(1);
            definition.Add(DTO.NewPluginInfoTestPlugin);

            TestPlugin plugin = new TestPlugin(50, true);
            IPlugin failedPlugin = null;
            Exception pluginException = null;

            IExecutionSlot slot = new ExecutionSlot(definition);
            slot.CommitFailed += delegate(object sender, ObjectErrorEventArgs<IPlugin> eventArgs)
                                 {
                                     failedPlugin    = eventArgs.EventObject;
                                     pluginException = eventArgs.Exception;
                                 };

            slot.Commit(plugin);

            Timing.WaitWhile(() => failedPlugin == null, 3000);

            Assert.AreEqual( plugin, failedPlugin );
            Assert.IsNotNull( pluginException );
            Assert.AreEqual( PluginStatus.CommitFailed, plugin.Status );
        }
Ejemplo n.º 9
0
        public void Should_Rollback_Plugin()
        {
            IBroker      broker = new Broker();
            IAgentEngine agent  = new AgentEngine( );
            IAllocationDefinition definition = new AllocationDefinition(2);
            IExecutionSlot slot = new ExecutionSlot(definition);

            broker.Add(agent);
            definition.Add( DTO.NewPluginInfoTestPlugin );
            agent.PluginManager.Install(definition);
            agent.ExecutionManager.Add( slot );

            definition.Add(DTO.NewPluginInfoTestPlugin);

            IPlugin completedPlugin = null;
            TestPlugin testPlugin = new TestPlugin(100);

            broker.RollbackCompleted += delegate(object sender, ObjectEventArgs<IPlugin> eventArgs)
                                        {
                                            completedPlugin = eventArgs.EventObject;
                                        };

            broker.Rollback(testPlugin);

            Assert.AreEqual(slot, agent.ExecutionManager[definition]);
            Assert.AreEqual(1, agent.ExecutionManager[definition].UsedSlots, "Slots Used");

            Timing.WaitWhile(() => completedPlugin == null, 1000);

            Assert.AreEqual(testPlugin, completedPlugin);
            Assert.AreEqual(0, agent.ExecutionManager[definition].UsedSlots);
            Assert.AreEqual(PluginStatus.Rolledback, testPlugin.Status);
        }
Ejemplo n.º 10
0
        public void Should_Throw_Exception_When_Plugin_Isnt_Installed_When_Rollback()
        {
            IBroker broker = new Broker();
            IAgentEngine agent = new AgentEngine();
            IAllocationDefinition definition = new AllocationDefinition(2);
            IExecutionSlot slot = new ExecutionSlot(definition);

            broker.Add(agent);
            agent.PluginManager.Install(definition);
            agent.ExecutionManager.Add(slot);

            TestPlugin testPlugin = new TestPlugin();

            broker.Rollback(testPlugin);
        }