Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove @Disabled from jetty-jmx #9143

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

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;
Expand All @@ -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);
public static final int DEFAULT_PORT = 1099;
joakime marked this conversation as resolved.
Show resolved Hide resolved

private JMXServiceURL _jmxURL;
private final Map<String, Object> _environment;
Expand Down Expand Up @@ -182,7 +184,20 @@ public void doStart() throws Exception
{
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().getHostName(), DEFAULT_PORT);
}
else if (rawHost.startsWith(":")) // port without host
{
hostPort = new HostPort(InetAddress.getLocalHost().getHostName() + rawHost);
}
else
hostPort = new HostPort(rawHost);
joakime marked this conversation as resolved.
Show resolved Hide resolved

String registryHost = startRegistry(hostPort);
// If the RMI registry was already started, use the existing port.
if (_registryPort == 0)
Expand Down Expand Up @@ -211,7 +226,8 @@ public void doStart() throws Exception
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();
Expand All @@ -220,7 +236,7 @@ public void doStop() throws Exception
private String startRegistry(HostPort hostPort) throws Exception
{
String host = hostPort.getHost();
int port = hostPort.getPort(1099);
int port = hostPort.getPort(DEFAULT_PORT);

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
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
Expand All @@ -46,7 +47,6 @@
* 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";
Expand All @@ -55,8 +55,7 @@ public class ConnectorServerTest
@AfterEach
public void tearDown() throws Exception
{
if (connectorServer != null)
connectorServer.stop();
LifeCycle.stop(connectorServer);
}

@Test
Expand All @@ -66,7 +65,7 @@ public void testAddressAfterStart() throws Exception
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Jetty Logging using jetty-slf4j-impl
#org.eclipse.jetty.jmx.LEVEL=DEBUG
#org.eclipse.jetty.util.HostPort.LEVEL=DEBUG