public void SampleCombinerCopiesInitialData()
        {
            var hitCountSample = new DataSample { HitCount = 400, SampleType = DataSampleType.HitCount, StartTime = this.start.ToMillisecondTimestamp(), EndTime = this.end.ToMillisecondTimestamp() };

            var combiner = new SampleCombiner(hitCountSample);
            Assert.IsNotNull(combiner.Data);
            Assert.AreEqual(DataSampleType.HitCount, combiner.Data.SampleType);
            Assert.AreEqual(400, (int)(combiner.Data).HitCount);
        }
        public void TestHitCountSampleCombiner()
        {
            var hitCountSample = new DataSample { HitCount = 1, SampleType = DataSampleType.HitCount, StartTime = this.start.ToMillisecondTimestamp(), EndTime = this.end.ToMillisecondTimestamp() };
            var combiner = new SampleCombiner(hitCountSample);

            for (uint i = 0; i < 100; i++)
            {
                var before = (combiner.Data).HitCount;
                combiner.AddSample(new DataSample { HitCount = i, SampleType = DataSampleType.HitCount, StartTime = this.start.ToMillisecondTimestamp(), EndTime = this.end.ToMillisecondTimestamp() });
                Assert.AreEqual(before + i, (combiner.Data).HitCount);
            }
        }
        public void SampleCombinerFactoryChecksArguments()
        {
            Assert.Throws<ArgumentNullException>(() => SampleCombiner.Create(null));

            var garbageDataSample = new DataSample();
            garbageDataSample.SampleType = DataSampleType.None;

            Assert.Throws<ArgumentException>(() => new SampleCombiner(garbageDataSample));

            garbageDataSample.SampleType = (DataSampleType)100;
            Assert.Throws<ArgumentException>(() => new SampleCombiner(garbageDataSample));

            var percentileSample = new DataSample();
            Assert.Throws<ArgumentException>(() => new SampleCombiner(percentileSample));
        }
        public void TestHistogramSampleCombiner()
        {
            var initialSample = new DataSample
                                {
                                    SampleType = DataSampleType.Histogram,
                                    Histogram = new Dictionary<long, uint> {{1, 1}, {2, 1}},
                                    StartTime = this.start.ToMillisecondTimestamp(),
                                    EndTime = this.end.ToMillisecondTimestamp()
                                };
            var combiner = new SampleCombiner(initialSample);

            var doubleSample = new DataSample
                               {
                                   Histogram = new Dictionary<long, uint> {{1, 2}, {10, 2}}
                               };
            for (int i = 0; i < 100; i++)
            {
                combiner.AddData(doubleSample);
            }

            var result = combiner.Data;
            Assert.AreEqual((uint)201, result.Histogram[1]);
            Assert.AreEqual((uint)1, result.Histogram[2]);
            Assert.AreEqual((uint)200, result.Histogram[10]);
        }
        public void TestMinimumSampleCombiner()
        {
            var initialSample = new DataSample
            {
                SampleType = DataSampleType.Minimum,
                MinValue = 100,
                SampleCount = 100,
                StartTime = this.start.ToMillisecondTimestamp(),
                EndTime = this.end.ToMillisecondTimestamp()
            };

            var combiner = new SampleCombiner(initialSample);
            var addMe = new DataSample { SampleCount = 1000, SampleType = DataSampleType.Minimum};
            for (int i = 0; i < 200; i++)
            {
                addMe.MinValue = i;
                combiner.AddData(addMe);
            }

            Assert.AreEqual(0, combiner.Data.MinValue);
            Assert.AreEqual((ulong)200100, combiner.Data.SampleCount);
        }
        public void SampleCombinerMergesTimeRanges()
        {
            var now = DateTime.Now;
            var today = new DateTime(now.Year, now.Month, now.Day);
            var yesterday = today.AddDays(-1);
            var tomorrow = today.AddDays(1);

            var firstSample = new DataSample { HitCount = 1, SampleType = DataSampleType.HitCount, StartTime = yesterday.ToMillisecondTimestamp(), EndTime = today.ToMillisecondTimestamp() };
            var secondSample = new DataSample { HitCount = 1, SampleType = DataSampleType.HitCount, StartTime = today.ToMillisecondTimestamp(), EndTime = tomorrow.ToMillisecondTimestamp() };
            var combiner = new SampleCombiner(firstSample);
            combiner.AddSample(secondSample);

            Assert.AreEqual(yesterday.ToMillisecondTimestamp(), combiner.Data.StartTime);
            Assert.AreEqual(tomorrow.ToMillisecondTimestamp(), combiner.Data.EndTime);
        }
        public void TestAverageSampleCombinerDoesNotOverflow()
        {
            const int iterations = 10;
            var theSample = new DataSample
            {
                SampleType = DataSampleType.Average,
                Average = double.MaxValue,
                SampleCount = ulong.MaxValue / (iterations + 1),
                StartTime = this.start.ToMillisecondTimestamp(),
                EndTime = this.end.ToMillisecondTimestamp()
            };

            var combiner = new SampleCombiner(theSample);
            for (int i = 0; i < iterations; i++)
            {
                combiner.AddData(theSample);
            }
        }
        public void TestAverageSampleCombiner()
        {
            var initialSample = new DataSample
                                {
                                    SampleType = DataSampleType.Average,
                                    Average = 1.0,
                                    SampleCount = 100,
                                    StartTime = this.start.ToMillisecondTimestamp(),
                                    EndTime = this.end.ToMillisecondTimestamp()
                                };

            var combiner = new SampleCombiner(initialSample);
            var addMe = new DataSample { Average = 1.0, SampleCount = 1000, SampleType = DataSampleType.Average};
            for (int i = 0; i < 100; i++)
            {
                combiner.AddData(addMe);
            }

            Assert.AreEqual(1.0, combiner.Data.Average);
            Assert.IsTrue(combiner.Data.SampleCount > 100);
        }
 private static TimeRange CreateTimeRange(DataSample sample)
 {
     return new TimeRange(sample.StartTime, sample.EndTime);
 }
Example #10
0
        private DataSample CalculatePercentile(DataSample dataSample)
        {
            if (dataSample == null || dataSample.SampleType != DataSampleType.Histogram)
            {
                return dataSample;
            }

            return new DataSample
                   {
                       Name = dataSample.Name,
                       Dimensions = new Dictionary<string, string>(dataSample.Dimensions) {{ReservedDimensions.PercentileDimension, this.requestedPercentile.ToString("##.###")}},
                       StartTime = dataSample.StartTime,
                       EndTime = dataSample.EndTime,
                       SampleCount = dataSample.SampleCount,
                       MachineCount = dataSample.MachineCount,
                       SampleType = DataSampleType.Percentile,
                       Percentile = this.requestedPercentile,
                       PercentileValue = dataSample.Histogram.GetValueAtPercentile(this.requestedPercentile)
                   };
        }
 private void VerifySample(DataSample sample, ulong expectedHitCount)
 {
     Assert.AreEqual(expectedHitCount, sample.HitCount);
 }