Ejemplo n.º 1
0
 public void GetVariable_ReturnLastUpdatedVariable()
 {
     using (var conn = new ConnectImpl())
     {
         conn.InitializeTestAPI(0, 1, 0, null);
         conn.NextTick(100, 0, 0);
         conn.SetVariable(TestVariableName0, 10);
         Assert.That(conn.GetVariable(TestVariableName0), Is.EqualTo(10));
         conn.NextTick(101, 0, 0);
         Assert.That(conn.GetVariable(TestVariableName0), Is.EqualTo(10));
         conn.SetVariable(TestVariableName0, 11);
         Assert.That(conn.GetVariable(TestVariableName0), Is.EqualTo(11));
     }
 }
        public void GetVariable_CanSummValuesOfVariable()
        {
            const int instancesCount = 2;

            using (var conn0 = new ConnectImpl())
            using (var conn1 = new ConnectImpl())
            {
                using (RunAsync(() => conn0.InitializeTestAPI(0, instancesCount, 0, null)))
                using (RunAsync(() => conn1.InitializeTestAPI(1, instancesCount, 0, null)))
                {
                }

                conn0.DeclareVariable(TestVariableName0, VariableOperations.Sum);

                conn0.NextTick(100, 0, 0);
                conn1.NextTick(100, 0, 0);
                conn0.SetVariable(TestVariableName0, 10);
                conn0.NextTick(101, 0, 0);
                conn1.NextTick(101, 0, 0);
                conn1.SetVariable(TestVariableName0, 12);
                conn0.NextTick(102, 0, 0);
                conn1.NextTick(102, 0, 0);

                Assert.That(conn0.GetVariable(TestVariableName0), Is.EqualTo(22));
                Assert.That(conn1.GetVariable(TestVariableName0), Is.EqualTo(22));
            }
        }
Ejemplo n.º 3
0
        public void GetVariable_ShouldNotWaitWhenAllInstancesIsHere()
        {
            const int instancesCount = 3;

            using (var conn0 = new ConnectImpl())
                using (var conn1 = new ConnectImpl())
                    using (var conn2 = new ConnectImpl())
                    {
                        using (RunAsync(() => conn0.InitializeTestAPI(0, instancesCount, 0, null)))
                            using (RunAsync(() => conn1.InitializeTestAPI(1, instancesCount, 0, null)))
                                using (RunAsync(() => conn2.InitializeTestAPI(2, instancesCount, 0, null)))
                                {
                                }

                        conn0.NextTick(100, 0, 0);
                        conn1.NextTick(100, 0, 0);
                        conn2.NextTick(100, 0, 0);

                        conn0.SetVariable(TestVariableName0, 10);

                        conn0.NextTick(101, 0, 0);
                        conn1.NextTick(101, 0, 0);

                        using (RunAsync(() => conn1.GetVariable(TestVariableName0)))
                        {
                            WaitForStatusWaiting(conn1);
                            conn2.NextTick(101, 0, 0);
                        }
                    }
        }
Ejemplo n.º 4
0
        public void GetVariable_CanSummValuesOfVariable()
        {
            const int instancesCount = 2;

            using (var conn0 = new ConnectImpl())
                using (var conn1 = new ConnectImpl())
                {
                    using (RunAsync(() => conn0.InitializeTestAPI(0, instancesCount, 0, null)))
                        using (RunAsync(() => conn1.InitializeTestAPI(1, instancesCount, 0, null)))
                        {
                        }

                    conn0.DeclareVariable(TestVariableName0, VariableOperations.Sum);

                    conn0.NextTick(100, 0, 0);
                    conn1.NextTick(100, 0, 0);
                    conn0.SetVariable(TestVariableName0, 10);
                    conn0.NextTick(101, 0, 0);
                    conn1.NextTick(101, 0, 0);
                    conn1.SetVariable(TestVariableName0, 12);
                    conn0.NextTick(102, 0, 0);
                    conn1.NextTick(102, 0, 0);

                    Assert.That(conn0.GetVariable(TestVariableName0), Is.EqualTo(22));
                    Assert.That(conn1.GetVariable(TestVariableName0), Is.EqualTo(22));
                }
        }
