Пример #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));
        }
Пример #2
0
        public virtual void GetMetrics(MetricsCollector collector, bool all)
        {
            StartupProgressView  prog    = startupProgress.CreateView();
            MetricsRecordBuilder builder = collector.AddRecord(StartupProgressMetricsInfo);

            builder.AddCounter(Interns.Info("ElapsedTime", "overall elapsed time"), prog.GetElapsedTime
                                   ());
            builder.AddGauge(Interns.Info("PercentComplete", "overall percent complete"), prog
                             .GetPercentComplete());
            foreach (Phase phase in prog.GetPhases())
            {
                AddCounter(builder, phase, "Count", " count", prog.GetCount(phase));
                AddCounter(builder, phase, "ElapsedTime", " elapsed time", prog.GetElapsedTime(phase
                                                                                               ));
                AddCounter(builder, phase, "Total", " total", prog.GetTotal(phase));
                AddGauge(builder, phase, "PercentComplete", " percent complete", prog.GetPercentComplete
                             (phase));
            }
        }
Пример #3
0
        public virtual void TestPercentComplete()
        {
            startupProgress.BeginPhase(Phase.LoadingFsimage);
            Step loadingFsImageInodes = new Step(StepType.Inodes);

            startupProgress.BeginStep(Phase.LoadingFsimage, loadingFsImageInodes);
            startupProgress.SetTotal(Phase.LoadingFsimage, loadingFsImageInodes, 1000L);
            StartupProgressTestHelper.IncrementCounter(startupProgress, Phase.LoadingFsimage,
                                                       loadingFsImageInodes, 100L);
            Step loadingFsImageDelegationKeys = new Step(StepType.DelegationKeys);

            startupProgress.BeginStep(Phase.LoadingFsimage, loadingFsImageDelegationKeys);
            startupProgress.SetTotal(Phase.LoadingFsimage, loadingFsImageDelegationKeys, 800L
                                     );
            StartupProgressTestHelper.IncrementCounter(startupProgress, Phase.LoadingFsimage,
                                                       loadingFsImageDelegationKeys, 200L);
            startupProgress.BeginPhase(Phase.LoadingEdits);
            Step loadingEditsFile = new Step("file", 1000L);

            startupProgress.BeginStep(Phase.LoadingEdits, loadingEditsFile);
            startupProgress.SetTotal(Phase.LoadingEdits, loadingEditsFile, 10000L);
            StartupProgressTestHelper.IncrementCounter(startupProgress, Phase.LoadingEdits, loadingEditsFile
                                                       , 5000L);
            StartupProgressView view = startupProgress.CreateView();

            NUnit.Framework.Assert.IsNotNull(view);
            NUnit.Framework.Assert.AreEqual(0.167f, view.GetPercentComplete(), 0.001f);
            NUnit.Framework.Assert.AreEqual(0.167f, view.GetPercentComplete(Phase.LoadingFsimage
                                                                            ), 0.001f);
            NUnit.Framework.Assert.AreEqual(0.10f, view.GetPercentComplete(Phase.LoadingFsimage
                                                                           , loadingFsImageInodes), 0.001f);
            NUnit.Framework.Assert.AreEqual(0.25f, view.GetPercentComplete(Phase.LoadingFsimage
                                                                           , loadingFsImageDelegationKeys), 0.001f);
            NUnit.Framework.Assert.AreEqual(0.5f, view.GetPercentComplete(Phase.LoadingEdits)
                                            , 0.001f);
            NUnit.Framework.Assert.AreEqual(0.5f, view.GetPercentComplete(Phase.LoadingEdits,
                                                                          loadingEditsFile), 0.001f);
            NUnit.Framework.Assert.AreEqual(0.0f, view.GetPercentComplete(Phase.SavingCheckpoint
                                                                          ), 0.001f);
            NUnit.Framework.Assert.AreEqual(0.0f, view.GetPercentComplete(Phase.SavingCheckpoint
                                                                          , new Step(StepType.Inodes)), 0.001f);
            // End steps/phases, and confirm that they jump to 100% completion.
            startupProgress.EndStep(Phase.LoadingFsimage, loadingFsImageInodes);
            startupProgress.EndStep(Phase.LoadingFsimage, loadingFsImageDelegationKeys);
            startupProgress.EndPhase(Phase.LoadingFsimage);
            startupProgress.EndStep(Phase.LoadingEdits, loadingEditsFile);
            startupProgress.EndPhase(Phase.LoadingEdits);
            view = startupProgress.CreateView();
            NUnit.Framework.Assert.IsNotNull(view);
            NUnit.Framework.Assert.AreEqual(0.5f, view.GetPercentComplete(), 0.001f);
            NUnit.Framework.Assert.AreEqual(1.0f, view.GetPercentComplete(Phase.LoadingFsimage
                                                                          ), 0.001f);
            NUnit.Framework.Assert.AreEqual(1.0f, view.GetPercentComplete(Phase.LoadingFsimage
                                                                          , loadingFsImageInodes), 0.001f);
            NUnit.Framework.Assert.AreEqual(1.0f, view.GetPercentComplete(Phase.LoadingFsimage
                                                                          , loadingFsImageDelegationKeys), 0.001f);
            NUnit.Framework.Assert.AreEqual(1.0f, view.GetPercentComplete(Phase.LoadingEdits)
                                            , 0.001f);
            NUnit.Framework.Assert.AreEqual(1.0f, view.GetPercentComplete(Phase.LoadingEdits,
                                                                          loadingEditsFile), 0.001f);
            NUnit.Framework.Assert.AreEqual(0.0f, view.GetPercentComplete(Phase.SavingCheckpoint
                                                                          ), 0.001f);
            NUnit.Framework.Assert.AreEqual(0.0f, view.GetPercentComplete(Phase.SavingCheckpoint
                                                                          , new Step(StepType.Inodes)), 0.001f);
        }