public void SummaryWriterIdleOutlierTest()
        {
            // we insert outliers after 8 and 9. It should finish the idle round and then start a non-idle one.
            var stream        = new StringStream();
            var summaryWriter = new SummaryWriter(stream.Writer)
            {
                IdleFlushRate = 10, NonIdleFlushRate = 5
            };

            for (var i = 0; i < 15; i++)
            {
                var measurement = new Measurement(new DateTime(2020, 12, 28, 0, 0, i), 2400 + (i > 7 ? 200 : 0), i == 0 ? 2500 : 7993 + i);
                var result      = new FlowMeter
                {
                    Amplitude         = 5 + (i > 7 ? 200 : 0), HighPass = 0, LowPassFast = 2400 - i, LowPassSlow = 2385 + i,
                    Exclude           = i > 7, ExcludeAll = false, Flow = false,
                    LowPassOnHighPass = i, Outlier = i > 7, Drift = i > 9
                };
                summaryWriter.AddMeasurement(measurement, result);
                summaryWriter.PrepareWrite();
                Assert.AreEqual(i < 8 ? 10u : 5u, summaryWriter.FlushRate,
                                " The first 8 data points FlushRate is 10, then it becomes 5 because of outliers (round {0})", i);
                if (i != 9)
                {
                    // force skipping the write at the time it was supposed to, so it gets done next time.
                    summaryWriter.Write();
                }

                if (i <= 9)
                {
                    Assert.IsTrue(string.IsNullOrEmpty(stream.Content()), "Nothing written the first 9 points");
                }
                else if (i < 14)
                {
                    //"S,Measure,Flows,SumAmplitude,SumLPonHP,LowPassFast,LPonHP,Outliers,Waits,Excludes,AvgDelay,CRC"
                    Assert.AreEqual("S,10,0,0,0,2391,2394,9,2,0,2,7448,49755\r\n", stream.Content(),
                                    "At 10 we get a summary with 2 outliers and 2 excludes");
                }
                else
                {
                    Assert.AreEqual("S,10,0,0,0,2391,2394,9,2,0,2,7448,49755\r\nS,5,0,0,0,2386,2399,14,5,5,5,8005,17350\r\n", stream.Content(),
                                    "At 15 we get the next batch with 5 outliers and excludes");
                }
            }
        }
        public void SummaryWriterExcludeAllTest()
        {
            // ExcludeAll becomes true in the third sample. That should put excluded on 3. It should finish the idle round and then start a non-idle one.
            // Then we put WaitSamples on 1 to get WaitCount filled.
            // We do this all before sample 5 so the non idle rate kicks in early.
            var stream        = new StringStream();
            var summaryWriter = new SummaryWriter(stream.Writer)
            {
                IdleFlushRate = 10, NonIdleFlushRate = 5
            };

            for (var i = 0; i < 15; i++)
            {
                var measurement = new Measurement(new DateTime(2020, 12, 28, 0, 0, i), 2400 + (i > 7 ? 200 : 0), i == 0 ? 2500 : 7500 + i * 5);

                var result = new FlowMeter
                {
                    Amplitude  = i == 0 ? 10000 : 2000, HighPass = 0, LowPassFast = 2400 - i, LowPassSlow = 2385 + i, Exclude = i == 2 || i == 3,
                    ExcludeAll = i == 2, Flow = false, LowPassOnHighPass = 10 + i, Outlier = i == 2, Drift = false
                };
                summaryWriter.AddMeasurement(measurement, result);
                summaryWriter.PrepareWrite();
                Assert.AreEqual(i < 2 || i > 4 ? 10u : 5u, summaryWriter.FlushRate,
                                "Flush rate is 10 the first two data points, and after the 5th. In between it is 5");
                summaryWriter.Write();
                if (i < 4)
                {
                    Assert.IsTrue(string.IsNullOrEmpty(stream.Content()), "Nothing written before the 5th data point");
                }
                else if (i < 14)
                {
                    //"S,Measure,Flows,SumAmplitude,SumLPonHP,LowPassFast,LPonHP,Outliers,Waits,Drifts,AvgDelay,CRC"
                    Assert.AreEqual("S,5,0,0,0,2396,2389,14,1,0,4,6510,17220\r\n", stream.Content(), "The right data written after 5 points");
                }
                else
                {
                    Assert.AreEqual("S,5,0,0,0,2396,2389,14,1,0,4,6510,17220\r\nS,10,0,0,0,2386,2399,24,0,0,0,7548,8484\r\n", stream.Content(),
                                    "Without special events, the next flush is after 10 data points");
                }
            }
        }
