/
StepMeterRegistryTests.java
66 lines (52 loc) · 1.46 KB
/
StepMeterRegistryTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package learningtest.io.micrometer.core.instrument.step;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.step.StepMeterRegistry;
import io.micrometer.core.instrument.step.StepRegistryConfig;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link StepMeterRegistry}.
*
* @author Johnny Lim
*/
class StepMeterRegistryTests {
private static final int STEP = 5;
private final StepRegistryConfig config = new StepRegistryConfig() {
@Override
public String prefix() {
return null;
}
@Override
public String get(String key) {
return null;
}
@Override
public Duration step() {
return Duration.ofSeconds(STEP);
}
};
private final MeterRegistry registry = new StepMeterRegistry(this.config, Clock.SYSTEM) {
@Override
protected void publish() {
}
@Override
protected TimeUnit getBaseTimeUnit() {
return TimeUnit.MILLISECONDS;
}
};
@Test
void test() throws InterruptedException {
Counter counter = this.registry.counter("test");
counter.increment();
counter.increment();
assertThat(counter.count()).isEqualTo(0);
TimeUnit.SECONDS.sleep(STEP);
assertThat(counter.count()).isEqualTo(2);
TimeUnit.SECONDS.sleep(STEP);
assertThat(counter.count()).isEqualTo(0);
}
}