|
28 | 28 | import java.security.KeyStore; |
29 | 29 | import java.util.HashMap; |
30 | 30 | import java.util.Map; |
| 31 | +import java.util.concurrent.atomic.AtomicReference; |
31 | 32 |
|
32 | 33 | import javax.management.MBeanServerConnection; |
33 | 34 | import javax.management.remote.JMXConnector; |
@@ -213,27 +214,36 @@ public void testSslJmxConnectionSucceeds() throws Exception { |
213 | 214 | context = createSslManagementContext(); |
214 | 215 | context.start(); |
215 | 216 |
|
| 217 | + assertTrue("Connector should be started", |
| 218 | + Wait.waitFor(context::isConnectorStarted, 20_000, 100)); |
| 219 | + |
216 | 220 | final int port = context.getConnectorPort(); |
217 | 221 | assertTrue("SSL connector port should be resolved", port > 0); |
218 | 222 |
|
219 | 223 | final JMXServiceURL url = new JMXServiceURL( |
220 | 224 | "service:jmx:rmi:///jndi/rmi://localhost:" + port + "/jmxrmi"); |
221 | 225 | final Map<String, Object> env = new HashMap<>(); |
222 | 226 | env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory()); |
| 227 | + final AtomicReference<Exception> lastError = new AtomicReference<>(); |
223 | 228 |
|
224 | 229 | // Retry connection: isConnectorStarted() can return true (via isActive()) before |
225 | 230 | // 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(() -> { |
227 | 232 | try (final JMXConnector connector = JMXConnectorFactory.connect(url, env)) { |
228 | 233 | final MBeanServerConnection connection = connector.getMBeanServerConnection(); |
229 | 234 | LOG.info("Successfully connected to SSL JMX on port {}, found {} MBeans", |
230 | 235 | port, connection.getMBeanCount()); |
231 | 236 | return connection.getMBeanCount() > 0; |
232 | 237 | } catch (final Exception e) { |
| 238 | + lastError.set(e); |
233 | 239 | LOG.debug("JMX SSL connection attempt failed: {}", e.getMessage()); |
234 | 240 | return false; |
235 | 241 | } |
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); |
237 | 247 | } |
238 | 248 |
|
239 | 249 | @Test |
|
0 commit comments