public virtual void TestFinalState() { StartupProgressTestHelper.SetStartupProgressForFinalState(startupProgress); MetricsRecordBuilder builder = MetricsAsserts.GetMetrics(metrics, true); NUnit.Framework.Assert.IsTrue(MetricsAsserts.GetLongCounter("ElapsedTime", builder ) >= 0L); MetricsAsserts.AssertGauge("PercentComplete", 1.0f, builder); MetricsAsserts.AssertCounter("LoadingFsImageCount", 100L, builder); NUnit.Framework.Assert.IsTrue(MetricsAsserts.GetLongCounter("LoadingFsImageElapsedTime" , builder) >= 0L); MetricsAsserts.AssertCounter("LoadingFsImageTotal", 100L, builder); MetricsAsserts.AssertGauge("LoadingFsImagePercentComplete", 1.0f, builder); MetricsAsserts.AssertCounter("LoadingEditsCount", 200L, builder); NUnit.Framework.Assert.IsTrue(MetricsAsserts.GetLongCounter("LoadingEditsElapsedTime" , builder) >= 0L); MetricsAsserts.AssertCounter("LoadingEditsTotal", 200L, builder); MetricsAsserts.AssertGauge("LoadingEditsPercentComplete", 1.0f, builder); MetricsAsserts.AssertCounter("SavingCheckpointCount", 300L, builder); NUnit.Framework.Assert.IsTrue(MetricsAsserts.GetLongCounter("SavingCheckpointElapsedTime" , builder) >= 0L); MetricsAsserts.AssertCounter("SavingCheckpointTotal", 300L, builder); MetricsAsserts.AssertGauge("SavingCheckpointPercentComplete", 1.0f, builder); MetricsAsserts.AssertCounter("SafeModeCount", 400L, builder); NUnit.Framework.Assert.IsTrue(MetricsAsserts.GetLongCounter("SafeModeElapsedTime" , builder) >= 0L); MetricsAsserts.AssertCounter("SafeModeTotal", 400L, builder); MetricsAsserts.AssertGauge("SafeModePercentComplete", 1.0f, builder); }
public Void Call() { this._enclosing.startupProgress.BeginPhase(phase); this._enclosing.startupProgress.SetFile(phase, file); this._enclosing.startupProgress.SetSize(phase, size); this._enclosing.startupProgress.SetTotal(phase, step, total); StartupProgressTestHelper.IncrementCounter(this._enclosing.startupProgress, phase , step, 100L); this._enclosing.startupProgress.EndStep(phase, step); this._enclosing.startupProgress.EndPhase(phase); return(null); }
public virtual void TestCounter() { startupProgress.BeginPhase(Phase.LoadingFsimage); Step loadingFsImageInodes = new Step(StepType.Inodes); startupProgress.BeginStep(Phase.LoadingFsimage, loadingFsImageInodes); StartupProgressTestHelper.IncrementCounter(startupProgress, Phase.LoadingFsimage, loadingFsImageInodes, 100L); startupProgress.EndStep(Phase.LoadingFsimage, loadingFsImageInodes); Step loadingFsImageDelegationKeys = new Step(StepType.DelegationKeys); startupProgress.BeginStep(Phase.LoadingFsimage, loadingFsImageDelegationKeys); StartupProgressTestHelper.IncrementCounter(startupProgress, Phase.LoadingFsimage, loadingFsImageDelegationKeys, 200L); startupProgress.EndStep(Phase.LoadingFsimage, loadingFsImageDelegationKeys); startupProgress.EndPhase(Phase.LoadingFsimage); startupProgress.BeginPhase(Phase.LoadingEdits); Step loadingEditsFile = new Step("file", 1000L); startupProgress.BeginStep(Phase.LoadingEdits, loadingEditsFile); StartupProgressTestHelper.IncrementCounter(startupProgress, Phase.LoadingEdits, loadingEditsFile , 5000L); StartupProgressView view = startupProgress.CreateView(); NUnit.Framework.Assert.IsNotNull(view); NUnit.Framework.Assert.AreEqual(100L, view.GetCount(Phase.LoadingFsimage, loadingFsImageInodes )); NUnit.Framework.Assert.AreEqual(200L, view.GetCount(Phase.LoadingFsimage, loadingFsImageDelegationKeys )); NUnit.Framework.Assert.AreEqual(5000L, view.GetCount(Phase.LoadingEdits, loadingEditsFile )); NUnit.Framework.Assert.AreEqual(0L, view.GetCount(Phase.SavingCheckpoint, new Step (StepType.Inodes))); // Increment a counter again and check that the existing view was not // modified, but a new view shows the updated value. StartupProgressTestHelper.IncrementCounter(startupProgress, Phase.LoadingEdits, loadingEditsFile , 1000L); startupProgress.EndStep(Phase.LoadingEdits, loadingEditsFile); startupProgress.EndPhase(Phase.LoadingEdits); NUnit.Framework.Assert.AreEqual(5000L, view.GetCount(Phase.LoadingEdits, loadingEditsFile )); view = startupProgress.CreateView(); NUnit.Framework.Assert.IsNotNull(view); NUnit.Framework.Assert.AreEqual(6000L, view.GetCount(Phase.LoadingEdits, loadingEditsFile )); }
/// <exception cref="System.Exception"/> public virtual void TestElapsedTime() { startupProgress.BeginPhase(Phase.LoadingFsimage); Step loadingFsImageInodes = new Step(StepType.Inodes); startupProgress.BeginStep(Phase.LoadingFsimage, loadingFsImageInodes); Sharpen.Thread.Sleep(50L); // brief sleep to fake elapsed time startupProgress.EndStep(Phase.LoadingFsimage, loadingFsImageInodes); Step loadingFsImageDelegationKeys = new Step(StepType.DelegationKeys); startupProgress.BeginStep(Phase.LoadingFsimage, loadingFsImageDelegationKeys); Sharpen.Thread.Sleep(50L); // brief sleep to fake elapsed time startupProgress.EndStep(Phase.LoadingFsimage, loadingFsImageDelegationKeys); startupProgress.EndPhase(Phase.LoadingFsimage); 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); Sharpen.Thread.Sleep(50L); // brief sleep to fake elapsed time StartupProgressView view = startupProgress.CreateView(); NUnit.Framework.Assert.IsNotNull(view); NUnit.Framework.Assert.IsTrue(view.GetElapsedTime() > 0); NUnit.Framework.Assert.IsTrue(view.GetElapsedTime(Phase.LoadingFsimage) > 0); NUnit.Framework.Assert.IsTrue(view.GetElapsedTime(Phase.LoadingFsimage, loadingFsImageInodes ) > 0); NUnit.Framework.Assert.IsTrue(view.GetElapsedTime(Phase.LoadingFsimage, loadingFsImageDelegationKeys ) > 0); NUnit.Framework.Assert.IsTrue(view.GetElapsedTime(Phase.LoadingEdits) > 0); NUnit.Framework.Assert.IsTrue(view.GetElapsedTime(Phase.LoadingEdits, loadingEditsFile ) > 0); NUnit.Framework.Assert.IsTrue(view.GetElapsedTime(Phase.SavingCheckpoint) == 0); NUnit.Framework.Assert.IsTrue(view.GetElapsedTime(Phase.SavingCheckpoint, new Step (StepType.Inodes)) == 0); // Brief sleep, then check that completed phases/steps have the same elapsed // time, but running phases/steps have updated elapsed time. long totalTime = view.GetElapsedTime(); long loadingFsImageTime = view.GetElapsedTime(Phase.LoadingFsimage); long loadingFsImageInodesTime = view.GetElapsedTime(Phase.LoadingFsimage, loadingFsImageInodes ); long loadingFsImageDelegationKeysTime = view.GetElapsedTime(Phase.LoadingFsimage, loadingFsImageInodes); long loadingEditsTime = view.GetElapsedTime(Phase.LoadingEdits); long loadingEditsFileTime = view.GetElapsedTime(Phase.LoadingEdits, loadingEditsFile ); Sharpen.Thread.Sleep(50L); NUnit.Framework.Assert.IsTrue(totalTime < view.GetElapsedTime()); NUnit.Framework.Assert.AreEqual(loadingFsImageTime, view.GetElapsedTime(Phase.LoadingFsimage )); NUnit.Framework.Assert.AreEqual(loadingFsImageInodesTime, view.GetElapsedTime(Phase .LoadingFsimage, loadingFsImageInodes)); NUnit.Framework.Assert.IsTrue(loadingEditsTime < view.GetElapsedTime(Phase.LoadingEdits )); NUnit.Framework.Assert.IsTrue(loadingEditsFileTime < view.GetElapsedTime(Phase.LoadingEdits , loadingEditsFile)); }
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); }
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()); }