Skip to content

Commit

Permalink
Implement missing overrides in NoopDistributionSummary (#1159)
Browse files Browse the repository at this point in the history
Implement overrides for batchUpdater and record in NoopDistributionSummary
that do nothing and avoid allocating.
  • Loading branch information
kilink authored Sep 16, 2024
1 parent bf5a849 commit 6c60028
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ enum NoopDistributionSummary implements DistributionSummary {
@Override public void record(long amount) {
}

@Override public void record(long[] amounts, int n) {
}

@Override public Iterable<Measurement> measure() {
return Collections.emptyList();
}
Expand All @@ -45,4 +48,22 @@ enum NoopDistributionSummary implements DistributionSummary {
@Override public long totalAmount() {
return 0L;
}

@Override
public BatchUpdater batchUpdater(int batchSize) {
return NoopBatchUpdater.INSTANCE;
}

private enum NoopBatchUpdater implements BatchUpdater {
INSTANCE;

@Override public void flush() {
}

@Override public void record(long amount) {
}

@Override public void close() {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ public void testMeasure() {
NoopDistributionSummary t = NoopDistributionSummary.INSTANCE;
t.record(42);
Assertions.assertFalse(t.measure().iterator().hasNext());
t.record(new long[] { 1L, 2L, 3L }, 3);
Assertions.assertFalse(t.measure().iterator().hasNext());
}

@Test
public void testBatchUpdate() throws Exception {
NoopDistributionSummary t = NoopDistributionSummary.INSTANCE;
try (DistributionSummary.BatchUpdater batchUpdater = t.batchUpdater(10)) {
for (long i = 0; i < 100; i++) {
batchUpdater.record(i);
}
}
Assertions.assertFalse(t.measure().iterator().hasNext());
}
}

0 comments on commit 6c60028

Please sign in to comment.