提交 53630da0 编写于 作者: Z zentol

[hotfix][metrics] Harden JMXAvailability test

上级 123be227
......@@ -125,6 +125,10 @@ public class JMXReporter implements MetricReporter {
}
}
}
public int getPort() {
return jmxServer.port;
}
// ------------------------------------------------------------------------
// adding / removing metrics
......@@ -415,6 +419,7 @@ public class JMXReporter implements MetricReporter {
private static class JMXServer {
private Registry rmiRegistry;
private JMXConnectorServer connector;
private int port;
public void start(int port) throws IOException {
if (rmiRegistry != null && connector != null) {
......@@ -423,6 +428,7 @@ public class JMXReporter implements MetricReporter {
}
startRmiRegistry(port);
startJmxService(port);
this.port = port;
}
/**
......
......@@ -38,7 +38,6 @@ import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.lang.management.ManagementFactory;
import static org.apache.flink.metrics.MetricRegistry.KEY_METRICS_JMX_PORT;
import static org.apache.flink.metrics.MetricRegistry.KEY_METRICS_REPORTER_CLASS;
import static org.junit.Assert.assertEquals;
......@@ -137,16 +136,8 @@ public class JMXReporterTest extends TestLogger {
JMXReporter rep1 = new JMXReporter();
JMXReporter rep2 = new JMXReporter();
int port1 = 9010;
int port2 = 9011;
Configuration cfg1 = new Configuration();
cfg1.setString(KEY_METRICS_JMX_PORT, String.valueOf(port1));
Configuration cfg2 = new Configuration();
cfg2.setString(KEY_METRICS_JMX_PORT, String.valueOf(port2));
rep1.open(cfg1);
rep2.open(cfg2);
rep1.open(new Configuration());
rep2.open(new Configuration());
rep1.notifyOfAddedMetric(new Gauge<Integer>() {
@Override
......@@ -165,7 +156,7 @@ public class JMXReporterTest extends TestLogger {
ObjectName objectName1 = new ObjectName(JMXReporter.generateJmxName("rep1", mg.getScopeComponents()));
ObjectName objectName2 = new ObjectName(JMXReporter.generateJmxName("rep2", mg.getScopeComponents()));
JMXServiceURL url1 = new JMXServiceURL("service:jmx:rmi://localhost:" + port1 + "/jndi/rmi://localhost:" + port1 + "/jmxrmi");
JMXServiceURL url1 = new JMXServiceURL("service:jmx:rmi://localhost:" + rep1.getPort() + "/jndi/rmi://localhost:" + rep1.getPort() + "/jmxrmi");
JMXConnector jmxCon1 = JMXConnectorFactory.connect(url1);
MBeanServerConnection mCon1 = jmxCon1.getMBeanServerConnection();
......@@ -177,7 +168,7 @@ public class JMXReporterTest extends TestLogger {
jmxCon1 = null;
mCon1 = null;
JMXServiceURL url2 = new JMXServiceURL("service:jmx:rmi://localhost:" + port2 + "/jndi/rmi://localhost:" + port2 + "/jmxrmi");
JMXServiceURL url2 = new JMXServiceURL("service:jmx:rmi://localhost:" + rep2.getPort() + "/jndi/rmi://localhost:" + rep2.getPort() + "/jmxrmi");
JMXConnector jmxCon2 = JMXConnectorFactory.connect(url2);
MBeanServerConnection mCon2 = jmxCon2.getMBeanServerConnection();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册