@Test void attemptZero() { Ratelimiter noRatelimiter = new GuavaCacheRatelimiter(0, TimeUnit.MILLISECONDS); assertTrue(noRatelimiter.attempt(InetAddress.getLoopbackAddress())); assertTrue(noRatelimiter.attempt(InetAddress.getLoopbackAddress())); }
@Override public boolean attempt(InetAddress address) { Preconditions.checkNotNull(address, "address"); long expectedNewValue = System.nanoTime() + timeoutNanos; long last; try { last = expiringCache.get(address, () -> expectedNewValue); } catch (ExecutionException e) { throw new AssertionError(e); } return expectedNewValue == last; }
GuavaCacheRatelimiter implements Ratelimiter { @Override public boolean attempt(InetAddress address) { Preconditions.checkNotNull(address, "address"); long expectedNewValue = System.nanoTime() + timeoutNanos; long last; try { last = expiringCache.get(address, () -> expectedNewValue); } catch (ExecutionException e) { throw new AssertionError(e); } return expectedNewValue == last; } }
GuavaCacheRatelimiter implements Ratelimiter { @Override public boolean attempt(InetAddress address) { Preconditions.checkNotNull(address, "address"); long expectedNewValue = System.nanoTime() + timeoutNanos; long last; try { last = expiringCache.get(address, () -> expectedNewValue); } catch (ExecutionException e) { throw new AssertionError(e); } return expectedNewValue == last; } GuavaCacheRatelimiter(long time, TimeUnit unit); @VisibleForTesting  GuavaCacheRatelimiter(long time, TimeUnit unit, Ticker ticker); }
GuavaCacheRatelimiter implements Ratelimiter { @Override public boolean attempt(InetAddress address) { Preconditions.checkNotNull(address, "address"); long expectedNewValue = System.nanoTime() + timeoutNanos; long last; try { last = expiringCache.get(address, () -> expectedNewValue); } catch (ExecutionException e) { throw new AssertionError(e); } return expectedNewValue == last; } GuavaCacheRatelimiter(long time, TimeUnit unit); @VisibleForTesting  GuavaCacheRatelimiter(long time, TimeUnit unit, Ticker ticker); @Override boolean attempt(InetAddress address); }
GuavaCacheRatelimiter implements Ratelimiter { @Override public boolean attempt(InetAddress address) { Preconditions.checkNotNull(address, "address"); long expectedNewValue = System.nanoTime() + timeoutNanos; long last; try { last = expiringCache.get(address, () -> expectedNewValue); } catch (ExecutionException e) { throw new AssertionError(e); } return expectedNewValue == last; } GuavaCacheRatelimiter(long time, TimeUnit unit); @VisibleForTesting  GuavaCacheRatelimiter(long time, TimeUnit unit, Ticker ticker); @Override boolean attempt(InetAddress address);  }