RateControl { double ratePerNano(int rate, TimeUnit unit) { return rate / (double) unit.toNanos(1); } RateControl(int maxEntries); void config(String group, int maxPermits, int fillRate, TimeUnit unit); void validateRate(String group, String clientIP); public Map<String, RateConfig> config; }
@Test void ratePerNano() { RateControl limiter = new RateControl(1); assertThat(limiter.ratePerNano(100, TimeUnit.MICROSECONDS)).isEqualTo(0.1); assertThat(limiter.ratePerNano(1, TimeUnit.SECONDS)).isEqualTo(0.000000001); assertThat(limiter.ratePerNano(100, TimeUnit.NANOSECONDS)).isEqualTo(100); }