HystrixRollingPercentile { public int getPercentile(double percentile) { if (!enabled.get()) return -1; getCurrentBucket(); return getCurrentPercentileSnapshot().getPercentile(percentile); } @Deprecated  HystrixRollingPercentile(HystrixProperty<Integer> timeInMilliseconds, HystrixProperty<Integer> numberOfBuckets, HystrixProperty<Integer> bucketDataLength, HystrixProperty<Boolean> enabled);  HystrixRollingPercentile(int timeInMilliseconds, int numberOfBuckets, int bucketDataLength, HystrixProperty<Boolean> enabled);   HystrixRollingPercentile(Time time, int timeInMilliseconds, int numberOfBuckets, int bucketDataLength, HystrixProperty<Boolean> enabled); void addValue(int... value); int getPercentile(double percentile); int getMean(); void reset();  }
@Test public void testPercentileAlgorithm_Median1() { PercentileSnapshot list = new PercentileSnapshot(100, 100, 100, 100, 200, 200, 200, 300, 300, 300, 300); Assert.assertEquals(200, list.getPercentile(50)); }
@Test public void testPercentileAlgorithm_Median2() { PercentileSnapshot list = new PercentileSnapshot(100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 500); Assert.assertEquals(100, list.getPercentile(50)); }
@Test public void testPercentileAlgorithm_Median3() { PercentileSnapshot list = new PercentileSnapshot(50, 75, 100, 125, 160, 170, 180, 200, 210, 300, 500); Assert.assertEquals(175, list.getPercentile(50)); }
@Test public void testPercentileAlgorithm_Median4() { PercentileSnapshot list = new PercentileSnapshot(300, 75, 125, 500, 100, 160, 180, 200, 210, 50, 170); Assert.assertEquals(175, list.getPercentile(50)); }
@Test public void testPercentileAlgorithm_Extremes() { PercentileSnapshot p = new PercentileSnapshot(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 800, 768, 657, 700, 867); System.out.println("0.01: " + p.getPercentile(0.01)); System.out.println("10th: " + p.getPercentile(10)); System.out.println("Median: " + p.getPercentile(50)); System.out.println("75th: " + p.getPercentile(75)); System.out.println("90th: " + p.getPercentile(90)); System.out.println("99th: " + p.getPercentile(99)); System.out.println("99.5th: " + p.getPercentile(99.5)); System.out.println("99.99: " + p.getPercentile(99.99)); Assert.assertEquals(2, p.getPercentile(50)); Assert.assertEquals(2, p.getPercentile(10)); Assert.assertEquals(2, p.getPercentile(75)); if (p.getPercentile(95) < 600) { fail("We expect the 90th to be over 600 to show the extremes but got: " + p.getPercentile(90)); } if (p.getPercentile(99) < 600) { fail("We expect the 99th to be over 600 to show the extremes but got: " + p.getPercentile(99)); } }
@Test public void testPercentileAlgorithm_HighPercentile() { PercentileSnapshot p = getPercentileForValues(1, 2, 3); Assert.assertEquals(2, p.getPercentile(50)); Assert.assertEquals(3, p.getPercentile(75)); }
@Test public void testPercentileAlgorithm_LowPercentile() { PercentileSnapshot p = getPercentileForValues(1, 2); Assert.assertEquals(1, p.getPercentile(25)); Assert.assertEquals(2, p.getPercentile(75)); }
@Test public void testPercentileAlgorithm_Percentiles() { PercentileSnapshot p = getPercentileForValues(10, 30, 20, 40); Assert.assertEquals(22, p.getPercentile(30), 1.0e-5); Assert.assertEquals(20, p.getPercentile(25), 1.0e-5); Assert.assertEquals(40, p.getPercentile(75), 1.0e-5); Assert.assertEquals(30, p.getPercentile(50), 1.0e-5); Assert.assertEquals(10, p.getPercentile(-1)); Assert.assertEquals(40, p.getPercentile(101)); }
@Test public void testPercentileAlgorithm_NISTExample() { PercentileSnapshot p = getPercentileForValues(951772, 951567, 951937, 951959, 951442, 950610, 951591, 951195, 951772, 950925, 951990, 951682); Assert.assertEquals(951983, p.getPercentile(90)); Assert.assertEquals(951990, p.getPercentile(100)); }