OLD | NEW |
(Empty) | |
| 1 #region Copyright notice and license |
| 2 |
| 3 // Copyright 2015, Google Inc. |
| 4 // All rights reserved. |
| 5 // |
| 6 // Redistribution and use in source and binary forms, with or without |
| 7 // modification, are permitted provided that the following conditions are |
| 8 // met: |
| 9 // |
| 10 // * Redistributions of source code must retain the above copyright |
| 11 // notice, this list of conditions and the following disclaimer. |
| 12 // * Redistributions in binary form must reproduce the above |
| 13 // copyright notice, this list of conditions and the following disclaimer |
| 14 // in the documentation and/or other materials provided with the |
| 15 // distribution. |
| 16 // * Neither the name of Google Inc. nor the names of its |
| 17 // contributors may be used to endorse or promote products derived from |
| 18 // this software without specific prior written permission. |
| 19 // |
| 20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 |
| 32 #endregion |
| 33 |
| 34 using System; |
| 35 using System.Collections.Generic; |
| 36 using System.IO; |
| 37 using System.Linq; |
| 38 using System.Threading; |
| 39 using System.Threading.Tasks; |
| 40 using Grpc.Core; |
| 41 using Grpc.Core.Utils; |
| 42 using Grpc.Testing; |
| 43 using NUnit.Framework; |
| 44 |
| 45 namespace Grpc.IntegrationTesting |
| 46 { |
| 47 public class HistogramTest |
| 48 { |
| 49 [Test] |
| 50 public void Simple() |
| 51 { |
| 52 var hist = new Histogram(0.01, 60e9); |
| 53 hist.AddObservation(10000); |
| 54 hist.AddObservation(10000); |
| 55 hist.AddObservation(11000); |
| 56 hist.AddObservation(11000); |
| 57 |
| 58 var data = hist.GetSnapshot(); |
| 59 |
| 60 Assert.AreEqual(4, data.Count); |
| 61 Assert.AreEqual(42000.0, data.Sum, 1e-6); |
| 62 Assert.AreEqual(10000, data.MinSeen); |
| 63 Assert.AreEqual(11000, data.MaxSeen); |
| 64 Assert.AreEqual(2.0*10000*10000 + 2.0*11000*11000, data.SumOfSquares
, 1e-6); |
| 65 |
| 66 // 1.01^925 < 10000 < 1.01^926 |
| 67 Assert.AreEqual(2, data.Bucket[925]); |
| 68 Assert.AreEqual(2, data.Bucket[935]); |
| 69 } |
| 70 |
| 71 [Test] |
| 72 public void ExtremeObservations() |
| 73 { |
| 74 var hist = new Histogram(0.01, 60e9); |
| 75 hist.AddObservation(-0.5); // should be in the first bucket |
| 76 hist.AddObservation(1e12); // should be in the last bucket |
| 77 |
| 78 var data = hist.GetSnapshot(); |
| 79 Assert.AreEqual(1, data.Bucket[0]); |
| 80 Assert.AreEqual(1, data.Bucket[data.Bucket.Count - 1]); |
| 81 } |
| 82 |
| 83 [Test] |
| 84 public void Reset() |
| 85 { |
| 86 var hist = new Histogram(0.01, 60e9); |
| 87 hist.AddObservation(10000); |
| 88 hist.AddObservation(11000); |
| 89 |
| 90 var data = hist.GetSnapshot(true); // snapshot contains data before
reset |
| 91 Assert.AreEqual(2, data.Count); |
| 92 Assert.AreEqual(10000, data.MinSeen); |
| 93 Assert.AreEqual(11000, data.MaxSeen); |
| 94 |
| 95 data = hist.GetSnapshot(); // snapshot contains state after reset |
| 96 Assert.AreEqual(0, data.Count); |
| 97 Assert.AreEqual(double.PositiveInfinity, data.MinSeen); |
| 98 Assert.AreEqual(double.NegativeInfinity, data.MaxSeen); |
| 99 Assert.AreEqual(0, data.Sum); |
| 100 Assert.AreEqual(0, data.SumOfSquares); |
| 101 CollectionAssert.AreEqual(new uint[data.Bucket.Count], data.Bucket);
|
| 102 } |
| 103 } |
| 104 } |
OLD | NEW |