Ejemplo n.º 5
0
        public void GetVariable_ShouldNotWaitDeinitializatedHimself()
        {
            const int instancesCount = 2;

            using (var conn0 = new ConnectImpl())
                using (var conn1 = new ConnectImpl())
                {
                    using (RunAsync(() => conn0.InitializeTestAPI(0, instancesCount, 0, null)))
                        using (RunAsync(() => conn1.InitializeTestAPI(1, instancesCount, 0, null)))
                        {
                        }

                    conn0.NextTick(100, 0, 0);
                    using (RunAsync(() => conn0.GetVariable(TestVariableName0)))
                    {
                        //conn0.GetLastTick() 100
                        //conn1.GetLastTick() 0
                        //conn0 should wait conn1
                        WaitForStatusWaiting(conn0);

                        //conn0 deinitializated
                        //conn0 getvalue shouldn't wait
                        conn0.DeinitializeTestAPI();
                        WaitForStatus(conn0, InstanceStatus.Deinitialized);
                    }
                }
        }
 public void GetVariable_IfVariableDoesntExistReturn0()
 {
     using (var conn = new ConnectImpl())
     {
         conn.InitializeTestAPI(0, 1, 0, null);
         Assert.That(conn.GetVariable(TestVariableName0), Is.EqualTo(0));
     }
 }
Ejemplo n.º 7
0
 public void GetVariable_IfVariableDoesntExistReturn0()
 {
     using (var conn = new ConnectImpl())
     {
         conn.InitializeTestAPI(0, 1, 0, null);
         Assert.That(conn.GetVariable(TestVariableName0), Is.EqualTo(0));
     }
 }
