ActionLog { public int track(String operation, long elapsed, int readEntries, int writeEntries) { PerformanceStat stat = performanceStats.computeIfAbsent(operation, key -> new PerformanceStat()); stat.count += 1; stat.totalElapsed += elapsed; stat.readEntries += readEntries; stat.writeEntries += writeEntries; return stat.count; } ActionLog(String message, String id); long elapsed(); String errorCode(); void context(String key, Object... values); void stat(String key, double value); int track(String operation, long elapsed, int readEntries, int writeEntries); String correlationId(); void action(String action); final String id; final Map<String, List<String>> context; final Map<String, Double> stats; final Instant date; public boolean trace; public String action; public List<String> correlationIds; public List<String> clients; public List<String> refIds; public boolean suppressSlowSQLWarning; }
@Test void track() { assertThat(log.track("db", 1000, 1, 0)).isEqualTo(1); PerformanceStat stat = log.performanceStats.get("db"); assertThat(stat.count).isEqualTo(1); assertThat(stat.totalElapsed).isEqualTo(1000); assertThat(stat.readEntries).isEqualTo(1); assertThat(stat.writeEntries).isEqualTo(0); assertThat(log.track("db", 1000, 1, 1)).isEqualTo(2); stat = log.performanceStats.get("db"); assertThat(stat.count).isEqualTo(2); assertThat(stat.totalElapsed).isEqualTo(2000); assertThat(stat.readEntries).isEqualTo(2); assertThat(stat.writeEntries).isEqualTo(1); assertThat(log.track("http", 3000, 0, 0)).isEqualTo(1); stat = log.performanceStats.get("http"); assertThat(stat.count).isEqualTo(1); assertThat(stat.totalElapsed).isEqualTo(3000); assertThat(stat.readEntries).isZero(); assertThat(stat.writeEntries).isZero(); }