jiajunwang commented on a change in pull request #1059: URL: https://github.com/apache/helix/pull/1059#discussion_r439636316
########## File path: helix-core/src/test/java/org/apache/helix/controller/rebalancer/constraint/TestAbnormalStatesResolverMonitor.java ########## @@ -0,0 +1,89 @@ +package org.apache.helix.controller.rebalancer.constraint; + +/* + * 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. + */ + +import java.lang.management.ManagementFactory; +import java.util.Random; +import javax.management.AttributeNotFoundException; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.ReflectionException; + +import org.apache.helix.model.MasterSlaveSMD; +import org.apache.helix.monitoring.mbeans.MonitorDomainNames; +import org.apache.helix.monitoring.metrics.AbnormalStatesMetricCollector; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class TestAbnormalStatesResolverMonitor { + private static final MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer(); + + @Test + public void testMonitorResolver() + throws MalformedObjectNameException, AttributeNotFoundException, MBeanException, + ReflectionException, InstanceNotFoundException { + final String clusterName = "TestCluster"; + + final String TEST_RESOLVER_MONITOR_MBEAN_NAME = String + .format("%s:%s=%s, %s=%s.%s", MonitorDomainNames.Rebalancer, "ClusterName", clusterName, + "EntityName", "AbnormalStates", MasterSlaveSMD.name); + final ObjectName TEST_RESOLVER_MONITOR_MBEAN_OBJECT_NAME = + new ObjectName(TEST_RESOLVER_MONITOR_MBEAN_NAME); + + Assert.assertFalse(beanServer.isRegistered(TEST_RESOLVER_MONITOR_MBEAN_OBJECT_NAME)); + + // Update the resolver configuration for MasterSlave state model. + MonitoredAbnormalResolver monitoredAbnormalResolver = + new MonitoredAbnormalResolver(new MockAbnormalStateResolver(), clusterName, + MasterSlaveSMD.name); + + // Validate if the MBean has been registered + Assert.assertTrue(beanServer.isRegistered(TEST_RESOLVER_MONITOR_MBEAN_OBJECT_NAME)); + Assert.assertEquals(beanServer.getAttribute(TEST_RESOLVER_MONITOR_MBEAN_OBJECT_NAME, + AbnormalStatesMetricCollector.AbnormalStatesMetricNames.AbnormalStatePartitionCounter.name()), + 0L); + Assert.assertEquals(beanServer.getAttribute(TEST_RESOLVER_MONITOR_MBEAN_OBJECT_NAME, + AbnormalStatesMetricCollector.AbnormalStatesMetricNames.RecoveryAttemptCounter.name()), 0L); + // Validate if the metrics recording methods work as expected + Random ran = new Random(System.currentTimeMillis()); + Long expectation = 1L + ran.nextInt(10); Review comment: Actually, I believe the check will fail if using primitive types. The Assert thinks the values are different. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
