MetricsQueue { @JsonProperty("summary") public RequestMetricSummary getTotals() { MutableLong count = new MutableLong(0); MutableDouble averageTime = new MutableDouble(0); MutableLong intolerableCount = new MutableLong(0); MutableDouble averageIntolerableTime = new MutableDouble(0); MutableLong databaseQueryCount = new MutableLong(0); MutableDouble averageDatabaseQueryTime = new MutableDouble(0); MutableLong databaseIntolerableQueryCount = new MutableLong(0); MutableDouble averageDatabaseIntolerableQueryTime = new MutableDouble(0); statistics.forEach((key, summary) -> { averageTime.set(addAverages(count.get(), averageTime.get(), summary.getCount(), summary.getAverageTime()) ); count.add(summary.getCount()); averageIntolerableTime.set(addAverages(intolerableCount.get(), averageIntolerableTime.get(), summary.getIntolerableCount(), summary.getAverageIntolerableTime()) ); intolerableCount.add(summary.getIntolerableCount()); averageDatabaseQueryTime.set(addAverages(databaseQueryCount.get(), averageDatabaseQueryTime.get(), summary.getDatabaseQueryCount(), summary.getAverageDatabaseQueryTime() ) ); databaseQueryCount.add(summary.getDatabaseQueryCount()); averageDatabaseIntolerableQueryTime.set(addAverages(databaseIntolerableQueryCount.get(), averageDatabaseIntolerableQueryTime.get(), summary.getDatabaseIntolerableQueryCount(), summary.getAverageDatabaseIntolerableQueryTime() ) ); databaseIntolerableQueryCount.add(summary.getDatabaseIntolerableQueryCount()); }); return new RequestMetricSummary(count.get(), averageTime.get(), intolerableCount.get(), averageIntolerableTime.get(), databaseQueryCount.get(), averageDatabaseQueryTime.get(), databaseIntolerableQueryCount.get(), averageDatabaseIntolerableQueryTime.get()); } MetricsQueue(); @JsonCreator  MetricsQueue(@JsonProperty("lastRequests") ConcurrentLinkedDeque<RequestMetric> queue,
                        @JsonProperty("detailed") Map<StatusCodeGroup, RequestMetricSummary> statistics); boolean offer(RequestMetric metric); Map<StatusCodeGroup, RequestMetricSummary> getDetailed(); ConcurrentLinkedDeque<RequestMetric> getLastRequests(); @JsonProperty("summary") RequestMetricSummary getTotals(); static final int MAX_ENTRIES; }
@Test void totals() { RequestMetricSummary summary = queue.getTotals(); assertNotNull(summary); assertEquals(3, summary.getCount()); assertEquals(1, summary.getIntolerableCount()); assertEquals(((double)(MAX_TIME+3+5)) / 3.0, summary.getAverageTime(), DELTA); assertEquals((double)MAX_TIME+1, summary.getAverageIntolerableTime(), DELTA); assertEquals(3, summary.getDatabaseQueryCount()); assertEquals(3, summary.getAverageDatabaseQueryTime(), DELTA); assertEquals(2, summary.getDatabaseIntolerableQueryCount()); assertEquals(3.5, summary.getAverageDatabaseIntolerableQueryTime(), DELTA); }