Skip to content

Commit 69fe9f4

Browse files
committed
test(jmx): Enhance SSL JMX connection test with improved error handling and connection retries
1 parent 5a64f84 commit 69fe9f4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

activemq-broker/src/test/java/org/apache/activemq/broker/jmx/ManagementContextSslTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.security.KeyStore;
2929
import java.util.HashMap;
3030
import java.util.Map;
31+
import java.util.concurrent.atomic.AtomicReference;
3132

3233
import javax.management.MBeanServerConnection;
3334
import javax.management.remote.JMXConnector;
@@ -213,27 +214,36 @@ public void testSslJmxConnectionSucceeds() throws Exception {
213214
context = createSslManagementContext();
214215
context.start();
215216

217+
assertTrue("Connector should be started",
218+
Wait.waitFor(context::isConnectorStarted, 20_000, 100));
219+
216220
final int port = context.getConnectorPort();
217221
assertTrue("SSL connector port should be resolved", port > 0);
218222

219223
final JMXServiceURL url = new JMXServiceURL(
220224
"service:jmx:rmi:///jndi/rmi://localhost:" + port + "/jmxrmi");
221225
final Map<String, Object> env = new HashMap<>();
222226
env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
227+
final AtomicReference<Exception> lastError = new AtomicReference<>();
223228

224229
// Retry connection: isConnectorStarted() can return true (via isActive()) before
225230
// the RMI server stub is fully registered in the registry
226-
assertTrue("Should connect to SSL JMX", Wait.waitFor(() -> {
231+
final boolean connected = Wait.waitFor(() -> {
227232
try (final JMXConnector connector = JMXConnectorFactory.connect(url, env)) {
228233
final MBeanServerConnection connection = connector.getMBeanServerConnection();
229234
LOG.info("Successfully connected to SSL JMX on port {}, found {} MBeans",
230235
port, connection.getMBeanCount());
231236
return connection.getMBeanCount() > 0;
232237
} catch (final Exception e) {
238+
lastError.set(e);
233239
LOG.debug("JMX SSL connection attempt failed: {}", e.getMessage());
234240
return false;
235241
}
236-
}, 10_000, 500));
242+
}, 30_000, 500);
243+
final Exception error = lastError.get();
244+
assertTrue("Should connect to SSL JMX"
245+
+ (error == null ? "" : " (last error: " + error + ")"),
246+
connected);
237247
}
238248

239249
@Test

0 commit comments

Comments
 (0)