Exemplo n.º 1
0
        public virtual void TestInitialState()
        {
            StartupProgressView view = startupProgress.CreateView();

            NUnit.Framework.Assert.IsNotNull(view);
            NUnit.Framework.Assert.AreEqual(0L, view.GetElapsedTime());
            NUnit.Framework.Assert.AreEqual(0.0f, view.GetPercentComplete(), 0.001f);
            IList <Phase> phases = new AList <Phase>();

            foreach (Phase phase in view.GetPhases())
            {
                phases.AddItem(phase);
                NUnit.Framework.Assert.AreEqual(0L, view.GetElapsedTime(phase));
                NUnit.Framework.Assert.IsNull(view.GetFile(phase));
                NUnit.Framework.Assert.AreEqual(0.0f, view.GetPercentComplete(phase), 0.001f);
                NUnit.Framework.Assert.AreEqual(long.MinValue, view.GetSize(phase));
                NUnit.Framework.Assert.AreEqual(Status.Pending, view.GetStatus(phase));
                NUnit.Framework.Assert.AreEqual(0L, view.GetTotal(phase));
                foreach (Step step in view.GetSteps(phase))
                {
                    NUnit.Framework.Assert.Fail(string.Format("unexpected step %s in phase %s at initial state"
                                                              , step, phase));
                }
            }
            Assert.AssertArrayEquals(Sharpen.Collections.ToArray(EnumSet.AllOf <Phase>()), Sharpen.Collections.ToArray
                                         (phases));
        }
Exemplo n.º 2
0
        public virtual void TestStepSequence()
        {
            // Test that steps are returned in the correct sort order (by file and then
            // sequence number) by starting a few steps in a randomly shuffled order and
            // then asserting that they are returned in the expected order.
            Step[] expectedSteps = new Step[] { new Step(StepType.Inodes, "file1"), new Step(
                                                    StepType.DelegationKeys, "file1"), new Step(StepType.Inodes, "file2"), new Step(
                                                    StepType.DelegationKeys, "file2"), new Step(StepType.Inodes, "file3"), new Step(
                                                    StepType.DelegationKeys, "file3") };
            IList <Step> shuffledSteps = new AList <Step>(Arrays.AsList(expectedSteps));

            Sharpen.Collections.Shuffle(shuffledSteps);
            startupProgress.BeginPhase(Phase.SavingCheckpoint);
            foreach (Step step in shuffledSteps)
            {
                startupProgress.BeginStep(Phase.SavingCheckpoint, step);
            }
            IList <Step>        actualSteps = new AList <Step>(expectedSteps.Length);
            StartupProgressView view        = startupProgress.CreateView();

            NUnit.Framework.Assert.IsNotNull(view);
            foreach (Step step_1 in view.GetSteps(Phase.SavingCheckpoint))
            {
                actualSteps.AddItem(step_1);
            }
            Assert.AssertArrayEquals(expectedSteps, Sharpen.Collections.ToArray(actualSteps));
        }
Exemplo n.º 3
0
        public virtual void TestFrozenAfterStartupCompletes()
        {
            // Do some updates and counter increments.
            startupProgress.BeginPhase(Phase.LoadingFsimage);
            startupProgress.SetFile(Phase.LoadingFsimage, "file1");
            startupProgress.SetSize(Phase.LoadingFsimage, 1000L);
            Step step = new Step(StepType.Inodes);

            startupProgress.BeginStep(Phase.LoadingFsimage, step);
            startupProgress.SetTotal(Phase.LoadingFsimage, step, 10000L);
            StartupProgressTestHelper.IncrementCounter(startupProgress, Phase.LoadingFsimage,
                                                       step, 100L);
            startupProgress.EndStep(Phase.LoadingFsimage, step);
            startupProgress.EndPhase(Phase.LoadingFsimage);
            // Force completion of phases, so that entire startup process is completed.
            foreach (Phase phase in EnumSet.AllOf <Phase>())
            {
                if (startupProgress.GetStatus(phase) != Status.Complete)
                {
                    startupProgress.BeginPhase(phase);
                    startupProgress.EndPhase(phase);
                }
            }
            StartupProgressView before = startupProgress.CreateView();

            // Attempt more updates and counter increments.
            startupProgress.BeginPhase(Phase.LoadingFsimage);
            startupProgress.SetFile(Phase.LoadingFsimage, "file2");
            startupProgress.SetSize(Phase.LoadingFsimage, 2000L);
            startupProgress.BeginStep(Phase.LoadingFsimage, step);
            startupProgress.SetTotal(Phase.LoadingFsimage, step, 20000L);
            StartupProgressTestHelper.IncrementCounter(startupProgress, Phase.LoadingFsimage,
                                                       step, 100L);
            startupProgress.EndStep(Phase.LoadingFsimage, step);
            startupProgress.EndPhase(Phase.LoadingFsimage);
            // Also attempt a whole new step that wasn't used last time.
            startupProgress.BeginPhase(Phase.LoadingEdits);
            Step newStep = new Step("file1");

            startupProgress.BeginStep(Phase.LoadingEdits, newStep);
            StartupProgressTestHelper.IncrementCounter(startupProgress, Phase.LoadingEdits, newStep
                                                       , 100L);
            startupProgress.EndStep(Phase.LoadingEdits, newStep);
            startupProgress.EndPhase(Phase.LoadingEdits);
            StartupProgressView after = startupProgress.CreateView();

            // Expect that data was frozen after completion of entire startup process, so
            // second set of updates and counter increments should have had no effect.
            NUnit.Framework.Assert.AreEqual(before.GetCount(Phase.LoadingFsimage), after.GetCount
                                                (Phase.LoadingFsimage));
            NUnit.Framework.Assert.AreEqual(before.GetCount(Phase.LoadingFsimage, step), after
                                            .GetCount(Phase.LoadingFsimage, step));
            NUnit.Framework.Assert.AreEqual(before.GetElapsedTime(), after.GetElapsedTime());
            NUnit.Framework.Assert.AreEqual(before.GetElapsedTime(Phase.LoadingFsimage), after
                                            .GetElapsedTime(Phase.LoadingFsimage));
            NUnit.Framework.Assert.AreEqual(before.GetElapsedTime(Phase.LoadingFsimage, step)
                                            , after.GetElapsedTime(Phase.LoadingFsimage, step));
            NUnit.Framework.Assert.AreEqual(before.GetFile(Phase.LoadingFsimage), after.GetFile
                                                (Phase.LoadingFsimage));
            NUnit.Framework.Assert.AreEqual(before.GetSize(Phase.LoadingFsimage), after.GetSize
                                                (Phase.LoadingFsimage));
            NUnit.Framework.Assert.AreEqual(before.GetTotal(Phase.LoadingFsimage), after.GetTotal
                                                (Phase.LoadingFsimage));
            NUnit.Framework.Assert.AreEqual(before.GetTotal(Phase.LoadingFsimage, step), after
                                            .GetTotal(Phase.LoadingFsimage, step));
            NUnit.Framework.Assert.IsFalse(after.GetSteps(Phase.LoadingEdits).GetEnumerator()
                                           .HasNext());
        }