SentinelLeakyBucket extends AbstractStartStoppable implements LeakyBucket { @Override public int references() { return origin.references(); } SentinelLeakyBucket(ConsoleConfig config, ScheduledExecutorService scheduled); @Override boolean tryAcquire(); @Override void release(); void delayRelease(long time, TimeUnit timeUnit); @Override void resize(int newSize); @Override int references(); @Override int getTotalSize(); static int PERIODIC_MILLI; }
@Test public void testReferences() { when(consoleConfig.isSentinelRateLimitOpen()).thenReturn(true); when(consoleConfig.getSentinelRateLimitSize()).thenReturn(3); leakyBucket = new SentinelLeakyBucket(consoleConfig, scheduled); leakyBucket.tryAcquire(); Assert.assertEquals(2, leakyBucket.references()); leakyBucket.tryAcquire(); Assert.assertEquals(1, leakyBucket.references()); }