public void CanAppendHistogram()
        {
            var histogram1 = Create(DefaultHighestTrackableValue, DefaultSignificantDigits);

            histogram1.RecordValue(1);
            histogram1.RecordValue((long.MaxValue / 2) + 1);
            histogram1.SetTimes();
            var histogram2 = Create(DefaultHighestTrackableValue, DefaultSignificantDigits);

            histogram2.RecordValue(2);
            histogram2.SetTimes();

            byte[] data;
            using (var writerStream = new MemoryStream())
                using (var log = new HistogramLogWriter(writerStream))
                {
                    log.Append(histogram1);
                    log.Append(histogram2);
                    data = writerStream.ToArray();
                }
            var actualHistograms = data.ReadHistograms();

            Assert.Equal(2, actualHistograms.Length);
            HistogramAssert.AreValueEqual(histogram1, actualHistograms.First());
            HistogramAssert.AreValueEqual(histogram2, actualHistograms.Skip(1).First());
        }
        public void CanReadV2TaggedLogs(string logPath)
        {
            var  readerStream   = GetEmbeddedFileStream(logPath);
            var  reader         = new HistogramLogReader(readerStream);
            int  histogramCount = 0;
            long totalCount     = 0;
            var  accumulatedHistogramWithNoTag = Create(85899345920838, DefaultSignificantDigits);
            var  accumulatedHistogramWithTagA  = Create(85899345920838, DefaultSignificantDigits);

            foreach (var histogram in reader.ReadHistograms())
            {
                histogramCount++;
                Assert.IsAssignableFrom <HistogramBase>(histogram);// "Expected integer value histograms in log file");

                totalCount += histogram.TotalCount;
                if (string.IsNullOrEmpty(histogram.Tag))
                {
                    accumulatedHistogramWithNoTag.Add(histogram);
                }
                else if (histogram.Tag == "A")
                {
                    accumulatedHistogramWithTagA.Add(histogram);
                }
            }

            Assert.Equal(42, histogramCount);
            Assert.Equal(32290, totalCount);

            HistogramAssert.AreValueEqual(accumulatedHistogramWithNoTag, accumulatedHistogramWithTagA);
        }
Exemple #3
0
        public void Given_a_Histogram_populated_with_full_range_of_values_When_encoded_and_decoded_with_compression_Then_data_is_preserved()
        {
            var source = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);

            LoadFullRange(source);
            var result = CompressedEncodeDecode(source);

            HistogramAssert.AreValueEqual(source, result);
        }
Exemple #4
0
        public void Given_a_populated_Histogram_When_encoded_and_decoded_Then_data_is_preserved()
        {
            var source = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);

            Load(source);
            var result = EncodeDecode(source);

            HistogramAssert.AreValueEqual(source, result);
        }
        public void CanRoundTripSingleHistogram(long highestTrackableValue, int significantDigits, int multiplier)
        {
            var histogram = CreatePopulatedHistogram(highestTrackableValue, significantDigits, multiplier);

            histogram.SetTimes();
            var data             = histogram.WriteLog();
            var actualHistograms = data.ReadHistograms();

            Assert.Equal(1, actualHistograms.Length);
            HistogramAssert.AreValueEqual(histogram, actualHistograms.Single());
        }
        protected void RoundTripSingleHistogramsWithFullRangesOfCountsAndValues(long count)
        {
            var value     = 1;
            var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantDigits);

            histogram.RecordValueWithCount(value, count);

            histogram.SetTimes();
            var data             = histogram.WriteLog();
            var actualHistograms = data.ReadHistograms();

            Assert.Equal(1, actualHistograms.Length);
            HistogramAssert.AreValueEqual(histogram, actualHistograms.Single());
        }
        public void CanRoundTripSingleHistogramsWithSparseValues(string tag)
        {
            var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantDigits);

            histogram.Tag = tag;
            histogram.RecordValue(1);
            histogram.RecordValue((long.MaxValue / 2) + 1);

            histogram.SetTimes();
            var data             = histogram.WriteLog();
            var actualHistograms = data.ReadHistograms();

            Assert.Equal(1, actualHistograms.Length);
            Assert.Equal(tag, actualHistograms[0].Tag);
            HistogramAssert.AreValueEqual(histogram, actualHistograms.Single());
        }