public void TestParallelCommandGroupWithTwoCommands()
        {
            MockCommand command1 = new MockCommand();
            MockCommand command2 = new MockCommand();

            CommandGroup commandGroup = new CommandGroup();
            commandGroup.AddParallel(command1);
            commandGroup.AddParallel(command2);

            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            commandGroup.Start();
            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 1, 1, 0, 0);
            AssertCommandState(command2, 1, 1, 1, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 2, 2, 0, 0);
            AssertCommandState(command2, 1, 2, 2, 0, 0);
            command1.SetHasFinished(true);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 3, 3, 1, 0);
            AssertCommandState(command2, 1, 3, 3, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 3, 3, 1, 0);
            AssertCommandState(command2, 1, 4, 4, 0, 0);
            command2.SetHasFinished(true);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 3, 3, 1, 0);
            AssertCommandState(command2, 1, 5, 5, 1, 0);
        }
Exemple #2
0
        internal void SetParent(CommandGroup parent)
        {
            lock (m_syncRoot)
            {

                if (m_parent != null)
                {
                    throw new IllegalUseOfCommandException(
                        "Can not give command to a command group after already being put in a command group");
                }

                LockChanges();
                m_parent = parent;

                Table?.PutBoolean("isParented", true);
            }
        }
        public void TestThreeCommandOnSubSystem()
        {
            ASubsystem subsystem = new ASubsystem();

            MockCommand command1 = new MockCommand();
            command1.AddRequires(subsystem);

            MockCommand command2 = new MockCommand();
            command2.AddRequires(subsystem);

            MockCommand command3 = new MockCommand();
            command3.AddRequires(subsystem);

            CommandGroup commandGroup = new CommandGroup();
            commandGroup.AddSequential(command1, 1.0);
            commandGroup.AddSequential(command2, 2.0);
            commandGroup.AddSequential(command3);

            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            commandGroup.Start();
            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 1, 1, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            Sleep(1000);// command 1 timeout
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 1, 1, 0, 1);
            AssertCommandState(command2, 1, 1, 1, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 1, 1, 0, 1);
            AssertCommandState(command2, 1, 2, 2, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            Sleep(2000);// command 2 timeout
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 1, 1, 0, 1);
            AssertCommandState(command2, 1, 2, 2, 0, 1);
            AssertCommandState(command3, 1, 1, 1, 0, 0);

            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 1, 1, 0, 1);
            AssertCommandState(command2, 1, 2, 2, 0, 1);
            AssertCommandState(command3, 1, 2, 2, 0, 0);
            command3.SetHasFinished(true);
            AssertCommandState(command1, 1, 1, 1, 0, 1);
            AssertCommandState(command2, 1, 2, 2, 0, 1);
            AssertCommandState(command3, 1, 2, 2, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 1, 1, 0, 1);
            AssertCommandState(command2, 1, 2, 2, 0, 1);
            AssertCommandState(command3, 1, 3, 3, 1, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 1, 1, 0, 1);
            AssertCommandState(command2, 1, 2, 2, 0, 1);
            AssertCommandState(command3, 1, 3, 3, 1, 0);
        }