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); }
public void MarkCommandSuccess_BeforeFirstSnapshot_GetsIncludedInSnapshot() { var metrics = new StandardCommandMetrics( GroupKey.Named("Test"), new TransientConfigurableValue <long>(30000), new TransientConfigurableValue <long>(1000), new IgnoringStats()); metrics.MarkCommandSuccess(); var snapshot = metrics.GetSnapshot(); Assert.Equal(1, snapshot.Total); Assert.Equal(0, snapshot.ErrorPercentage); }
public void GetSnapshot_WithinCachePeriod_ReturnsPreviousSnapshot() { var clock = new ManualTestClock(); var key = AnyGroupKey; var mockConfig = new Mock <IFailurePercentageCircuitBreakerConfig>(MockBehavior.Strict); mockConfig.Setup(m => m.GetWindowMillis(key)).Returns(10000); mockConfig.Setup(m => m.GetSnapshotTtlMillis(key)).Returns(1000); // 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 UtcSystemClock().GetMillisecondTimestamp()); var metrics = new StandardCommandMetrics(key, mockConfig.Object, clock, new DefaultMjolnirLogFactory()); 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); }
public void MarkCommandSuccess_BeforeFirstSnapshot_GetsIncludedInSnapshot() { var key = AnyGroupKey; var mockConfig = new Mock <IFailurePercentageCircuitBreakerConfig>(MockBehavior.Strict); mockConfig.Setup(m => m.GetWindowMillis(key)).Returns(30000); mockConfig.Setup(m => m.GetSnapshotTtlMillis(key)).Returns(1000); var metrics = new StandardCommandMetrics(key, mockConfig.Object, new DefaultMjolnirLogFactory()); metrics.MarkCommandSuccess(); var snapshot = metrics.GetSnapshot(); Assert.Equal(1, snapshot.Total); Assert.Equal(0, snapshot.ErrorPercentage); }
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()); }
private MetricsSnapshot SnapshotFor(int success, int failure) { var key = AnyGroupKey; var mockConfig = new Mock <IFailurePercentageCircuitBreakerConfig>(MockBehavior.Strict); mockConfig.Setup(m => m.GetWindowMillis(key)).Returns(10000); mockConfig.Setup(m => m.GetSnapshotTtlMillis(key)).Returns(0); // Don't cache snapshots. var metrics = new StandardCommandMetrics(key, mockConfig.Object, new DefaultMjolnirLogFactory()); for (var i = 0; i < success; i++) { metrics.MarkCommandSuccess(); } for (var i = 0; i < failure; i++) { metrics.MarkCommandFailure(); } return(metrics.GetSnapshot()); }