dttung2905 commented on code in PR #13697:
URL: https://github.com/apache/pinot/pull/13697#discussion_r1710195309


##########
pinot-common/src/test/java/org/apache/pinot/common/metrics/AbstractMetricsTest.java:
##########
@@ -48,4 +52,66 @@ public void testAddOrUpdateGauge() {
     controllerMetrics.removeGauge(metricName);
     
Assert.assertTrue(controllerMetrics.getMetricsRegistry().allMetrics().isEmpty());
   }
+
+  @Test
+  public void testConcurrentGaugeUpdates() 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 = "testConcurrent";
+
+    // update and remove gauge simultaneously
+    ExecutorService service = Executors.newFixedThreadPool(3);
+    IntStream.range(0, 1000).forEach(i -> {
+      controllerMetrics.setOrUpdateGauge(metricName, () -> (long) i);
+    });
+    service.shutdown();
+    service.awaitTermination(1, TimeUnit.MINUTES);
+
+    // Verify final value
+    Assert.assertEquals(MetricValueUtils.getGaugeValue(controllerMetrics, 
metricName), 999);
+    // remove gauge
+    controllerMetrics.removeGauge(metricName);
+    
Assert.assertTrue(controllerMetrics.getMetricsRegistry().allMetrics().isEmpty());
+  }
+
+  @Test
+  public void testRemoveNoneExistentGauge() {

Review Comment:
   nice catch :facepalm: 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to