Exemple #1
0
        public virtual void TestThread()
        {
            TestReconfiguration.ReconfigurableDummy dummy = new TestReconfiguration.ReconfigurableDummy
                                                                (conf1);
            Assert.True(dummy.GetConf().Get(Prop1).Equals(Val1));
            Thread dummyThread = new Thread(dummy);

            dummyThread.Start();
            try
            {
                Thread.Sleep(500);
            }
            catch (Exception)
            {
            }
            // do nothing
            dummy.ReconfigureProperty(Prop1, Val2);
            long endWait = Time.Now() + 2000;

            while (dummyThread.IsAlive() && Time.Now() < endWait)
            {
                try
                {
                    Thread.Sleep(50);
                }
                catch (Exception)
                {
                }
            }
            // do nothing
            NUnit.Framework.Assert.IsFalse("dummy thread should not be alive", dummyThread.IsAlive
                                               ());
            dummy.running = false;
            try
            {
                dummyThread.Join();
            }
            catch (Exception)
            {
            }
            // do nothing
            Assert.True(Prop1 + " is set to wrong value", dummy.GetConf().Get
                            (Prop1).Equals(Val2));
        }
Exemple #2
0
 public virtual void TestReconfigure()
 {
     TestReconfiguration.ReconfigurableDummy dummy = new TestReconfiguration.ReconfigurableDummy
                                                         (conf1);
     Assert.True(Prop1 + " set to wrong value ", dummy.GetConf().Get
                     (Prop1).Equals(Val1));
     Assert.True(Prop2 + " set to wrong value ", dummy.GetConf().Get
                     (Prop2).Equals(Val1));
     Assert.True(Prop3 + " set to wrong value ", dummy.GetConf().Get
                     (Prop3).Equals(Val1));
     Assert.True(Prop4 + " set to wrong value ", dummy.GetConf().Get
                     (Prop4) == null);
     Assert.True(Prop5 + " set to wrong value ", dummy.GetConf().Get
                     (Prop5) == null);
     Assert.True(Prop1 + " should be reconfigurable ", dummy.IsPropertyReconfigurable
                     (Prop1));
     Assert.True(Prop2 + " should be reconfigurable ", dummy.IsPropertyReconfigurable
                     (Prop2));
     NUnit.Framework.Assert.IsFalse(Prop3 + " should not be reconfigurable ", dummy.IsPropertyReconfigurable
                                        (Prop3));
     Assert.True(Prop4 + " should be reconfigurable ", dummy.IsPropertyReconfigurable
                     (Prop4));
     NUnit.Framework.Assert.IsFalse(Prop5 + " should not be reconfigurable ", dummy.IsPropertyReconfigurable
                                        (Prop5));
     {
         // change something to the same value as before
         bool exceptionCaught = false;
         try
         {
             dummy.ReconfigureProperty(Prop1, Val1);
             Assert.True(Prop1 + " set to wrong value ", dummy.GetConf().Get
                             (Prop1).Equals(Val1));
         }
         catch (ReconfigurationException)
         {
             exceptionCaught = true;
         }
         NUnit.Framework.Assert.IsFalse("received unexpected exception", exceptionCaught);
     }
     {
         // change something to null
         bool exceptionCaught = false;
         try
         {
             dummy.ReconfigureProperty(Prop1, null);
             Assert.True(Prop1 + "set to wrong value ", dummy.GetConf().Get(
                             Prop1) == null);
         }
         catch (ReconfigurationException)
         {
             exceptionCaught = true;
         }
         NUnit.Framework.Assert.IsFalse("received unexpected exception", exceptionCaught);
     }
     {
         // change something to a different value than before
         bool exceptionCaught = false;
         try
         {
             dummy.ReconfigureProperty(Prop1, Val2);
             Assert.True(Prop1 + "set to wrong value ", dummy.GetConf().Get(
                             Prop1).Equals(Val2));
         }
         catch (ReconfigurationException)
         {
             exceptionCaught = true;
         }
         NUnit.Framework.Assert.IsFalse("received unexpected exception", exceptionCaught);
     }
     {
         // set unset property to null
         bool exceptionCaught = false;
         try
         {
             dummy.ReconfigureProperty(Prop4, null);
             Assert.True(Prop4 + "set to wrong value ", dummy.GetConf().Get(
                             Prop4) == null);
         }
         catch (ReconfigurationException)
         {
             exceptionCaught = true;
         }
         NUnit.Framework.Assert.IsFalse("received unexpected exception", exceptionCaught);
     }
     {
         // set unset property
         bool exceptionCaught = false;
         try
         {
             dummy.ReconfigureProperty(Prop4, Val1);
             Assert.True(Prop4 + "set to wrong value ", dummy.GetConf().Get(
                             Prop4).Equals(Val1));
         }
         catch (ReconfigurationException)
         {
             exceptionCaught = true;
         }
         NUnit.Framework.Assert.IsFalse("received unexpected exception", exceptionCaught);
     }
     {
         // try to set unset property to null (not reconfigurable)
         bool exceptionCaught = false;
         try
         {
             dummy.ReconfigureProperty(Prop5, null);
         }
         catch (ReconfigurationException)
         {
             exceptionCaught = true;
         }
         Assert.True("did not receive expected exception", exceptionCaught
                     );
     }
     {
         // try to set unset property to value (not reconfigurable)
         bool exceptionCaught = false;
         try
         {
             dummy.ReconfigureProperty(Prop5, Val1);
         }
         catch (ReconfigurationException)
         {
             exceptionCaught = true;
         }
         Assert.True("did not receive expected exception", exceptionCaught
                     );
     }
     {
         // try to change property to value (not reconfigurable)
         bool exceptionCaught = false;
         try
         {
             dummy.ReconfigureProperty(Prop3, Val2);
         }
         catch (ReconfigurationException)
         {
             exceptionCaught = true;
         }
         Assert.True("did not receive expected exception", exceptionCaught
                     );
     }
     {
         // try to change property to null (not reconfigurable)
         bool exceptionCaught = false;
         try
         {
             dummy.ReconfigureProperty(Prop3, null);
         }
         catch (ReconfigurationException)
         {
             exceptionCaught = true;
         }
         Assert.True("did not receive expected exception", exceptionCaught
                     );
     }
 }