@Test public void testNotSharedBucket() { TokenBucketAdmissionController controller = new TokenBucketAdmissionController( Collections.singletonList(NOT_SHARED_CONFIGURATION), titusRuntime ); AdmissionControllerRequest user1Request = AdmissionControllerRequest.newBuilder() .withCallerId("myUser1") .withEndpointName("any") .build(); AdmissionControllerRequest user2Request = AdmissionControllerRequest.newBuilder() .withCallerId("myUser2") .withEndpointName("any") .build(); int limit = NOT_SHARED_CONFIGURATION.getCapacity() + NOT_SHARED_CONFIGURATION.getRefillRateInSec() + 1; int stoppedAt = 0; while (stoppedAt < limit) { AdmissionControllerResponse response1 = controller.apply(user1Request); AdmissionControllerResponse response2 = controller.apply(user2Request); if (response1.isAllowed() && response2.isAllowed()) { stoppedAt++; } else { break; } } assertThat(stoppedAt).isGreaterThanOrEqualTo(NOT_SHARED_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);  }