Remove `@Disabled` from `jetty-jmx` (#9143)

* Remove @Disabled from jetty-jmx
This commit is contained in:
Joakim Erdfelt 2023-01-09 15:20:55 -06:00 committed by GitHub
parent 6d075a4c17
commit b4d274e3d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -38,6 +38,7 @@ import javax.rmi.ssl.SslRMIClientSocketFactory;
import org.eclipse.jetty.util.HostPort;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.ShutdownThread;
@ -58,6 +59,7 @@ public class ConnectorServer extends AbstractLifeCycle
{
public static final String RMI_REGISTRY_CLIENT_SOCKET_FACTORY_ATTRIBUTE = "com.sun.jndi.rmi.factory.socket";
private static final Logger LOG = LoggerFactory.getLogger(ConnectorServer.class);
private static final int DEFAULT_REGISTRY_PORT = 1099;
private JMXServiceURL _jmxURL;
private final Map<String, Object> _environment;
@ -182,7 +184,16 @@ public class ConnectorServer extends AbstractLifeCycle
{
int startIndex = jndiRMI.length();
int endIndex = urlPath.indexOf('/', startIndex);
HostPort hostPort = new HostPort(urlPath.substring(startIndex, endIndex));
String rawHost = urlPath.substring(startIndex, endIndex);
HostPort hostPort;
if (StringUtil.isBlank(rawHost)) // no host
hostPort = new HostPort(InetAddress.getLocalHost().getHostAddress(), DEFAULT_REGISTRY_PORT);
else if (rawHost.startsWith(":")) // port without host
hostPort = new HostPort(InetAddress.getLocalHost().getHostAddress() + rawHost);
else
hostPort = new HostPort(rawHost);
String registryHost = startRegistry(hostPort);
// If the RMI registry was already started, use the existing port.
if (_registryPort == 0)
@ -211,7 +222,8 @@ public class ConnectorServer extends AbstractLifeCycle
public void doStop() throws Exception
{
ShutdownThread.deregister(this);
_connectorServer.stop();
if (_connectorServer != null)
_connectorServer.stop();
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
mbeanServer.unregisterMBean(new ObjectName(getObjectName()));
stopRegistry();
@ -220,7 +232,7 @@ public class ConnectorServer extends AbstractLifeCycle
private String startRegistry(HostPort hostPort) throws Exception
{
String host = hostPort.getHost();
int port = hostPort.getPort(1099);
int port = hostPort.getPort(DEFAULT_REGISTRY_PORT);
try
{

View File

@ -25,14 +25,15 @@ import javax.management.remote.JMXServiceURL;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.matchesRegex;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Running the tests of this class in the same JVM results often in
@ -46,7 +47,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* Running each test method in a forked JVM makes these tests all pass,
* therefore the issue is likely caused by use of stale stubs cached by the JDK.
*/
@Disabled
public class ConnectorServerTest
{
private String objectName = "org.eclipse.jetty:name=rmiconnectorserver";
@ -55,8 +55,7 @@ public class ConnectorServerTest
@AfterEach
public void tearDown() throws Exception
{
if (connectorServer != null)
connectorServer.stop();
LifeCycle.stop(connectorServer);
}
@Test
@ -66,7 +65,7 @@ public class ConnectorServerTest
connectorServer.start();
JMXServiceURL address = connectorServer.getAddress();
assertTrue(address.toString().matches("service:jmx:rmi://[^:]+:\\d+/jndi/rmi://[^:]+:\\d+/jmxrmi"));
assertThat(address.toString(), matchesRegex("service:jmx:rmi://[^:]+(:\\d+)?/jndi/rmi://[^:]+:\\d+/jmxrmi"));
}
@Test

View File

@ -1,2 +1,2 @@
# Jetty Logging using jetty-slf4j-impl
#org.eclipse.jetty.jmx.LEVEL=DEBUG
#org.eclipse.jetty.util.HostPort.LEVEL=DEBUG