Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ void preIngest() {
* @param ingestTimeInNanos The time it took to perform the action.
*/
void postIngest(long ingestTimeInNanos) {
ingestCurrent.decrementAndGet();
long current = ingestCurrent.decrementAndGet();
assert current >= 0 : "ingest metric current count double-decremented";
this.ingestTimeInNanos.inc(ingestTimeInNanos);
ingestCount.inc();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,18 @@ public void testIngestTimeInNanos() {
assertThat(1L, equalTo(metric.createStats().getIngestTimeInMillis()));
}

public void testPostIngestDoubleDecrement() {
IngestMetric metric = new IngestMetric();

metric.preIngest();
assertThat(1L, equalTo(metric.createStats().getIngestCurrent()));

metric.postIngest(500000L);
assertThat(0L, equalTo(metric.createStats().getIngestCurrent()));

// the second postIngest triggers an assertion error
expectThrows(AssertionError.class, () -> metric.postIngest(500000L));
assertThat(-1L, equalTo(metric.createStats().getIngestCurrent()));
}

}