package com.hazelcast.internal.management;

import com.hazelcast.config.Config;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.internal.management.dto.PartitionServiceBeanDTO;
import com.hazelcast.monitor.impl.MemberStateImpl;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
import com.hazelcast.test.annotation.ParallelTest;
import com.hazelcast.test.annotation.QuickTest;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

@RunWith(HazelcastParallelClassRunner.class)
@Category({QuickTest.class, ParallelTest.class})
public class PartitionServiceBeanDTOTest extends HazelcastTestSupport {

    /**
     * https://github.com/hazelcast/hazelcast/issues/8463
     */
    @Test
    public void testJMXStatsWithPublicAddressHostName() {
        Config config = new Config();
        config.getNetworkConfig().setPublicAddress("hazelcast.org");
        HazelcastInstance instance = createHazelcastInstance(config);
        warmUpPartitions(instance);
        MemberStateImpl memberState = new MemberStateImpl();
        TimedMemberStateFactoryHelper.registerJMXBeans(getNode(instance).hazelcastInstance, memberState);
        PartitionServiceBeanDTO partitionServiceDTO = memberState.getMXBeans().getPartitionServiceBean();
        assertEquals(partitionServiceDTO.getPartitionCount(), partitionServiceDTO.getActivePartitionCount());
    }
}

@@ -73,16 +73,136 @@
 Config;%0A
+import com.hazelcast.config.JoinConfig;%0Aimport com.hazelcast.config.NetworkConfig;%0Aimport com.hazelcast.core.Hazelcast;%0A
 import c
@@ -558,24 +558,48 @@
 .QuickTest;%0A
+import org.junit.After;%0A
 import org.j
@@ -694,16 +694,55 @@
 nWith;%0A%0A
+import java.net.UnknownHostException;%0A%0A
 import s
@@ -777,16 +777,62 @@
 tEquals;
+%0Aimport static org.junit.Assume.assumeNotNull;
 %0A%0A@RunWi
@@ -1000,323 +1000,574 @@
     
-/**%0A     * https://github.com/hazelcast/hazelcast/issues/8463%0A     */%0A    @Test%0A    public void testJMXStatsWithPublicAddressHostName() %7B%0A        Config config = new Config();%0A        config.getNetworkConfig().setPublicAddress(%22hazelcast.org%22);%0A        HazelcastInstance instance = createHazelcastInstance(config
+private HazelcastInstance instance;%0A%0A    @After%0A    public void shutdown() %7B%0A        if (instance != null) %7B%0A            instance.shutdown();%0A        %7D%0A    %7D%0A%0A    /**%0A     * https://github.com/hazelcast/hazelcast/issues/8463%0A     */%0A    @Test%0A    public void testJMXStatsWithPublicAddressHostName() %7B%0A        String publicAddress = %22hazelcast.org%22;%0A        instance = createInstanceWithPublicAddress(publicAddress);%0A        assumeNotNull(instance, %22Internet access and/or DNS resolver are not available, %22%0A                + publicAddress + %22 cannot be resolved!%22
 );%0A
+%0A
     
@@ -1594,24 +1594,25 @@
 (instance);%0A
+%0A
         Memb
@@ -1987,11 +1987,1017 @@
 );%0A    %7D
+%0A%0A    private HazelcastInstance createInstanceWithPublicAddress(String publicAddress) %7B%0A        try %7B%0A            Config config = getConfig();%0A            NetworkConfig networkConfig = config.getNetworkConfig();%0A            networkConfig.setPublicAddress(publicAddress);%0A            return Hazelcast.newHazelcastInstance(config);%0A        %7D catch (RuntimeException e) %7B%0A            if (e.getCause() instanceof UnknownHostException) %7B%0A                // internet access and/or DNS resolver are not available%0A                return null;%0A            %7D%0A            throw e;%0A        %7D%0A    %7D%0A%0A    @Override%0A    protected Config getConfig() %7B%0A        Config config = new Config();%0A%0A        // Join is disabled intentionally. will start standalone HazelcastInstance.%0A        NetworkConfig networkConfig = config.getNetworkConfig();%0A        JoinConfig join = networkConfig.getJoin();%0A        join.getMulticastConfig().setEnabled(false);%0A        join.getTcpIpConfig().setEnabled(false);%0A%0A        return config;%0A    %7D
 %0A%7D%0A

Fix PartitionServiceBeanDTOTest.testJMXStatsWithPublicAddressHostName