Exemplo n.º 1
0
        /// <exception cref="System.Exception"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestStartReconfigurationFailureDueToExistingRunningTask()
        {
            TestReconfiguration.AsyncReconfigurableDummy dummy = Org.Mockito.Mockito.Spy(new
                                                                                         TestReconfiguration.AsyncReconfigurableDummy(conf1));
            IList <ReconfigurationUtil.PropertyChange> changes = Lists.NewArrayList(new ReconfigurationUtil.PropertyChange
                                                                                        (Prop1, "new1", "old1"));

            Org.Mockito.Mockito.DoReturn(changes).When(dummy).GetChangedProperties(Matchers.Any
                                                                                   <Configuration>(), Matchers.Any <Configuration>());
            ReconfigurationTaskStatus status = dummy.GetReconfigurationTaskStatus();

            NUnit.Framework.Assert.IsFalse(status.HasTask());
            dummy.StartReconfigurationTask();
            status = dummy.GetReconfigurationTaskStatus();
            Assert.True(status.HasTask());
            NUnit.Framework.Assert.IsFalse(status.Stopped());
            // An active reconfiguration task is running.
            try
            {
                dummy.StartReconfigurationTask();
                NUnit.Framework.Assert.Fail("Expect to throw IOException.");
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("Another reconfiguration task is running"
                                                         , e);
            }
            status = dummy.GetReconfigurationTaskStatus();
            Assert.True(status.HasTask());
            NUnit.Framework.Assert.IsFalse(status.Stopped());
            dummy.latch.CountDown();
            WaitAsyncReconfigureTaskFinish(dummy);
            status = dummy.GetReconfigurationTaskStatus();
            Assert.True(status.HasTask());
            Assert.True(status.Stopped());
            // The first task has finished.
            dummy.StartReconfigurationTask();
            WaitAsyncReconfigureTaskFinish(dummy);
            ReconfigurationTaskStatus status2 = dummy.GetReconfigurationTaskStatus();

            Assert.True(status2.GetStartTime() >= status.GetEndTime());
            dummy.ShutdownReconfigurationTask();
            try
            {
                dummy.StartReconfigurationTask();
                NUnit.Framework.Assert.Fail("Expect to throw IOException");
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("The server is stopped", e);
            }
        }
Exemplo n.º 2
0
        public virtual void TestAsyncReconfigure()
        {
            TestReconfiguration.AsyncReconfigurableDummy dummy = Org.Mockito.Mockito.Spy(new
                                                                                         TestReconfiguration.AsyncReconfigurableDummy(conf1));
            IList <ReconfigurationUtil.PropertyChange> changes = Lists.NewArrayList();

            changes.AddItem(new ReconfigurationUtil.PropertyChange("name1", "new1", "old1"));
            changes.AddItem(new ReconfigurationUtil.PropertyChange("name2", "new2", "old2"));
            changes.AddItem(new ReconfigurationUtil.PropertyChange("name3", "new3", "old3"));
            Org.Mockito.Mockito.DoReturn(changes).When(dummy).GetChangedProperties(Matchers.Any
                                                                                   <Configuration>(), Matchers.Any <Configuration>());
            Org.Mockito.Mockito.DoReturn(true).When(dummy).IsPropertyReconfigurable(Matchers.Eq
                                                                                        ("name1"));
            Org.Mockito.Mockito.DoReturn(false).When(dummy).IsPropertyReconfigurable(Matchers.Eq
                                                                                         ("name2"));
            Org.Mockito.Mockito.DoReturn(true).When(dummy).IsPropertyReconfigurable(Matchers.Eq
                                                                                        ("name3"));
            Org.Mockito.Mockito.DoNothing().When(dummy).ReconfigurePropertyImpl(Matchers.Eq("name1"
                                                                                            ), Matchers.AnyString());
            Org.Mockito.Mockito.DoNothing().When(dummy).ReconfigurePropertyImpl(Matchers.Eq("name2"
                                                                                            ), Matchers.AnyString());
            Org.Mockito.Mockito.DoThrow(new ReconfigurationException("NAME3", "NEW3", "OLD3",
                                                                     new IOException("io exception"))).When(dummy).ReconfigurePropertyImpl(Matchers.Eq
                                                                                                                                               ("name3"), Matchers.AnyString());
            dummy.StartReconfigurationTask();
            WaitAsyncReconfigureTaskFinish(dummy);
            ReconfigurationTaskStatus status = dummy.GetReconfigurationTaskStatus();

            Assert.Equal(3, status.GetStatus().Count);
            foreach (KeyValuePair <ReconfigurationUtil.PropertyChange, Optional <string> > result
                     in status.GetStatus())
            {
                ReconfigurationUtil.PropertyChange change = result.Key;
                if (change.prop.Equals("name1"))
                {
                    NUnit.Framework.Assert.IsFalse(result.Value.IsPresent());
                }
                else
                {
                    if (change.prop.Equals("name2"))
                    {
                        MatcherAssert.AssertThat(result.Value.Get(), CoreMatchers.ContainsString("Property name2 is not reconfigurable"
                                                                                                 ));
                    }
                    else
                    {
                        if (change.prop.Equals("name3"))
                        {
                            MatcherAssert.AssertThat(result.Value.Get(), CoreMatchers.ContainsString("io exception"
                                                                                                     ));
                        }
                        else
                        {
                            NUnit.Framework.Assert.Fail("Unknown property: " + change.prop);
                        }
                    }
                }
            }
        }