mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-03 04:30:06 +00:00
8355278: Improve debuggability of com/sun/jndi/ldap/LdapPoolTimeoutTest.java test
Reviewed-by: aefimov
This commit is contained in:
parent
023f30bcaa
commit
6befc18974
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -30,10 +30,8 @@
|
||||
* @run testng/othervm LdapPoolTimeoutTest
|
||||
*/
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
@ -44,13 +42,8 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static jdk.test.lib.Utils.adjustTimeout;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.expectThrows;
|
||||
|
||||
public class LdapPoolTimeoutTest {
|
||||
/*
|
||||
@ -101,12 +94,13 @@ public class LdapPoolTimeoutTest {
|
||||
executorService.shutdown();
|
||||
}
|
||||
int failedCount = 0;
|
||||
for (var f : futures) {
|
||||
for (int i = 0; i < futures.size(); i++) {
|
||||
try {
|
||||
f.get();
|
||||
futures.get(i).get();
|
||||
} catch (ExecutionException e) {
|
||||
failedCount++;
|
||||
e.getCause().printStackTrace(System.out);
|
||||
System.err.println("task " + (i + 1) + " failed:");
|
||||
e.getCause().printStackTrace();
|
||||
}
|
||||
}
|
||||
if (failedCount > 0)
|
||||
@ -119,20 +113,31 @@ public class LdapPoolTimeoutTest {
|
||||
2 * CONNECT_MILLIS + TOLERANCE,
|
||||
() -> new InitialDirContext(env));
|
||||
} catch (RuntimeException e) {
|
||||
String msg = e.getCause() == null ? e.getMessage() : e.getCause().getMessage();
|
||||
System.err.println("MSG RTE: " + msg);
|
||||
final String msg = e.getCause() == null ? e.getMessage() : e.getCause().getMessage();
|
||||
// assertCompletion may wrap a CommunicationException in an RTE
|
||||
assertNotNull(msg);
|
||||
assertTrue(msg.contains("Network is unreachable")
|
||||
|| msg.contains("No route to host") || msg.contains("Connection timed out"));
|
||||
if (msg != null &&
|
||||
(msg.contains("Network is unreachable")
|
||||
|| msg.contains("No route to host")
|
||||
|| msg.contains("Connection timed out"))) {
|
||||
// got the expected exception
|
||||
System.out.println("Received expected RuntimeException message: " + msg);
|
||||
} else {
|
||||
// propagate the unexpected exception
|
||||
throw e;
|
||||
}
|
||||
} catch (NamingException ex) {
|
||||
String msg = ex.getCause() == null ? ex.getMessage() : ex.getCause().getMessage();
|
||||
System.err.println("MSG: " + msg);
|
||||
assertTrue(msg != null &&
|
||||
final String msg = ex.getCause() == null ? ex.getMessage() : ex.getCause().getMessage();
|
||||
if (msg != null &&
|
||||
(msg.contains("Network is unreachable")
|
||||
|| msg.contains("Timed out waiting for lock")
|
||||
|| msg.contains("Connect timed out")
|
||||
|| msg.contains("Timeout exceeded while waiting for a connection")));
|
||||
|| msg.contains("Timeout exceeded while waiting for a connection"))) {
|
||||
// got the expected exception
|
||||
System.out.println("Received expected NamingException message: " + msg);
|
||||
} else {
|
||||
// propagate the unexpected exception
|
||||
throw ex;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user