int getPort() {
        return port;
    }
@Test
    void testJMXServiceRegisterMBean() throws Exception {
        TestObject testObject = new TestObject();
        ObjectName testObjectName = new ObjectName("org.apache.flink.management", "key", "value");
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

        try {
            Optional<JMXServer> server = JMXService.getInstance();
            assertThat(server).isPresent();
            mBeanServer.registerMBean(testObject, testObjectName);

            JMXServiceURL url =
                    new JMXServiceURL(
                            "service:jmx:rmi://localhost:"
                                    + server.get().getPort()
                                    + "/jndi/rmi://localhost:"
                                    + server.get().getPort()
                                    + "/jmxrmi");
            JMXConnector jmxConn = JMXConnectorFactory.connect(url);
            MBeanServerConnection mbeanConnConn = jmxConn.getMBeanServerConnection();

            assertThat((int) mbeanConnConn.getAttribute(testObjectName, "Foo")).isOne();
            mBeanServer.unregisterMBean(testObjectName);
            assertThatThrownBy(() -> mbeanConnConn.getAttribute(testObjectName, "Foo"))
                    .isInstanceOf(InstanceNotFoundException.class);
        } finally {
            JMXService.stopInstance();
        }
    }