@Test public void quotaTest() throws Exception { Properties props = new Properties(); props.setProperty(FrontendConfig.REST_REQUEST_QUOTA_STRING, "{\"PUT\": \"20\",\"GET\": \"20\",\"POST\": \"20\",\"HEAD\": \"20\",\"OPTIONS\": \"20\",\"DELETE\": \"20\"}"); FrontendConfig frontendConfig = new FrontendConfig(new VerifiableProperties(props)); MockClock clock = new MockClock(); QuotaManager quotaManager = new QuotaManager(createQuotaMock(frontendConfig, clock)); for (int i = 0; i < 100; i++) { for (RestMethod restMethod : RestMethod.values()) { RestRequest restRequest = createRestRequest(restMethod, "http: Assert.assertFalse("Should not throttle", quotaManager.shouldThrottle(restRequest)); } } clock.tick(5); for (RestMethod restMethod : RestMethod.values()) { RestRequest restRequest = createRestRequest(restMethod, "http: if (restMethod == RestMethod.UNKNOWN) { Assert.assertFalse("Should not throttle.", quotaManager.shouldThrottle(restRequest)); } else { Assert.assertTrue("Should throttle", quotaManager.shouldThrottle(restRequest)); } } clock.tick(5); for (RestMethod restMethod : RestMethod.values()) { RestRequest restRequest = createRestRequest(restMethod, "http: Assert.assertFalse("Should not throttle", quotaManager.shouldThrottle(restRequest)); } }
public boolean shouldThrottle(RestRequest restRequest) { RejectThrottler throttler = quotaMap.get(restRequest.getRestMethod()); return throttler != null && throttler.shouldThrottle(1); }
QuotaManager { public boolean shouldThrottle(RestRequest restRequest) { RejectThrottler throttler = quotaMap.get(restRequest.getRestMethod()); return throttler != null && throttler.shouldThrottle(1); } }
QuotaManager { public boolean shouldThrottle(RestRequest restRequest) { RejectThrottler throttler = quotaMap.get(restRequest.getRestMethod()); return throttler != null && throttler.shouldThrottle(1); } QuotaManager(FrontendConfig frontendConfig);  QuotaManager(Map<RestMethod, RejectThrottler> quotaMap); }
QuotaManager { public boolean shouldThrottle(RestRequest restRequest) { RejectThrottler throttler = quotaMap.get(restRequest.getRestMethod()); return throttler != null && throttler.shouldThrottle(1); } QuotaManager(FrontendConfig frontendConfig);  QuotaManager(Map<RestMethod, RejectThrottler> quotaMap); boolean shouldThrottle(RestRequest restRequest); }
QuotaManager { public boolean shouldThrottle(RestRequest restRequest) { RejectThrottler throttler = quotaMap.get(restRequest.getRestMethod()); return throttler != null && throttler.shouldThrottle(1); } QuotaManager(FrontendConfig frontendConfig);  QuotaManager(Map<RestMethod, RejectThrottler> quotaMap); boolean shouldThrottle(RestRequest restRequest);  }