HystrixRollingNumber { public void increment(HystrixRollingNumberEvent type) { getCurrentBucket().getAdder(type).increment(); } @Deprecated  HystrixRollingNumber(HystrixProperty<Integer> timeInMilliseconds, HystrixProperty<Integer> numberOfBuckets);  HystrixRollingNumber(int timeInMilliseconds, int numberOfBuckets);   HystrixRollingNumber(Time time, int timeInMilliseconds, int numberOfBuckets); void increment(HystrixRollingNumberEvent type); void add(HystrixRollingNumberEvent type, long value); void updateRollingMax(HystrixRollingNumberEvent type, long value); void reset(); long getCumulativeSum(HystrixRollingNumberEvent type); long getRollingSum(HystrixRollingNumberEvent type); long getValueOfLatestBucket(HystrixRollingNumberEvent type); long[] getValues(HystrixRollingNumberEvent type); long getRollingMaxValue(HystrixRollingNumberEvent type);  }
@Test public void testCreatesBuckets() { MockedTime time = new MockedTime(); try { HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10); assertEquals(200, counter.timeInMilliseconds); assertEquals(10, counter.numberOfBuckets); assertEquals(20, counter.bucketSizeInMillseconds); assertEquals(0, counter.buckets.size()); for (int i = 0; i < counter.numberOfBuckets; i++) { counter.increment(HystrixRollingNumberEvent.SUCCESS); time.increment(counter.bucketSizeInMillseconds); } assertEquals(10, counter.buckets.size()); counter.increment(HystrixRollingNumberEvent.SUCCESS); assertEquals(10, counter.buckets.size()); } catch (Exception e) { e.printStackTrace(); fail("Exception: " + e.getMessage()); } }
@Test public void testResetBuckets() { MockedTime time = new MockedTime(); try { HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10); assertEquals(0, counter.buckets.size()); counter.increment(HystrixRollingNumberEvent.SUCCESS); assertEquals(1, counter.buckets.size()); assertEquals(1, counter.buckets.size()); counter.increment(HystrixRollingNumberEvent.SUCCESS); assertEquals(1, counter.buckets.size()); } catch (Exception e) { e.printStackTrace(); fail("Exception: " + e.getMessage()); } }
@Test public void testEmptyBucketsFillIn() { MockedTime time = new MockedTime(); try { HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10); counter.increment(HystrixRollingNumberEvent.SUCCESS); assertEquals(1, counter.buckets.size()); time.increment(counter.bucketSizeInMillseconds * 3); counter.increment(HystrixRollingNumberEvent.SUCCESS); assertEquals(4, counter.buckets.size()); } catch (Exception e) { e.printStackTrace(); fail("Exception: " + e.getMessage()); } }
@Test public void testIncrementInSingleBucket() { MockedTime time = new MockedTime(); try { HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10); counter.increment(HystrixRollingNumberEvent.SUCCESS); counter.increment(HystrixRollingNumberEvent.SUCCESS); counter.increment(HystrixRollingNumberEvent.SUCCESS); counter.increment(HystrixRollingNumberEvent.SUCCESS); counter.increment(HystrixRollingNumberEvent.FAILURE); counter.increment(HystrixRollingNumberEvent.FAILURE); counter.increment(HystrixRollingNumberEvent.TIMEOUT); assertEquals(1, counter.buckets.size()); assertEquals(4, counter.buckets.getLast().getAdder(HystrixRollingNumberEvent.SUCCESS).sum()); assertEquals(2, counter.buckets.getLast().getAdder(HystrixRollingNumberEvent.FAILURE).sum()); assertEquals(1, counter.buckets.getLast().getAdder(HystrixRollingNumberEvent.TIMEOUT).sum()); } catch (Exception e) { e.printStackTrace(); fail("Exception: " + e.getMessage()); } }