コード例 #1
0
        public void MarkCommandFailure_BeforeFirstSnapshot_GetsIncludedInSnapshot()
        {
            var metrics = new StandardCommandMetrics(
                GroupKey.Named("Test"),
                new TransientConfigurableValue<long>(30000),
                new TransientConfigurableValue<long>(1000),
                new IgnoringStats());
            metrics.MarkCommandFailure();

            var snapshot = metrics.GetSnapshot();
            Assert.Equal(1, snapshot.Total);
            Assert.Equal(100, snapshot.ErrorPercentage);
        }
コード例 #2
0
        public void GetSnapshot_WithinCachePeriod_ReturnsPreviousSnapshot()
        {
            var clock = new ManualTestClock();

            // Within the metrics, the last snapshot timestamp will probably be zero.
            // Let's start our clock with something far away from zero.
            clock.AddMilliseconds(new SystemClock().GetMillisecondTimestamp());
            var metrics = new StandardCommandMetrics(
                GroupKey.Named("Test"),
                new TransientConfigurableValue<long>(10000),
                new TransientConfigurableValue<long>(1000),
                clock,
                new IgnoringStats());

            metrics.MarkCommandSuccess();
            metrics.GetSnapshot(); // Take the first snapshot to cache it.
            metrics.MarkCommandSuccess();
            clock.AddMilliseconds(500); // Still within the snapshot TTL (1000).
            Assert.Equal(1, metrics.GetSnapshot().Total);
            clock.AddMilliseconds(1000); // Push time past the TTL.
            Assert.Equal(2, metrics.GetSnapshot().Total);
        }
コード例 #3
0
        private MetricsSnapshot SnapshotFor(int success, int failure)
        {
            var metrics = new StandardCommandMetrics(
                GroupKey.Named("Test"),
                new TransientConfigurableValue<long>(10000),
                new TransientConfigurableValue<long>(0),
                new IgnoringStats()); // Don't cache snapshots.
            for (var i = 0; i < success; i++)
            {
                metrics.MarkCommandSuccess();
            }

            for (var i = 0; i < failure; i++)
            {
                metrics.MarkCommandFailure();
            }
            return metrics.GetSnapshot();
        }