8134267: javax/net/ssl/TLS/TestJSSE.java fails intermittently with BindException: Address already in use

Reviewed-by: chegar
This commit is contained in:
Artem Smotrakov 2016-05-19 09:16:59 -07:00
parent 4b1159ce76
commit 2100b2e6c2
3 changed files with 56 additions and 37 deletions

@ -1,5 +1,5 @@
/**
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, 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 under
@ -202,6 +202,8 @@ public class CipherTestUtils {
@Override
public abstract void run();
abstract int getPort();
void handleRequest(InputStream in, OutputStream out)
throws IOException {
boolean newline = false;
@ -528,9 +530,9 @@ public class CipherTestUtils {
return ks;
}
public static void main(PeerFactory peerFactory, String mode,
String expectedException)
throws Exception {
public static int mainServer(PeerFactory peerFactory,
String expectedException) throws Exception {
long time = System.currentTimeMillis();
setTestedArguments(peerFactory.getTestedProtocol(),
peerFactory.getTestedCipher());
@ -540,33 +542,49 @@ public class CipherTestUtils {
secureRandom.nextInt();
CipherTestUtils cipherTest = CipherTestUtils.getInstance();
if (mode.equalsIgnoreCase("Server")) { // server mode
Thread serverThread = new Thread(peerFactory.newServer(cipherTest),
"Server");
serverThread.start();
} else if (mode.equalsIgnoreCase("Client")) {
peerFactory.newClient(cipherTest).run();
cipherTest.checkResult(expectedException);
JSSEServer.closeServer = true;
} else {
throw new RuntimeException("unsupported mode");
}
Server server = peerFactory.newServer(cipherTest, PeerFactory.FREE_PORT);
Thread serverThread = new Thread(server, "Server");
serverThread.start();
time = System.currentTimeMillis() - time;
System.out.println("Elapsed time " + time);
return server.getPort();
}
public static void mainClient(PeerFactory peerFactory, int port,
String expectedException) throws Exception {
long time = System.currentTimeMillis();
setTestedArguments(peerFactory.getTestedProtocol(),
peerFactory.getTestedCipher());
System.out.print(
" Initializing test '" + peerFactory.getName() + "'...");
secureRandom.nextInt();
CipherTestUtils cipherTest = CipherTestUtils.getInstance();
peerFactory.newClient(cipherTest, port).run();
cipherTest.checkResult(expectedException);
JSSEServer.closeServer = true;
time = System.currentTimeMillis() - time;
System.out.println("Elapsed time " + time);
}
public static abstract class PeerFactory {
public static final int FREE_PORT = 0;
abstract String getName();
abstract String getTestedProtocol();
abstract String getTestedCipher();
abstract Client newClient(CipherTestUtils cipherTest) throws Exception;
abstract Client newClient(CipherTestUtils cipherTest, int testPort) throws Exception;
abstract Server newServer(CipherTestUtils cipherTest) throws Exception;
abstract Server newServer(CipherTestUtils cipherTest, int testPort) throws Exception;
boolean isSupported(String cipherSuite) {
return true;

@ -1,5 +1,5 @@
/**
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, 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 under
@ -77,4 +77,8 @@ public class JSSEServer extends CipherTestUtils.Server {
}
}
}
int getPort() {
return serverSocket.getLocalPort();
}
}

@ -27,10 +27,8 @@ import java.security.Security;
/**
* @test
* @bug 8049429
* @library ../../../../lib/testlibrary/
* @modules java.management
* jdk.crypto.ec/sun.security.ec
* @build jdk.testlibrary.Utils
* @compile CipherTestUtils.java JSSEClient.java JSSEServer.java
* @summary Test that all cipher suites work in all versions and all client
* authentication types. The way this is setup the server is stateless and
@ -86,7 +84,6 @@ public class TestJSSE {
String serverProtocol = System.getProperty("SERVER_PROTOCOL");
String clientProtocol = System.getProperty("CLIENT_PROTOCOL");
int port = jdk.testlibrary.Utils.getFreePort();
String cipher = System.getProperty("CIPHER");
if (serverProtocol == null
|| clientProtocol == null
@ -97,7 +94,7 @@ public class TestJSSE {
out.println("ServerProtocol =" + serverProtocol);
out.println("ClientProtocol =" + clientProtocol);
out.println("Cipher =" + cipher);
server(serverProtocol, cipher, port, args);
int port = server(serverProtocol, cipher, args);
client(port, clientProtocol, cipher, args);
}
@ -112,28 +109,30 @@ public class TestJSSE {
out.println(" Testing - Protocol : " + testProtocols);
out.println(" Testing - Cipher : " + testCipher);
try {
CipherTestUtils.main(new JSSEFactory(LOCAL_IP,
testPort, testProtocols,
testCipher, "client JSSE"),
"client", expectedException);
CipherTestUtils.mainClient(new JSSEFactory(LOCAL_IP, testProtocols,
testCipher, "Client JSSE"),
testPort, expectedException);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void server(String testProtocol, String testCipher,
int testPort,
public static int server(String testProtocol, String testCipher,
String... exception) throws Exception {
String expectedException = exception.length >= 1
? exception[0] : null;
out.println(" This is Server");
out.println(" Testing Protocol: " + testProtocol);
out.println(" Testing Cipher: " + testCipher);
out.println(" Testing Port: " + testPort);
try {
CipherTestUtils.main(new JSSEFactory(null, testPort,
testProtocol, testCipher, "Server JSSE"),
"Server", expectedException);
int port = CipherTestUtils.mainServer(new JSSEFactory(
null, testProtocol, testCipher, "Server JSSE"),
expectedException);
out.println(" Testing Port: " + port);
return port;
} catch (Exception e) {
throw new RuntimeException(e);
}
@ -142,15 +141,13 @@ public class TestJSSE {
private static class JSSEFactory extends CipherTestUtils.PeerFactory {
final String testedCipherSuite, testedProtocol, testHost;
final int testPort;
final String name;
JSSEFactory(String testHost, int testPort, String testedProtocol,
JSSEFactory(String testHost, String testedProtocol,
String testedCipherSuite, String name) {
this.testedCipherSuite = testedCipherSuite;
this.testedProtocol = testedProtocol;
this.testHost = testHost;
this.testPort = testPort;
this.name = name;
}
@ -170,14 +167,14 @@ public class TestJSSE {
}
@Override
CipherTestUtils.Client newClient(CipherTestUtils cipherTest)
CipherTestUtils.Client newClient(CipherTestUtils cipherTest, int testPort)
throws Exception {
return new JSSEClient(cipherTest, testHost, testPort,
testedProtocol, testedCipherSuite);
}
@Override
CipherTestUtils.Server newServer(CipherTestUtils cipherTest)
CipherTestUtils.Server newServer(CipherTestUtils cipherTest, int testPort)
throws Exception {
return new JSSEServer(cipherTest, testPort,
testedProtocol, testedCipherSuite);