PerformanceMonitor implements ServiceWrapper { public <T> T invoke(final Callable<T> c) throws Exception { final LatencyTracker latencyTracker = new LatencyTracker(); try { T result = requestCounter.invoke(new Callable<T>() { public T call() throws Exception { return latencyTracker.invoke(c); } }); recordSuccess(latencyTracker); return result; } catch (Exception e) { recordFailure(latencyTracker); if (WRAP_MSG.equals(e.getMessage())) { throw (Exception)e.getCause(); } else { throw e; } } } PerformanceMonitor(); T invoke(final Callable<T> c); void invoke(final Runnable r); T invoke(final Runnable r, T result); double getAverageSuccessLatencyLastMinute(); double getAverageSuccessLatencyLastHour(); double getAverageSuccessLatencyLastDay(); double getAverageFailureLatencyLastMinute(); double getAverageFailureLatencyLastHour(); double getAverageFailureLatencyLastDay(); double getTotalRequestsPerSecondLastMinute(); double getSuccessRequestsPerSecondLastMinute(); double getFailureRequestsPerSecondLastMinute(); double getTotalRequestsPerSecondLastHour(); double getSuccessRequestsPerSecondLastHour(); double getFailureRequestsPerSecondLastHour(); double getTotalRequestsPerSecondLastDay(); double getSuccessRequestsPerSecondLastDay(); double getFailureRequestsPerSecondLastDay(); double getTotalRequestsPerSecondLifetime(); double getSuccessRequestsPerSecondLifetime(); double getFailureRequestsPerSecondLifetime(); RequestCounter getRequestCounter(); long getRequestCount(); long getSuccessCount(); long getFailureCount(); long getMedianPercentileSuccessLatencyLifetime(); long get95thPercentileSuccessLatencyLifetime(); long get99thPercentileSuccessLatencyLifetime(); long getMaxSuccessLatencyLifetime(); long getMedianPercentileSuccessLatencyLastMinute(); long get95thPercentileSuccessLatencyLastMinute(); long get99thPercentileSuccessLatencyLastMinute(); long getMedianPercentileSuccessfulLatencyLastHour(); long get95thPercentileSuccessLatencyLastHour(); long get99thPercentileSuccessLatencyLastHour(); long getMedianPercentileSuccessLatencyLastDay(); long get95thPercentileSuccessLatencyLastDay(); long get99thPercentileSuccessLatencyLastDay(); long getMedianPercentileFailureLatencyLifetime(); long get95thPercentileFailureLatencyLifetime(); long get99thPercentileFailureLatencyLifetime(); long getMaxFailureLatencyLifetime(); long getMedianPercentileFailureLatencyLastMinute(); long get95thPercentileFailureLatencyLastMinute(); long get99thPercentileFailureLatencyLastMinute(); long getMedianPercentileFailureLatencyLastHour(); long get95thPercentileFailureLatencyLastHour(); long get99thPercentileFailureLatencyLastHour(); long getMedianPercentileFailureLatencyLastDay(); long get95thPercentileFailureLatencyLastDay(); long get99thPercentileFailureLatencyLastDay();  }
@Test public void testRunnableWithResultReturnsResultOnSuccess() throws Exception { PerformanceMonitor perfMon = new PerformanceMonitor(); Integer returnResult = 21; Integer callResult = perfMon.invoke(new ConstantSuccessPerformer(5), returnResult); assertEquals(returnResult, callResult); }
@Test(expected=Exception.class) public void testRunnableWithResultReturnsExceptionOnFailure() throws Exception { PerformanceMonitor perfMon = new PerformanceMonitor(); Integer returnResult = 21; perfMon.invoke(new OccasionalExceptionPerformer(1), returnResult); }