This is an automated email from the ASF dual-hosted git repository.

jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b9439d6fe Add more unit test for `AbstractMetricsTest` (#13697)
3b9439d6fe is described below

commit 3b9439d6fe7162731cfa1235926aa1119e1c5eea
Author: Dao Thanh Tung <[email protected]>
AuthorDate: Fri Aug 16 08:00:33 2024 +0100

    Add more unit test for `AbstractMetricsTest` (#13697)
---
 .../pinot/common/metrics/AbstractMetricsTest.java  | 60 ++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git 
a/pinot-common/src/test/java/org/apache/pinot/common/metrics/AbstractMetricsTest.java
 
b/pinot-common/src/test/java/org/apache/pinot/common/metrics/AbstractMetricsTest.java
index 1ff1d1a58f..4ad2dc2fb9 100644
--- 
a/pinot-common/src/test/java/org/apache/pinot/common/metrics/AbstractMetricsTest.java
+++ 
b/pinot-common/src/test/java/org/apache/pinot/common/metrics/AbstractMetricsTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.pinot.common.metrics;
 
+import java.util.stream.IntStream;
 import org.apache.pinot.plugin.metrics.yammer.YammerMetricsRegistry;
 import org.apache.pinot.spi.env.PinotConfiguration;
 import org.apache.pinot.spi.metrics.PinotMetricUtils;
@@ -48,4 +49,63 @@ public class AbstractMetricsTest {
     controllerMetrics.removeGauge(metricName);
     
Assert.assertTrue(controllerMetrics.getMetricsRegistry().allMetrics().isEmpty());
   }
+
+  @Test
+  public void testMultipleUpdatesToGauge() throws InterruptedException {
+    PinotConfiguration pinotConfiguration = new PinotConfiguration();
+    pinotConfiguration.setProperty(CONFIG_OF_METRICS_FACTORY_CLASS_NAME,
+        "org.apache.pinot.plugin.metrics.yammer.YammerMetricsFactory");
+    PinotMetricUtils.init(pinotConfiguration);
+    ControllerMetrics controllerMetrics = new ControllerMetrics(new 
YammerMetricsRegistry());
+    String metricName = "testMultipleUpdates";
+
+    // update and remove gauge simultaneously
+    IntStream.range(0, 1000).forEach(i -> {
+      controllerMetrics.setOrUpdateGauge(metricName, () -> (long) i);
+    });
+
+    // Verify final value
+    Assert.assertEquals(MetricValueUtils.getGaugeValue(controllerMetrics, 
metricName), 999);
+    // remove gauge
+    controllerMetrics.removeGauge(metricName);
+    
Assert.assertTrue(controllerMetrics.getMetricsRegistry().allMetrics().isEmpty());
+  }
+
+  @Test
+  public void testRemoveNonExistentGauge() {
+    PinotConfiguration pinotConfiguration = new PinotConfiguration();
+    pinotConfiguration.setProperty(CONFIG_OF_METRICS_FACTORY_CLASS_NAME,
+        "org.apache.pinot.plugin.metrics.yammer.YammerMetricsFactory");
+    PinotMetricUtils.init(pinotConfiguration);
+    ControllerMetrics controllerMetrics = new ControllerMetrics(new 
YammerMetricsRegistry());
+    String metricName = "testNonExistent";
+
+    // Attempt to remove a nonexistent gauge
+    controllerMetrics.removeGauge(metricName);
+    
Assert.assertTrue(controllerMetrics.getMetricsRegistry().allMetrics().isEmpty());
+  }
+
+  @Test
+  public void testMultipleGauges() {
+    PinotConfiguration pinotConfiguration = new PinotConfiguration();
+    pinotConfiguration.setProperty(CONFIG_OF_METRICS_FACTORY_CLASS_NAME,
+        "org.apache.pinot.plugin.metrics.yammer.YammerMetricsFactory");
+    PinotMetricUtils.init(pinotConfiguration);
+    ControllerMetrics controllerMetrics = new ControllerMetrics(new 
YammerMetricsRegistry());
+    String metricName1 = "testMultiple1";
+    String metricName2 = "testMultiple2";
+
+    // Add multiple gauges
+    controllerMetrics.setOrUpdateGauge(metricName1, () -> 1L);
+    controllerMetrics.setOrUpdateGauge(metricName2, () -> 2L);
+
+    // Verify values
+    Assert.assertEquals(MetricValueUtils.getGaugeValue(controllerMetrics, 
metricName1), 1);
+    Assert.assertEquals(MetricValueUtils.getGaugeValue(controllerMetrics, 
metricName2), 2);
+
+    // Remove gauges
+    controllerMetrics.removeGauge(metricName1);
+    controllerMetrics.removeGauge(metricName2);
+    
Assert.assertTrue(controllerMetrics.getMetricsRegistry().allMetrics().isEmpty());
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to