public void TimeIntervalCollectionAcceptance() { var collection = new TimeIntervalCollection(); Assert.Equal(0, collection.Count); collection.AddIntervals("i1"); collection.AddIntervals("i2"); Assert.Equal(2, collection.GetIntervalsCount()); var ti = new TimeInterval(); ti.Start(); ti.Stop(); collection.AddInterval("i1", ti); collection.AddInterval("i2", ti); collection.AddInterval("i3", ti); collection.AddInterval("i3", ti); var i3 = collection.GetIntervals("i3").ToList(); Assert.Equal(2, i3.Count); collection.Reset("i3"); i3 = collection.GetIntervals("i3").ToList(); Assert.Equal(0, i3.Count); }
private long GenerateIntervals(MetricsService metrics, string name) { var r = new Random(); long cycles = 50 + r.Next() % 200; if (cycles % 2 == 1) cycles++; Enumerable.Range(1, (int)cycles).ToList() .ForEach(x => { var ti = new TimeInterval(); ti.Start(); Thread.Sleep(10); ti.Stop(); metrics.Intervals.AddInterval(name, ti); }); return cycles; }