public void CanReadv1Logs_Skip_PreStart(string logPath, int skip, int take,
                                                int expectedHistogramCount, int expectedCombinedValueCount,
                                                int expectedCombined999, long expectedCombinedMaxLength,
                                                double expectedStartTime)
        {
            var  readerStream   = GetEmbeddedFileStream(logPath);
            var  reader         = new HistogramLogReader(readerStream);
            int  histogramCount = 0;
            long totalCount     = 0;

            HistogramBase accumulatedHistogram = Create(OneHourOfNanoseconds, DefaultSignificantDigits);
            var           histograms           = reader.ReadHistograms()
                                                 .Where(h => h.StartTimeStamp >= reader.GetStartTime().MillisecondsSinceUnixEpoch())
                                                 .Skip(skip)
                                                 .Take(take);

            foreach (var histogram in histograms)
            {
                histogramCount++;
                totalCount += histogram.TotalCount;
                accumulatedHistogram.Add(histogram);
            }

            Assert.Equal(expectedHistogramCount, histogramCount);
            Assert.Equal(expectedCombinedValueCount, totalCount);
            Assert.Equal(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
            Assert.Equal(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
            Assert.Equal(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
        }
        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);
        }
Beispiel #3
0
        public void CanReadv1Logs(string logPath, int skip, int take,
                                  int expectedHistogramCount, int expectedCombinedValueCount,
                                  int expectedCombined999, long expectedCombinedMaxLength,
                                  double expectedStartTime)
        {
            var  readerStream   = GetEmbeddedFileStream(logPath);
            var  reader         = new HistogramLogReader(readerStream);
            int  histogramCount = 0;
            long totalCount     = 0;

            HistogramBase accumulatedHistogram = new LongHistogram(3600L * 1000 * 1000 * 1000, 3);
            var           histograms           = reader.ReadHistograms()
                                                 .Skip(skip)
                                                 .Take(take);

            foreach (var histogram in histograms)
            {
                histogramCount++;
                totalCount += histogram.TotalCount;
                accumulatedHistogram.Add(histogram);
            }

            Assert.AreEqual(expectedHistogramCount, histogramCount);
            Assert.AreEqual(expectedCombinedValueCount, totalCount);
            Assert.AreEqual(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
            Assert.AreEqual(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
            Assert.AreEqual(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
        }
        public void CanReadEmptyLog()
        {
            byte[] data;
            var startTimeWritten = DateTime.Now;
            var expectedStartTime = startTimeWritten.SecondsSinceUnixEpoch()
                .Round(3);

            using (var writerStream = new MemoryStream())
            {
                HistogramLogWriter.Write(writerStream, startTimeWritten);
                data = writerStream.ToArray();
            }

            using (var readerStream = new MemoryStream(data))
            {
                var reader = new HistogramLogReader(readerStream);
                CollectionAssert.IsEmpty(reader.ReadHistograms().ToList());
                var actualStartTime = reader.GetStartTime().SecondsSinceUnixEpoch().Round(3);
                Assert.AreEqual(expectedStartTime, actualStartTime);
            }
        }
        public void CanReadEmptyLog()
        {
            byte[] data;
            var    startTimeWritten  = DateTime.Now;
            var    expectedStartTime = startTimeWritten.SecondsSinceUnixEpoch()
                                       .Round(3);

            using (var writerStream = new MemoryStream())
            {
                HistogramLogWriter.Write(writerStream, startTimeWritten);
                data = writerStream.ToArray();
            }

            using (var readerStream = new MemoryStream(data))
            {
                var reader = new HistogramLogReader(readerStream);
                Assert.Empty(reader.ReadHistograms().ToList());
                var actualStartTime = reader.GetStartTime().SecondsSinceUnixEpoch().Round(3);
                Assert.Equal(expectedStartTime, actualStartTime);
            }
        }
        public void CanReadv2Logs(string logPath)
        {
            var  readerStream         = GetEmbeddedFileStream(logPath);
            var  reader               = new HistogramLogReader(readerStream);
            int  histogramCount       = 0;
            long totalCount           = 0;
            var  accumulatedHistogram = Create(85899345920838, DefaultSignificantDigits);

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

                totalCount += histogram.TotalCount;
                accumulatedHistogram.Add(histogram);
            }

            Assert.Equal(62, histogramCount);
            Assert.Equal(48761, totalCount);
            Assert.Equal(1745879039, accumulatedHistogram.GetValueAtPercentile(99.9));
            Assert.Equal(1796210687, accumulatedHistogram.GetMaxValue());
            Assert.Equal(1441812279.474, reader.GetStartTime().SecondsSinceUnixEpoch());
        }
        public void CanReadv2Logs(string logPath)
        {
            var readerStream = GetEmbeddedFileStream(logPath);
            var reader = new HistogramLogReader(readerStream);
            int histogramCount = 0;
            long totalCount = 0;
            var accumulatedHistogram = new LongHistogram(85899345920838, 3);
            foreach (var histogram in reader.ReadHistograms())
            {
                histogramCount++;
                Assert.IsInstanceOf<HistogramBase>(histogram, "Expected integer value histograms in log file");

                totalCount += histogram.TotalCount;
                accumulatedHistogram.Add(histogram);
            }

            Assert.AreEqual(62, histogramCount);
            Assert.AreEqual(48761, totalCount);
            Assert.AreEqual(1745879039, accumulatedHistogram.GetValueAtPercentile(99.9));
            Assert.AreEqual(1796210687, accumulatedHistogram.GetMaxValue());
            Assert.AreEqual(1441812279.474, reader.GetStartTime().SecondsSinceUnixEpoch());
        }
        public void CanReadv1Logs_Skip_PreStart(string logPath, int skip, int take,
            int expectedHistogramCount, int expectedCombinedValueCount,
            int expectedCombined999, long expectedCombinedMaxLength,
            double expectedStartTime)
        {
            var readerStream = GetEmbeddedFileStream(logPath);
            var reader = new HistogramLogReader(readerStream);
            int histogramCount = 0;
            long totalCount = 0;

            HistogramBase accumulatedHistogram = new LongHistogram(3600L * 1000 * 1000 * 1000, 3);
            var histograms = reader.ReadHistograms()
                .Where(h => h.StartTimeStamp >= reader.GetStartTime().MillisecondsSinceUnixEpoch())
                .Skip(skip)
                .Take(take);
            foreach (var histogram in histograms)
            {
                histogramCount++;
                totalCount += histogram.TotalCount;
                accumulatedHistogram.Add(histogram);
            }

            Assert.AreEqual(expectedHistogramCount, histogramCount);
            Assert.AreEqual(expectedCombinedValueCount, totalCount);
            Assert.AreEqual(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
            Assert.AreEqual(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
            Assert.AreEqual(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
        }
        public void CanReadv1Logs(string logPath, int skip, int take,
            int expectedHistogramCount, int expectedCombinedValueCount,
            int expectedCombined999, long expectedCombinedMaxLength,
            double expectedStartTime)
        {
            var readerStream = GetEmbeddedFileStream(logPath);
            var reader = new HistogramLogReader(readerStream);
            int histogramCount = 0;
            long totalCount = 0;

            HistogramBase accumulatedHistogram = Create(OneHourOfNanoseconds, DefaultSignificantDigits);
            var histograms = reader.ReadHistograms()
                .Skip(skip)
                .Take(take);
            foreach (var histogram in histograms)
            {
                histogramCount++;
                totalCount += histogram.TotalCount;
                accumulatedHistogram.Add(histogram);
            }

            Assert.AreEqual(expectedHistogramCount, histogramCount);
            Assert.AreEqual(expectedCombinedValueCount, totalCount);
            Assert.AreEqual(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
            Assert.AreEqual(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
            Assert.AreEqual(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
        }
        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.IsInstanceOf<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.AreEqual(42, histogramCount);
            Assert.AreEqual(32290, totalCount);

            HistogramAssert.AreValueEqual(accumulatedHistogramWithNoTag, accumulatedHistogramWithTagA);
        }