@Test public void testMetrics() throws Exception { ThrottlingGuiceServletConfig guiceServletConfig = new ThrottlingGuiceServletConfig(); guiceServletConfig.initialize(ConfigFactory.empty()); Injector injector = guiceServletConfig.getInjector(); LimiterServerResource limiterServer = injector.getInstance(LimiterServerResource.class); PermitRequest request = new PermitRequest(); request.setPermits(10); request.setResource("myResource"); limiterServer.getSync(new ComplexResourceKey<>(request, new EmptyRecord())); limiterServer.getSync(new ComplexResourceKey<>(request, new EmptyRecord())); limiterServer.getSync(new ComplexResourceKey<>(request, new EmptyRecord())); MetricContext metricContext = limiterServer.metricContext; Timer timer = metricContext.timer(LimiterServerResource.REQUEST_TIMER_NAME); Assert.assertEquals(timer.getCount(), 3); }
public PermitAllocation getSync(ComplexResourceKey<PermitRequest, EmptyRecord> key) { try { FutureCallback<PermitAllocation> callback = new FutureCallback<>(); get(key, callback); return callback.get(); } catch (ExecutionException ee) { Throwable t = ee.getCause(); if (t instanceof RestLiServiceException) { throw (RestLiServiceException) t; } else { throw new RuntimeException(t); } } catch (InterruptedException ie) { throw new RuntimeException(ie); } }
LimiterServerResource extends ComplexKeyResourceAsyncTemplate<PermitRequest, EmptyRecord, PermitAllocation> { public PermitAllocation getSync(ComplexResourceKey<PermitRequest, EmptyRecord> key) { try { FutureCallback<PermitAllocation> callback = new FutureCallback<>(); get(key, callback); return callback.get(); } catch (ExecutionException ee) { Throwable t = ee.getCause(); if (t instanceof RestLiServiceException) { throw (RestLiServiceException) t; } else { throw new RuntimeException(t); } } catch (InterruptedException ie) { throw new RuntimeException(ie); } } }
LimiterServerResource extends ComplexKeyResourceAsyncTemplate<PermitRequest, EmptyRecord, PermitAllocation> { public PermitAllocation getSync(ComplexResourceKey<PermitRequest, EmptyRecord> key) { try { FutureCallback<PermitAllocation> callback = new FutureCallback<>(); get(key, callback); return callback.get(); } catch (ExecutionException ee) { Throwable t = ee.getCause(); if (t instanceof RestLiServiceException) { throw (RestLiServiceException) t; } else { throw new RuntimeException(t); } } catch (InterruptedException ie) { throw new RuntimeException(ie); } }  }
LimiterServerResource extends ComplexKeyResourceAsyncTemplate<PermitRequest, EmptyRecord, PermitAllocation> { public PermitAllocation getSync(ComplexResourceKey<PermitRequest, EmptyRecord> key) { try { FutureCallback<PermitAllocation> callback = new FutureCallback<>(); get(key, callback); return callback.get(); } catch (ExecutionException ee) { Throwable t = ee.getCause(); if (t instanceof RestLiServiceException) { throw (RestLiServiceException) t; } else { throw new RuntimeException(t); } } catch (InterruptedException ie) { throw new RuntimeException(ie); } }  @Override @RestMethod.Get void get(
      ComplexResourceKey<PermitRequest, EmptyRecord> key,
      @CallbackParam final Callback<PermitAllocation> callback); PermitAllocation getSync(ComplexResourceKey<PermitRequest, EmptyRecord> key); }
LimiterServerResource extends ComplexKeyResourceAsyncTemplate<PermitRequest, EmptyRecord, PermitAllocation> { public PermitAllocation getSync(ComplexResourceKey<PermitRequest, EmptyRecord> key) { try { FutureCallback<PermitAllocation> callback = new FutureCallback<>(); get(key, callback); return callback.get(); } catch (ExecutionException ee) { Throwable t = ee.getCause(); if (t instanceof RestLiServiceException) { throw (RestLiServiceException) t; } else { throw new RuntimeException(t); } } catch (InterruptedException ie) { throw new RuntimeException(ie); } }  @Override @RestMethod.Get void get(
      ComplexResourceKey<PermitRequest, EmptyRecord> key,
      @CallbackParam final Callback<PermitAllocation> callback); PermitAllocation getSync(ComplexResourceKey<PermitRequest, EmptyRecord> key); static final long TIMEOUT_MILLIS; static final String BROKER_INJECT_NAME; static final String METRIC_CONTEXT_INJECT_NAME; static final String REQUEST_TIMER_INJECT_NAME; static final String LEADER_FINDER_INJECT_NAME; static final String REQUEST_TIMER_NAME; static final String PERMITS_REQUESTED_METER_NAME; static final String PERMITS_GRANTED_METER_NAME; static final String LIMITER_TIMER_NAME; static final String RESOURCE_ID_TAG; static final String LOCATION_301; }