@Test public void testSlidingWindowMetrics() { FixedSizeSlidingWindowMetrics metrics = new FixedSizeSlidingWindowMetrics(4); Snapshot snapshot = metrics.record(100, TimeUnit.MILLISECONDS, Metrics.Outcome.ERROR); assertThat(snapshot.getTotalNumberOfCalls()).isEqualTo(1); assertThat(snapshot.getNumberOfSuccessfulCalls()).isEqualTo(0); assertThat(snapshot.getNumberOfFailedCalls()).isEqualTo(1); assertThat(snapshot.getTotalDuration().toMillis()).isEqualTo(100); assertThat(snapshot.getAverageDuration().toMillis()).isEqualTo(100); assertThat(snapshot.getFailureRate()).isEqualTo(100); snapshot = metrics.record(100, TimeUnit.MILLISECONDS, Metrics.Outcome.SUCCESS); assertThat(snapshot.getTotalNumberOfCalls()).isEqualTo(2); assertThat(snapshot.getNumberOfSuccessfulCalls()).isEqualTo(1); assertThat(snapshot.getNumberOfFailedCalls()).isEqualTo(1); assertThat(snapshot.getTotalDuration().toMillis()).isEqualTo(200); assertThat(snapshot.getAverageDuration().toMillis()).isEqualTo(100); assertThat(snapshot.getFailureRate()).isEqualTo(50); snapshot = metrics.record(100, TimeUnit.MILLISECONDS, Metrics.Outcome.SUCCESS); assertThat(snapshot.getTotalNumberOfCalls()).isEqualTo(3); assertThat(snapshot.getNumberOfSuccessfulCalls()).isEqualTo(2); assertThat(snapshot.getNumberOfFailedCalls()).isEqualTo(1); assertThat(snapshot.getTotalDuration().toMillis()).isEqualTo(300); assertThat(snapshot.getAverageDuration().toMillis()).isEqualTo(100); assertThat(snapshot.getFailureRate()).isEqualTo(33.333332f); snapshot = metrics.record(100, TimeUnit.MILLISECONDS, Metrics.Outcome.SUCCESS); assertThat(snapshot.getTotalNumberOfCalls()).isEqualTo(4); assertThat(snapshot.getNumberOfSuccessfulCalls()).isEqualTo(3); assertThat(snapshot.getNumberOfFailedCalls()).isEqualTo(1); assertThat(snapshot.getTotalDuration().toMillis()).isEqualTo(400); assertThat(snapshot.getAverageDuration().toMillis()).isEqualTo(100); assertThat(snapshot.getFailureRate()).isEqualTo(25); snapshot = metrics.record(100, TimeUnit.MILLISECONDS, Metrics.Outcome.SUCCESS); assertThat(snapshot.getTotalNumberOfCalls()).isEqualTo(4); assertThat(snapshot.getNumberOfSuccessfulCalls()).isEqualTo(4); assertThat(snapshot.getNumberOfFailedCalls()).isEqualTo(0); assertThat(snapshot.getTotalDuration().toMillis()).isEqualTo(400); assertThat(snapshot.getAverageDuration().toMillis()).isEqualTo(100); assertThat(snapshot.getFailureRate()).isEqualTo(0); }
@Override public synchronized Snapshot record(long duration, TimeUnit durationUnit, Outcome outcome) { totalAggregation.record(duration, durationUnit, outcome); moveWindowByOne().record(duration, durationUnit, outcome); return new SnapshotImpl(totalAggregation); }
FixedSizeSlidingWindowMetrics implements Metrics { @Override public synchronized Snapshot record(long duration, TimeUnit durationUnit, Outcome outcome) { totalAggregation.record(duration, durationUnit, outcome); moveWindowByOne().record(duration, durationUnit, outcome); return new SnapshotImpl(totalAggregation); } }
FixedSizeSlidingWindowMetrics implements Metrics { @Override public synchronized Snapshot record(long duration, TimeUnit durationUnit, Outcome outcome) { totalAggregation.record(duration, durationUnit, outcome); moveWindowByOne().record(duration, durationUnit, outcome); return new SnapshotImpl(totalAggregation); } FixedSizeSlidingWindowMetrics(int windowSize); }
FixedSizeSlidingWindowMetrics implements Metrics { @Override public synchronized Snapshot record(long duration, TimeUnit durationUnit, Outcome outcome) { totalAggregation.record(duration, durationUnit, outcome); moveWindowByOne().record(duration, durationUnit, outcome); return new SnapshotImpl(totalAggregation); } FixedSizeSlidingWindowMetrics(int windowSize); @Override synchronized Snapshot record(long duration, TimeUnit durationUnit, Outcome outcome); synchronized Snapshot getSnapshot(); }
FixedSizeSlidingWindowMetrics implements Metrics { @Override public synchronized Snapshot record(long duration, TimeUnit durationUnit, Outcome outcome) { totalAggregation.record(duration, durationUnit, outcome); moveWindowByOne().record(duration, durationUnit, outcome); return new SnapshotImpl(totalAggregation); } FixedSizeSlidingWindowMetrics(int windowSize); @Override synchronized Snapshot record(long duration, TimeUnit durationUnit, Outcome outcome); synchronized Snapshot getSnapshot();  }