# HG changeset patch
# User prappo
# Date 1568368807 -3600
# Node ID 1def54255e934bed024a4f4cef1d3c152b62a8c0
# Parent 9b4717ca9bd16667b00c632ee1f3f397b4b580fb
8151678: com/sun/jndi/ldap/LdapTimeoutTest.java failed due to timeout on DeadServerNoTimeoutTest is incorrect
Reviewed-by: dfuchs, martin, robm
diff -r 9b4717ca9bd1 -r 1def54255e93 src/java.naming/share/classes/com/sun/jndi/ldap/DefaultLdapDnsProvider.java
--- a/src/java.naming/share/classes/com/sun/jndi/ldap/DefaultLdapDnsProvider.java Fri Sep 13 08:40:09 2019 +0200
+++ b/src/java.naming/share/classes/com/sun/jndi/ldap/DefaultLdapDnsProvider.java Fri Sep 13 11:00:07 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, 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
@@ -76,7 +76,7 @@
}
LdapDnsProviderResult res = new LdapDnsProviderResult(domainName, endpoints);
- if (res.getEndpoints().size() == 0 && res.getDomainName().isEmpty()) {
+ if (res.getEndpoints().isEmpty() && res.getDomainName().isEmpty()) {
return Optional.empty();
} else {
return Optional.of(res);
diff -r 9b4717ca9bd1 -r 1def54255e93 src/java.naming/share/classes/com/sun/jndi/ldap/LdapDnsProviderService.java
--- a/src/java.naming/share/classes/com/sun/jndi/ldap/LdapDnsProviderService.java Fri Sep 13 08:40:09 2019 +0200
+++ b/src/java.naming/share/classes/com/sun/jndi/ldap/LdapDnsProviderService.java Fri Sep 13 11:00:07 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, 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
@@ -37,6 +37,8 @@
* The {@code LdapDnsProviderService} is responsible for creating and providing
* access to the registered {@code LdapDnsProvider}s. The {@link ServiceLoader}
* is used to find and register any implementations of {@link LdapDnsProvider}.
+ *
+ *
Instances of this class are safe for use by multiple threads.
*/
final class LdapDnsProviderService {
@@ -68,11 +70,11 @@
}
/**
- * Retrieve the singleton static instance of LdapDnsProviderService.
+ * Retrieves the singleton instance of LdapDnsProviderService.
*/
static LdapDnsProviderService getInstance() {
if (service != null) return service;
- synchronized(LOCK) {
+ synchronized (LOCK) {
if (service != null) return service;
service = new LdapDnsProviderService();
}
@@ -80,7 +82,7 @@
}
/**
- * Retrieve result from the first provider that successfully resolves
+ * Retrieves result from the first provider that successfully resolves
* the endpoints. If no results are found when calling installed
* subclasses of {@code LdapDnsProvider} then this method will fall back
* to the {@code DefaultLdapDnsProvider}.
@@ -91,14 +93,15 @@
LdapDnsProviderResult lookupEndpoints(String url, Hashtable,?> env)
throws NamingException
{
- Iterator iterator = providers.iterator();
+ LdapDnsProviderResult result = null;
Hashtable, ?> envCopy = new Hashtable<>(env);
- LdapDnsProviderResult result = null;
-
- while (result == null && iterator.hasNext()) {
- result = iterator.next().lookupEndpoints(url, envCopy)
- .filter(r -> r.getEndpoints().size() > 0)
- .orElse(null);
+ synchronized (LOCK) {
+ Iterator iterator = providers.iterator();
+ while (result == null && iterator.hasNext()) {
+ result = iterator.next().lookupEndpoints(url, envCopy)
+ .filter(r -> !r.getEndpoints().isEmpty())
+ .orElse(null);
+ }
}
if (result == null) {
diff -r 9b4717ca9bd1 -r 1def54255e93 test/jdk/ProblemList.txt
--- a/test/jdk/ProblemList.txt Fri Sep 13 08:40:09 2019 +0200
+++ b/test/jdk/ProblemList.txt Fri Sep 13 11:00:07 2019 +0100
@@ -872,8 +872,6 @@
com/sun/jndi/ldap/DeadSSLLdapTimeoutTest.java 8169942 linux-i586,macosx-all,windows-x64
-com/sun/jndi/ldap/LdapTimeoutTest.java 8151678 generic-all
-
com/sun/jndi/dns/ConfigTests/PortUnreachable.java 7164518 macosx-all
javax/rmi/ssl/SSLSocketParametersTest.sh 8162906 generic-all
diff -r 9b4717ca9bd1 -r 1def54255e93 test/jdk/com/sun/jndi/ldap/LdapTimeoutTest.java
--- a/test/jdk/com/sun/jndi/ldap/LdapTimeoutTest.java Fri Sep 13 08:40:09 2019 +0200
+++ b/test/jdk/com/sun/jndi/ldap/LdapTimeoutTest.java Fri Sep 13 11:00:07 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, 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
@@ -21,424 +21,487 @@
* questions.
*/
-/**
+/*
* @test
- * @run main/othervm LdapTimeoutTest
- * @bug 7094377 8000487 6176036 7056489
+ * @library /test/lib
+ * lib/
+ * @run testng/othervm LdapTimeoutTest
+ * @bug 7094377 8000487 6176036 7056489 8151678
* @summary Timeout tests for ldap
*/
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import java.io.IOException;
+import java.io.OutputStream;
import java.net.Socket;
-import java.net.ServerSocket;
-import java.net.SocketTimeoutException;
-import java.io.*;
-import javax.naming.*;
-import javax.naming.directory.*;
+import java.util.ArrayList;
+import java.util.Hashtable;
import java.util.List;
-import java.util.Hashtable;
-import java.util.ArrayList;
+import java.util.Objects;
import java.util.concurrent.Callable;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import java.util.concurrent.TimeUnit;
-import javax.net.ssl.SSLHandshakeException;
+import static java.lang.String.format;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
+import static jdk.test.lib.Utils.adjustTimeout;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.expectThrows;
+public class LdapTimeoutTest {
+
+ // ------ configure test timeouts here ------
-abstract class LdapTest implements Callable {
+ /*
+ * Practical representation of an infinite timeout.
+ */
+ private static final long INFINITY_MILLIS = adjustTimeout(20_000);
+ /*
+ * The acceptable variation in timeout measurements.
+ */
+ private static final long TOLERANCE = adjustTimeout( 3_500);
- Hashtable env;
- TestServer server;
- ScheduledExecutorService killSwitchPool;
- boolean passed = false;
- private int HANGING_TEST_TIMEOUT = 20_000;
+ private static final long CONNECT_MILLIS = adjustTimeout( 3_000);
+ private static final long READ_MILLIS = adjustTimeout(10_000);
+
+ static {
+ // a series of checks to make sure this timeouts configuration is
+ // consistent and the timeouts do not overlap
- public LdapTest (TestServer server, Hashtable env) {
- this.server = server;
- this.env = env;
+ assert (TOLERANCE >= 0);
+ // context creation
+ assert (2 * CONNECT_MILLIS + TOLERANCE < READ_MILLIS);
+ // context creation immediately followed by search
+ assert (2 * CONNECT_MILLIS + READ_MILLIS + TOLERANCE < INFINITY_MILLIS);
+ }
+
+ @BeforeTest
+ public void beforeTest() {
+ startAuxiliaryDiagnosticOutput();
}
- public LdapTest(TestServer server, Hashtable env,
- ScheduledExecutorService killSwitchPool)
- {
- this(server, env);
- this.killSwitchPool = killSwitchPool;
+ /*
+ * These are timeout tests and they are run in parallel to reduce the total
+ * amount of run time.
+ *
+ * Currently it doesn't seem possible to instruct JTREG to run TestNG test
+ * methods in parallel. That said, this JTREG test is still
+ * a "TestNG-flavored" test for the sake of having org.testng.Assert
+ * capability.
+ */
+ @Test
+ public void test() throws Exception {
+ List> futures = new ArrayList<>();
+ ExecutorService executorService = Executors.newCachedThreadPool();
+ try {
+ futures.add(executorService.submit(() -> { test1(); return null; }));
+ futures.add(executorService.submit(() -> { test2(); return null; }));
+ futures.add(executorService.submit(() -> { test3(); return null; }));
+ futures.add(executorService.submit(() -> { test4(); return null; }));
+ futures.add(executorService.submit(() -> { test5(); return null; }));
+ futures.add(executorService.submit(() -> { test6(); return null; }));
+ futures.add(executorService.submit(() -> { test7(); return null; }));
+ } finally {
+ executorService.shutdown();
+ }
+ int failedCount = 0;
+ for (var f : futures) {
+ try {
+ f.get();
+ } catch (ExecutionException e) {
+ failedCount++;
+ e.getCause().printStackTrace(System.out);
+ }
+ }
+ if (failedCount > 0)
+ throw new RuntimeException(failedCount + " (sub)tests failed");
+ }
+
+ static void test1() throws Exception {
+ Hashtable