Ejemplo n.º 8
0
        public void GetVariable_ShouldWaitLastChanges()
        {
            const int instancesCount = 2;

            using (var conn0 = new ConnectImpl())
                using (var conn1 = new ConnectImpl())
                {
                    using (RunAsync(() => conn0.InitializeTestAPI(0, instancesCount, 0, null)))
                        using (RunAsync(() => conn1.InitializeTestAPI(1, instancesCount, 0, null)))
                        {
                        }

                    //conn0.GetLastTick() 100
                    //conn1.GetLastTick() 0
                    //conn0 should wait conn1
                    conn0.NextTick(100, 0, 0);
                    using (RunAsync(() => conn0.GetVariable(TestVariableName0)))
                    {
                        WaitForStatusWaiting(conn0);
                        conn1.NextTick(101, 0, 0);
                    }

                    //conn0.GetLastTick() 102
                    //conn1.GetLastTick() 101
                    //conn0 should wait conn1
                    conn0.NextTick(102, 0, 0);
                    using (RunAsync(() => conn0.GetVariable(TestVariableName0)))
                    {
                        WaitForStatusWaiting(conn0);
                        conn1.NextTick(102, 0, 0);
                        conn0.SetVariable(TestVariableName0, 10);
                    }

                    //conn0.GetLastTick() 103
                    //conn1.GetLastTick() 102
                    //conn0 should wait conn1
                    conn0.NextTick(103, 0, 0);
                    using (RunAsync(() => conn0.SetVariable(TestVariableName0, 11)))
                    {
                        WaitForStatusWaiting(conn0);
                        conn1.NextTick(103, 0, 0);
                    }
                }
        }
 public void GetVariable_ReturnLastUpdatedVariable()
 {
     using (var conn = new ConnectImpl())
     {
         conn.InitializeTestAPI(0, 1, 0, null);
         conn.NextTick(100, 0, 0);
         conn.SetVariable(TestVariableName0, 10);
         Assert.That(conn.GetVariable(TestVariableName0), Is.EqualTo(10));
         conn.NextTick(101, 0, 0);
         Assert.That(conn.GetVariable(TestVariableName0), Is.EqualTo(10));
         conn.SetVariable(TestVariableName0, 11);
         Assert.That(conn.GetVariable(TestVariableName0), Is.EqualTo(11));
     }
 }
        public void GetVariable_ShouldWaitLastChanges()
        {
            const int instancesCount = 2;

            using (var conn0 = new ConnectImpl())
            using (var conn1 = new ConnectImpl())
            {
                using (RunAsync(() => conn0.InitializeTestAPI(0, instancesCount, 0, null)))
                using (RunAsync(() => conn1.InitializeTestAPI(1, instancesCount, 0, null)))
                {
                }

                //conn0.GetLastTick() 100
                //conn1.GetLastTick() 0
                //conn0 should wait conn1
                conn0.NextTick(100, 0, 0);
                using (RunAsync(() => conn0.GetVariable(TestVariableName0)))
                {
                    WaitForStatusWaiting(conn0);
                    conn1.NextTick(101, 0, 0);
                }

                //conn0.GetLastTick() 102
                //conn1.GetLastTick() 101
                //conn0 should wait conn1
                conn0.NextTick(102, 0, 0);
                using (RunAsync(() => conn0.GetVariable(TestVariableName0)))
                {
                    WaitForStatusWaiting(conn0);
                    conn1.NextTick(102, 0, 0);
                    conn0.SetVariable(TestVariableName0, 10);
                }

                //conn0.GetLastTick() 103
                //conn1.GetLastTick() 102
                //conn0 should wait conn1
                conn0.NextTick(103, 0, 0);
                using (RunAsync(() => conn0.SetVariable(TestVariableName0, 11)))
                {
                    WaitForStatusWaiting(conn0);
                    conn1.NextTick(103, 0, 0);
                }
            }
        }
        public void GetVariable_ShouldNotWaitWhenAllInstancesIsHere()
        {
            const int instancesCount = 3;

            using (var conn0 = new ConnectImpl())
            using (var conn1 = new ConnectImpl())
            using (var conn2 = new ConnectImpl())
            {
                using (RunAsync(() => conn0.InitializeTestAPI(0, instancesCount, 0, null)))
                using (RunAsync(() => conn1.InitializeTestAPI(1, instancesCount, 0, null)))
                using (RunAsync(() => conn2.InitializeTestAPI(2, instancesCount, 0, null)))
                {
                }

                conn0.NextTick(100, 0, 0);
                conn1.NextTick(100, 0, 0);
                conn2.NextTick(100, 0, 0);

                conn0.SetVariable(TestVariableName0, 10);

                conn0.NextTick(101, 0, 0);
                conn1.NextTick(101, 0, 0);

                using (RunAsync(() => conn1.GetVariable(TestVariableName0)))
                {
                    WaitForStatusWaiting(conn1);
                    conn2.NextTick(101, 0, 0);
                }
            }
        }
        public void GetVariable_ShouldNotWaitDeinitializatedInstances()
        {
            const int instancesCount = 2;

            using (var conn0 = new ConnectImpl())
            using (var conn1 = new ConnectImpl())
            {
                using (RunAsync(() => conn0.InitializeTestAPI(0, instancesCount, 0, null)))
                using (RunAsync(() => conn1.InitializeTestAPI(1, instancesCount, 0, null)))
                {
                }

                conn0.NextTick(100, 0, 0);
                using (RunAsync(() => conn0.GetVariable(TestVariableName0)))
                {
                    //conn0.GetLastTick() 100
                    //conn1.GetLastTick() 0
                    //conn0 should wait conn1
                    WaitForStatusWaiting(conn0);

                    //conn1 deinitializated
                    //conn0 shouldn't wait
                    conn1.DeinitializeTestAPI();
                    WaitForStatus(conn0, InstanceStatus.Initialized);
                }
            }
        }