|
15 | 15 | */
|
16 | 16 | package com.netflix.servo.monitor;
|
17 | 17 |
|
| 18 | +import com.netflix.servo.DefaultMonitorRegistry; |
18 | 19 | import com.netflix.servo.SpectatorContext;
|
19 | 20 | import com.netflix.servo.annotations.DataSourceType;
|
20 | 21 | import com.netflix.servo.annotations.Monitor;
|
21 | 22 | import com.netflix.servo.stats.StatsConfig;
|
| 23 | +import com.netflix.servo.tag.BasicTagList; |
| 24 | +import com.netflix.servo.tag.TagList; |
22 | 25 | import com.netflix.servo.util.Clock;
|
| 26 | +import com.netflix.servo.util.ManualClock; |
23 | 27 | import com.netflix.spectator.api.DefaultRegistry;
|
24 | 28 | import com.netflix.spectator.api.Id;
|
25 | 29 | import com.netflix.spectator.api.Registry;
|
|
31 | 35 | import java.util.concurrent.TimeUnit;
|
32 | 36 |
|
33 | 37 | import static org.testng.Assert.assertEquals;
|
34 |
| -import static org.testng.Assert.assertFalse; |
35 |
| -import static org.testng.Assert.assertNotEquals; |
36 |
| -import static org.testng.Assert.assertNotNull; |
37 |
| -import static org.testng.Assert.assertTrue; |
38 | 38 |
|
39 | 39 | public class SpectatorIntegrationTest {
|
40 | 40 |
|
@@ -104,6 +104,35 @@ public void testAnnotatedCounter() {
|
104 | 104 | assertEquals(1, registry.counter(id).count());
|
105 | 105 | }
|
106 | 106 |
|
| 107 | + @Test |
| 108 | + public void testContextualCounter() { |
| 109 | + TagList context = BasicTagList.of("a", "1"); |
| 110 | + ContextualCounter c = new ContextualCounter(CONFIG, () -> context, BasicCounter::new); |
| 111 | + c.increment(); |
| 112 | + Id id = ID.withTag("a", "1"); |
| 113 | + assertEquals(1, registry.counter(id).count()); |
| 114 | + } |
| 115 | + |
| 116 | + @Test |
| 117 | + public void testPeakRateCounter() { |
| 118 | + PeakRateCounter c = new PeakRateCounter(CONFIG); |
| 119 | + DefaultMonitorRegistry.getInstance().register(c); |
| 120 | + c.increment(); |
| 121 | + PolledMeter.update(registry); |
| 122 | + registry.stream().forEach(m -> System.out.println(m.id())); |
| 123 | + assertEquals(1.0, registry.gauge(ID.withTag("type", "GAUGE")).value()); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void testPeakRateCounterRemove() { |
| 128 | + PeakRateCounter c = new PeakRateCounter(CONFIG); |
| 129 | + DefaultMonitorRegistry.getInstance().register(c); |
| 130 | + DefaultMonitorRegistry.getInstance().unregister(c); |
| 131 | + c.increment(); |
| 132 | + PolledMeter.update(registry); |
| 133 | + assertEquals(0, registry.stream().count()); |
| 134 | + } |
| 135 | + |
107 | 136 | @Test
|
108 | 137 | public void testDoubleGauge() {
|
109 | 138 | DoubleGauge c = new DoubleGauge(CONFIG);
|
@@ -151,6 +180,27 @@ public void testDoubleMaxGauge() {
|
151 | 180 | assertEquals(42.0, registry.maxGauge(ID).value(), 1e-12);
|
152 | 181 | }
|
153 | 182 |
|
| 183 | + @Test |
| 184 | + public void testMinGauge() { |
| 185 | + ManualClock clock = new ManualClock(0); |
| 186 | + MinGauge g = new MinGauge(CONFIG, clock); |
| 187 | + DefaultMonitorRegistry.getInstance().register(g); |
| 188 | + g.update(42); |
| 189 | + clock.set(60000); |
| 190 | + PolledMeter.update(registry); |
| 191 | + assertEquals(42.0, registry.gauge(ID.withTag("type", "GAUGE")).value()); |
| 192 | + } |
| 193 | + |
| 194 | + @Test |
| 195 | + public void testMinGaugeRemove() { |
| 196 | + MinGauge g = new MinGauge(CONFIG); |
| 197 | + DefaultMonitorRegistry.getInstance().register(g); |
| 198 | + DefaultMonitorRegistry.getInstance().unregister(g); |
| 199 | + g.update(42); |
| 200 | + PolledMeter.update(registry); |
| 201 | + assertEquals(0, registry.stream().count()); |
| 202 | + } |
| 203 | + |
154 | 204 | @Test
|
155 | 205 | public void testBasicDistributionSummaryRecord() {
|
156 | 206 | BasicDistributionSummary d = new BasicDistributionSummary(CONFIG);
|
@@ -227,6 +277,18 @@ public void testStatsTimerRecordMillis() {
|
227 | 277 | assertEquals(42.0, registry.gauge(id.withTag("statistic", "avg")).value(), 1e-12);
|
228 | 278 | }
|
229 | 279 |
|
| 280 | + @Test |
| 281 | + public void testContextualTimerRecordMillis() { |
| 282 | + TagList context = BasicTagList.of("a", "1"); |
| 283 | + ContextualTimer d = new ContextualTimer(CONFIG, () -> context, BasicTimer::new); |
| 284 | + d.record(42, TimeUnit.NANOSECONDS); |
| 285 | + Id id = ID.withTag("unit", "MILLISECONDS").withTag("a", "1"); |
| 286 | + assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); |
| 287 | + assertEquals(42e-6, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); |
| 288 | + assertEquals(42e-6 * 42e-6, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); |
| 289 | + assertEquals(42e-6, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); |
| 290 | + } |
| 291 | + |
230 | 292 | public static class AnnotateExample {
|
231 | 293 |
|
232 | 294 | private long count = 0;
|
|
0 commit comments