Beispiel #3
0
        public void MeasurementWriterHeaderAndFlushRateTest()
        {
            var stream = new StringStream();
            var writer = new MeasurementWriter(stream.Writer);

            Assert.AreEqual(10u, writer.FlushRate, "Default flush rate is 10");
            writer.DesiredFlushRate = 2;
            Assert.AreEqual(2u, writer.FlushRate, "Changing desired flush rate before printing in a line changes FlushRate");
            writer.WriteHeader();
            Assert.AreEqual("M,M0,W0,M1,W1,CRC\r\n", stream.Content(), "Header has 2 data points");
            writer.Write(new Measurement(DateTime.Now, 2400, 6000));
            writer.DesiredFlushRate = 0;
            Assert.AreEqual(2u, writer.FlushRate, "Changing desired flush rate while in a line doesn't immediately change FlushRate");
            writer.Write(new Measurement(DateTime.Now, 2375, 6200));
            Assert.AreEqual("M,M0,W0,M1,W1,CRC\r\nM,2400,6000,2375,6200,46910\r\n", stream.Content(), "Flush happens after 2 data points");
            Assert.AreEqual(0u, writer.FlushRate, "The desired flush rate gets applied now");
            // This measurement should get ignored
            writer.Write(new Measurement(DateTime.Now, 2450, 5800));
            writer.DesiredFlushRate = 1;
            Assert.AreEqual(1u, writer.FlushRate, "When not logging, FlushRrate gets applied immediately");
            writer.Write(new Measurement(DateTime.Now, 2425, 6400));
            Assert.AreEqual("M,M0,W0,M1,W1,CRC\r\nM,2400,6000,2375,6200,46910\r\nM,2425,6400,19517\r\n", stream.Content(),
                            "data point sent while FlushRate was 0 is not included");
        }
        public void SummaryWriterFlowTest()
        {
            var stream        = new StringStream();
            var summaryWriter = new SummaryWriter(stream.Writer)
            {
                IdleFlushRate = 10, NonIdleFlushRate = 5
            };

            for (var i = 0; i < 10; i++)
            {
                var measurement = new Measurement(new DateTime(2020, 12, 28, 0, 0, i), 2400 + i, 8000 + i);
                var result      = new FlowMeter
                {
                    Amplitude         = 5 + (i > 7 ? 10 : 0), HighPass = 0, LowPassFast = 2400, LowPassSlow = 2398, Exclude = false, ExcludeAll = false,
                    Flow              = i > 7,
                    LowPassOnHighPass = i, Outlier = false, Drift = false
                };
                summaryWriter.AddMeasurement(measurement, result);
                summaryWriter.PrepareWrite();
                summaryWriter.Write();
                if (i < 9)
                {
                    Assert.IsTrue(string.IsNullOrEmpty(stream.Content()), "Nothing written the first 9 data points");
                }
                else
                {
                    //"S,Measure,Flows,SumAmplitude,SumLPonHP,LowPassFast,LowPassSlow,LPonHP,Outliers,Waits,Excludes,AvgDelay,CRC"
                    Assert.AreEqual("S,10,2,30,17,2400,2398,9,0,0,0,8005,56358\r\n", stream.Content(),
                                    "After 10 points, we get a summary with 2 flows, and SumAmplitude and SumLPonP are populated");
                }
            }
            // Flush should not change anything as we have no more data.
            summaryWriter.Flush();
            Assert.AreEqual("S,10,2,30,17,2400,2398,9,0,0,0,8005,56358\r\n", stream.Content(),
                            "After 10 points, we get a summary with 2 flows, and SumAmplitude and SumLPonP are populated");
        }
        public void SummaryWriterIdleTest()
        {
            var stream        = new StringStream();
            var summaryWriter = new SummaryWriter(stream.Writer)
            {
                IdleFlushRate = 10, NonIdleFlushRate = 5
            };

            for (var i = 0; i < 10; i++)
            {
                var measurement = new Measurement(new DateTime(2020, 12, 28, 0, 0, i), 2400 + i, 8000 + i);
                var result      = new FlowMeter
                {
                    Amplitude         = i, HighPass = 0, LowPassFast = 2400, LowPassSlow = 2402, Exclude = false, ExcludeAll = false, Flow = false,
                    LowPassOnHighPass = 5 - i,
                    Outlier           = false, Drift = false
                };
                summaryWriter.AddMeasurement(measurement, result);
                if (i == 0)
                {
                    Assert.AreEqual(10u, summaryWriter.FlushRate, "Flush rate stays 10 (idle flush rate) when there is nothing special.");
                }
                summaryWriter.PrepareWrite();
                summaryWriter.Write();
                if (i < 9)
                {
                    Assert.IsTrue(string.IsNullOrEmpty(stream.Content()), "nothing written the fist 9 data points");
                }
                else
                {
                    //"S,Measure,Flows,SumAmplitude,SumLPonHP,LowPassFast,LowPassSlow,LPonHP,Outliers,Waits,Excludes,AvgDelay,CRC"
                    Assert.AreEqual("S,10,0,0,0,2400,2402,-4,0,0,0,8005,1750\r\n", stream.Content(),
                                    "10 idle points written after #10. LowPassFast and LPonHP get reported too.");
                }
            }
        }