Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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>()));
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }