public virtual void TestExceptions() { StopWatch sw = new StopWatch(); try { sw.Stop(); } catch (Exception e) { Assert.True("IllegalStateException is expected", e is InvalidOperationException ); } sw.Reset(); sw.Start(); try { sw.Start(); } catch (Exception e) { Assert.True("IllegalStateException is expected", e is InvalidOperationException ); } }
public virtual void Run() { StopWatch sw = new StopWatch(); IDictionary <string, JvmPauseMonitor.GcTimes> gcTimesBeforeSleep = this._enclosing .GetGcTimes(); while (this._enclosing.shouldRun) { sw.Reset().Start(); try { Thread.Sleep(JvmPauseMonitor.SleepIntervalMs); } catch (Exception) { return; } long extraSleepTime = sw.Now(TimeUnit.Milliseconds) - JvmPauseMonitor.SleepIntervalMs; IDictionary <string, JvmPauseMonitor.GcTimes> gcTimesAfterSleep = this._enclosing. GetGcTimes(); if (extraSleepTime > this._enclosing.warnThresholdMs) { ++this._enclosing.numGcWarnThresholdExceeded; JvmPauseMonitor.Log.Warn(this._enclosing.FormatMessage(extraSleepTime, gcTimesAfterSleep , gcTimesBeforeSleep)); } else { if (extraSleepTime > this._enclosing.infoThresholdMs) { ++this._enclosing.numGcInfoThresholdExceeded; JvmPauseMonitor.Log.Info(this._enclosing.FormatMessage(extraSleepTime, gcTimesAfterSleep , gcTimesBeforeSleep)); } } this._enclosing.totalGcExtraSleepTime += extraSleepTime; gcTimesBeforeSleep = gcTimesAfterSleep; } }