@Test public void testSharedBucket() { TokenBucketAdmissionController controller = new TokenBucketAdmissionController( Collections.singletonList(SHARED_ANY_CONFIGURATION), titusRuntime ); AdmissionControllerRequest request = AdmissionControllerRequest.newBuilder() .withCallerId("any") .withEndpointName("any") .build(); int limit = SHARED_ANY_CONFIGURATION.getCapacity() + SHARED_ANY_CONFIGURATION.getRefillRateInSec() + 1; int stoppedAt = 0; while (stoppedAt < limit) { AdmissionControllerResponse response = controller.apply(request); if (!response.isAllowed()) { break; } stoppedAt++; } assertThat(stoppedAt).isGreaterThanOrEqualTo(SHARED_ANY_CONFIGURATION.getCapacity()); assertThat(stoppedAt).isLessThan(limit); }
@Override public AdmissionControllerResponse apply(AdmissionControllerRequest request) { return findTokenBucket(request).map(this::consume).orElse(DEFAULT_OK); }
TokenBucketAdmissionController implements AdmissionController { @Override public AdmissionControllerResponse apply(AdmissionControllerRequest request) { return findTokenBucket(request).map(this::consume).orElse(DEFAULT_OK); } }
TokenBucketAdmissionController implements AdmissionController { @Override public AdmissionControllerResponse apply(AdmissionControllerRequest request) { return findTokenBucket(request).map(this::consume).orElse(DEFAULT_OK); } TokenBucketAdmissionController(List<TokenBucketConfiguration> tokenBucketConfigurations,
                                          TitusRuntime titusRuntime); }
TokenBucketAdmissionController implements AdmissionController { @Override public AdmissionControllerResponse apply(AdmissionControllerRequest request) { return findTokenBucket(request).map(this::consume).orElse(DEFAULT_OK); } TokenBucketAdmissionController(List<TokenBucketConfiguration> tokenBucketConfigurations,
                                          TitusRuntime titusRuntime); @Override AdmissionControllerResponse apply(AdmissionControllerRequest request); }
TokenBucketAdmissionController implements AdmissionController { @Override public AdmissionControllerResponse apply(AdmissionControllerRequest request) { return findTokenBucket(request).map(this::consume).orElse(DEFAULT_OK); } TokenBucketAdmissionController(List<TokenBucketConfiguration> tokenBucketConfigurations,
                                          TitusRuntime titusRuntime); @Override AdmissionControllerResponse apply(AdmissionControllerRequest request);  }