brusdev commented on code in PR #5483:
URL: https://github.com/apache/activemq-artemis/pull/5483#discussion_r1952646759


##########
artemis-server/src/test/java/org/apache/activemq/artemis/core/server/metrics/MetricsManagerTest.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.core.server.metrics;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.activemq.artemis.core.config.MetricsConfiguration;
+import org.apache.activemq.artemis.core.config.WildcardConfiguration;
+import 
org.apache.activemq.artemis.core.server.metrics.plugins.SimpleMetricsPlugin;
+import org.apache.activemq.artemis.core.settings.HierarchicalRepository;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import 
org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository;
+import org.apache.activemq.artemis.utils.RandomUtil;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class MetricsManagerTest {
+
+   @Test
+   public void testQueueMetricsEnabled() throws Exception {
+      testQueueMetrics(true);
+   }
+
+   @Test
+   public void testQueueMetricsDisabled() throws Exception {
+      testQueueMetrics(false);
+   }
+
+   public void testQueueMetrics(boolean enableMetrics) throws Exception {
+      final String tempQueueNamespace = "temp.";
+      final long latchTimeout = 100;
+
+      HierarchicalRepository<AddressSettings> addressSettingsRepository = new 
HierarchicalObjectRepository<>(new WildcardConfiguration());
+
+      // enable metrics for temp queues
+      addressSettingsRepository.addMatch(tempQueueNamespace + "#", new 
AddressSettings().setEnableMetrics(enableMetrics));
+
+      // enable metrics for normal queues
+      addressSettingsRepository.addMatch("#", new 
AddressSettings().setEnableMetrics(enableMetrics));
+
+      MetricsConfiguration metricsConfiguration = new MetricsConfiguration();
+      metricsConfiguration.setPlugin(new SimpleMetricsPlugin().init(null));
+      MetricsManager metricsManager = new 
MetricsManager(RandomUtil.randomString(), metricsConfiguration, 
addressSettingsRepository, null, temp -> {
+         // this is a simplified version of 
org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.getRuntimeTempQueueNamespace
+         if (temp) {
+            return tempQueueNamespace;
+         } else {
+            return "";
+         }
+      });
+
+      // test temp queue
+      CountDownLatch tempTest = new CountDownLatch(1);

Review Comment:
   The builder is executed before the return of registerQueueGauge, could 
tempTest be replace with an AtomicBoolean or any other simpler class to track 
the execution without waiting for the timeout?



-- 
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: gitbox-unsubscr...@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org
For additional commands, e-mail: gitbox-h...@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact


Reply via email to