### Question:
VegasLimit extends AbstractLimit { public static Builder newBuilder() { return new Builder(); } private  VegasLimit(Builder builder); static Builder newBuilder(); static VegasLimit newDefault(); @Override String toString();  }### Answer:
@Test public void decreaseWithoutSmoothing() { VegasLimit limit = VegasLimit.newBuilder() .decrease(current -> current / 2) .initialLimit(100) .maxConcurrency(200) .build(); limit.onSample(0, TimeUnit.MILLISECONDS.toNanos(10), 100, false); Assert.assertEquals(100, limit.getLimit()); limit.onSample(0, TimeUnit.MILLISECONDS.toNanos(20), 100, false); Assert.assertEquals(50, limit.getLimit()); limit.onSample(0, TimeUnit.MILLISECONDS.toNanos(20), 100, false); Assert.assertEquals(25, limit.getLimit()); }
@Test public void largeLimitIncrease() { VegasLimit limit = VegasLimit.newBuilder() .initialLimit(10000) .maxConcurrency(20000) .build(); limit.onSample(0, TimeUnit.SECONDS.toNanos(10), 5000, false); Assert.assertEquals(10000, limit.getLimit()); limit.onSample(0, TimeUnit.SECONDS.toNanos(10), 6000, false); Assert.assertEquals(10024, limit.getLimit()); }
@Test public void decreaseSmoothing() { VegasLimit limit = VegasLimit.newBuilder() .decrease(current -> current / 2) .smoothing(0.5) .initialLimit(100) .maxConcurrency(200) .build(); limit.onSample(0, TimeUnit.MILLISECONDS.toNanos(10), 100, false); Assert.assertEquals(100, limit.getLimit()); limit.onSample(0, TimeUnit.MILLISECONDS.toNanos(20), 100, false); Assert.assertEquals(75, limit.getLimit()); limit.onSample(0, TimeUnit.MILLISECONDS.toNanos(20), 100, false); Assert.assertEquals(56, limit.getLimit()); }