public void TimeShouldUpdateMetricWhenExisting() { //Arrange var timers = new ConcurrentDictionary <string, ILatencyTracker>(); var cache = new InMemoryMetricsCache(null, timers); var metricsLog = new InMemoryMetricsLog(null, cache); //Act metricsLog.Time("time_test", 1); metricsLog.Time("time_test", 9); metricsLog.Time("time_test", 8); //Assert ILatencyTracker timer = cache.GetLatencyTracker("time_test"); Assert.AreEqual(1, timer.GetLatency(0)); Assert.AreEqual(2, timer.GetLatency(6)); long[] latencies = timer.GetLatencies(); Assert.AreEqual(3, latencies.Sum()); }
public void SendTimeMetricsSuccessfully() { //Arrange var timers = new ConcurrentDictionary <string, ILatencyTracker>(); var metricsApiClientMock = new Mock <IMetricsSdkApiClient>(); var cache = new InMemoryMetricsCache(null, timers); var metricsLog = new InMemoryMetricsLog(metricsApiClientMock.Object, cache, 1, -1); //Act metricsLog.Time("time_test", 1); //Assert metricsApiClientMock.Verify(x => x.SendTimeMetrics(It.IsAny <string>())); }
public void TimeShouldNotAddMetricIfNoNameSpecified() { //Arrange var timers = new ConcurrentDictionary <string, ILatencyTracker>(); var cache = new InMemoryMetricsCache(null, timers); var metricsLog = new InMemoryMetricsLog(null, cache); //Act metricsLog.Time("", 1000); //Assert ILatencyTracker timer = cache.GetLatencyTracker(""); Assert.IsNull(timer); }
public void TimeShouldNotUpdateMetricIfDeltaIsLessThanZero() { //Arrange var timers = new ConcurrentDictionary <string, ILatencyTracker>(); var cache = new InMemoryMetricsCache(null, timers); var metricsLog = new InMemoryMetricsLog(null, cache); //Act metricsLog.Time("time_test", -1); //Assert ILatencyTracker timer = cache.GetLatencyTracker("time_test"); Assert.IsNull(timer); }