public void Returned_number_of_intervals_per_known_endpoint_equals_history_size() { var entries = EntriesBuilder.Build(new Dictionary <DateTime, long> { { now.AddSeconds(-9), 0L } }); var store = new IntervalsStore <int>(TimeSpan.FromSeconds(10), 33, 0); store.Store(0, entries); var timings = store.GetIntervals(now.Add(store.IntervalSize)); Assert.AreEqual(1, timings.Length); Assert.AreEqual(33, timings[0].Intervals.Length); // ordering of intervals var dateTimes = timings[0].Intervals.Select(i => i.IntervalStart).ToArray(); var orderedDateTimes = dateTimes.OrderByDescending(d => d).ToArray(); CollectionAssert.AreEqual(orderedDateTimes, dateTimes); // length of intervals var intervalLength = dateTimes[0] - dateTimes[1]; for (var i = 1; i < dateTimes.Length; i++) { var dateDiff = dateTimes[i - 1] - dateTimes[i]; Assert.AreEqual(intervalLength, dateDiff); } }
public void Delayed_intervals_are_not_reported() { const int delayedIntervals = 5; var intervalSize = TimeSpan.FromSeconds(1); var delay = TimeSpan.FromTicks(delayedIntervals * intervalSize.Ticks); var entries = EntriesBuilder.Build(new Dictionary <DateTime, long> { { now.AddSeconds(-4), 1L }, { now.AddSeconds(-3), 1L }, { now, 1L } }); var store = new IntervalsStore <int>(intervalSize, 10, delayedIntervals); store.Store(0, entries); var timings = store.GetIntervals(now); var delayedTimings = store.GetIntervals(now.Add(delay)); Assert.AreEqual(0, timings[0].TotalMeasurements); Assert.AreEqual(3, delayedTimings[0].TotalMeasurements); }
public void Intervals_older_than_history_size_are_discarded() { var intervalSize = TimeSpan.FromSeconds(10); var numberOfIntervals = 100; var historySize = TimeSpan.FromTicks(intervalSize.Ticks * numberOfIntervals); var entries = EntriesBuilder.Build(new Dictionary <DateTime, long> { { now.Subtract(historySize), 3L } }); var store = new IntervalsStore <int>(intervalSize, numberOfIntervals, 0); store.Store(0, entries); var timings = store.GetIntervals(now.Add(store.IntervalSize)); Assert.IsTrue(timings[0].Intervals.All(i => i.TotalMeasurements == 0)); }