Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
m-nagarajan committed Sep 12, 2024
1 parent d818de7 commit a0f265e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/tehuti/metrics/stats/Count.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public double measure(MetricConfig config, long now) {
return this.count;
}

public void reset() {
void reset() {
this.count = 0;
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/tehuti/metrics/stats/Total.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public double measure(MetricConfig config, long now) {
return this.total;
}

public void reset() {
void reset() {
this.total = 0.0;
}

Expand Down
8 changes: 7 additions & 1 deletion src/test/java/io/tehuti/metrics/MetricsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ public void testSimpleStats() throws Exception {
s.add("test.rate", new Rate(TimeUnit.SECONDS));
s.add("test.occurrence-rate", new OccurrenceRate());
s.add("test.count", new Count());
s.add("test.SimpleSampledCount", new SimpleSampledCount());
s.add(new Percentiles(100, -100, 100, BucketSizing.CONSTANT,
new Percentile("test.median", 50.0),
new Percentile("test.perc99_9", 99.9)));

Sensor s2 = metricsRepository.sensor("test.sensor2");
s2.add("s2.total", new Total());
s2.add("s2.SimpleSampledTotal", new SimpleSampledTotal());
s2.record(5.0);

for (int i = 0; i < 10; i++)
Expand All @@ -62,13 +64,17 @@ public void testSimpleStats() throws Exception {
// pretend 30 seconds passed...
time.sleep(config.timeWindowMs());

assertEquals("s2 reflects the constant value", 5.0, metricsRepository.getMetric("s2.total").value(), EPS);
assertEquals("s2 total reflects the constant value", 5.0, metricsRepository.getMetric("s2.total").value(), EPS);
assertEquals("s2 SimpleSampledTotal reflects the constant value", 5.0, metricsRepository.getMetric("s2.SimpleSampledTotal").value(), EPS);
assertEquals("s2 SimpleSampledTotal = 0 as its reset after last fetch", 0.0, metricsRepository.getMetric("s2.SimpleSampledTotal").value(), EPS);
assertEquals("Avg(0...9) = 4.5", 4.5, metricsRepository.getMetric("test.avg").value(), EPS);
assertEquals("Max(0...9) = 9", 9.0, metricsRepository.getMetric("test.max").value(), EPS);
assertEquals("Min(0...9) = 0", 0.0, metricsRepository.getMetric("test.min").value(), EPS);
assertEquals("Rate(0...9) = 1.5", 1.5, metricsRepository.getMetric("test.rate").value(), EPS);
assertEquals("OccurrenceRate(0...9) = 0.33333333333", 0.33333333333, metricsRepository.getMetric("test.occurrence-rate").value(), EPS);
assertEquals("Count(0...9) = 10", 10.0, metricsRepository.getMetric("test.count").value(), EPS);
assertEquals("SimpleSampledCount(0...9) = 10", 10.0, metricsRepository.getMetric("test.SimpleSampledCount").value(), EPS);
assertEquals("SimpleSampledCount = 0 as its reset after last fetch", 0.0, metricsRepository.getMetric("test.SimpleSampledCount").value(), EPS);
}

@Test
Expand Down

0 comments on commit a0f265e

Please sign in to comment.