RateLimitingSampler implements Sampler<T> { static <T> Sampler<T> create(int samplesPerSecond) { checkArgument(samplesPerSecond >= 0, "samplesPerSecond: %s (expected: >= 0)", samplesPerSecond); if (samplesPerSecond == 0) { return Sampler.never(); } return new RateLimitingSampler<>(samplesPerSecond); } RateLimitingSampler(int samplesPerSecond); @Override boolean isSampled(Object ignored); @Override String toString();  }
@Test public void testRateLimit_cantBeNegative() { assertThatThrownBy(() -> RateLimitingSampler.create(-1)).isInstanceOf(IllegalArgumentException.class); }
@Test public void testNeverSampledSampler() { assertThat(RateLimitingSampler.create(0)).isSameAs(Sampler.never()); }