Created
May 28, 2020 07:52
-
-
Save bdelacretaz/34564a69090b9c7323a4099c3e471502 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java | |
index a8af34a..ad0db8c 100644 | |
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java | |
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java | |
@@ -22,6 +22,8 @@ package org.apache.sling.commons.metrics.internal; | |
import java.lang.management.ManagementFactory; | |
import java.util.Collections; | |
import java.util.Set; | |
+import java.util.UUID; | |
+import java.util.concurrent.atomic.AtomicInteger; | |
import javax.management.MBeanServer; | |
import javax.management.ObjectName; | |
@@ -163,6 +165,23 @@ public class MetricServiceTest { | |
assertFalse(getRegistry().getGauges().containsKey("foo")); | |
} | |
+ @Test | |
+ public void lambdaGaugeExample() { | |
+ activate(); | |
+ final AtomicInteger value = new AtomicInteger(451); | |
+ final String name = "Gauge_" + UUID.randomUUID(); | |
+ getRegistry().register(name, (com.codahale.metrics.Gauge<Integer>) () -> value.get()); | |
+ try { | |
+ assertEquals(451, getRegistry().getGauges().get(name).getValue()); | |
+ value.incrementAndGet(); | |
+ assertEquals(452, getRegistry().getGauges().get(name).getValue()); | |
+ } finally { | |
+ assertTrue(getRegistry().getGauges().containsKey(name)); | |
+ getRegistry().remove(name); | |
+ assertFalse(getRegistry().getGauges().containsKey(name)); | |
+ } | |
+ } | |
+ | |
private MetricRegistry getRegistry(){ | |
return context.getService(MetricRegistry.class); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment