提交 0f080bcf 编写于 作者: A asaha

Merge

......@@ -594,6 +594,7 @@ f6cc9dbb5db5883385c91bb71ca02081220aaf3d jdk8u81-b00
25934d0d38fe10383ff22eb3f39bf5e8b9e73ac9 jdk8u101-b03
ebc56c2e803597ef409a5296addc986b390d934d jdk8u101-b04
c387bd2fb7db40467bd9aa803c8510a04ca32bae jdk8u101-b05
a15cdf2e91e7c2d71510280b31ae11048fb2f31e jdk8u101-b06
39baa472e20c13c0eb1243eb5dce589e82f78143 jdk8u76-b00
6ea3aea950d19d803475b3f4d704a2942e71b302 jdk8u76-b01
4de4cffb5988cd68959ce4bbd14c6d4547078c91 jdk8u76-b02
......
/*
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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
......@@ -35,6 +35,7 @@ import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.security.KeyStore;
public class SSLCtxAccessToSessCtx {
......@@ -63,7 +64,7 @@ public class SSLCtxAccessToSessCtx {
/*
* Is the server ready to serve?
*/
volatile static boolean serverReady = false;
AtomicInteger serverReady = new AtomicInteger(1); // only one port now
/*
* Turn on SSL debugging?
......@@ -89,12 +90,13 @@ public class SSLCtxAccessToSessCtx {
SSLServerSocket sslServerSocket =
(SSLServerSocket) sslssf.createServerSocket(serverPort);
serverPorts[createdPorts++] = sslServerSocket.getLocalPort();
int slot = createdPorts.getAndIncrement();
serverPorts[slot] = sslServerSocket.getLocalPort();
/*
* Signal Client, we're ready for his connect.
*/
serverReady = true;
serverReady.getAndDecrement();
int read = 0;
SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
InputStream sslIS = sslSocket.getInputStream();
......@@ -121,7 +123,7 @@ public class SSLCtxAccessToSessCtx {
/*
* Wait for server to get started.
*/
while (!serverReady) {
while (serverReady.get() > 0) {
Thread.sleep(50);
}
/*
......@@ -151,8 +153,8 @@ public class SSLCtxAccessToSessCtx {
* The remainder is just support stuff
*/
volatile int serverPorts[] = new int[]{0};
volatile int createdPorts = 0;
int serverPorts[] = new int[]{0}; // only one port at present
AtomicInteger createdPorts = new AtomicInteger(0);
static SSLServerSocketFactory sslssf;
static SSLSocketFactory sslsf;
static SSLContext sslctx;
......@@ -255,14 +257,20 @@ public class SSLCtxAccessToSessCtx {
*/
System.err.println("Server died...");
e.printStackTrace();
serverReady = true;
serverReady.set(0);
serverException = e;
}
}
};
serverThread.start();
} else {
doServerSide(port);
try {
doServerSide(port);
} catch (Exception e) {
serverException = e;
} finally {
serverReady.set(0);
}
}
}
......@@ -284,7 +292,11 @@ public class SSLCtxAccessToSessCtx {
};
clientThread.start();
} else {
doClientSide();
try {
doClientSide();
} catch (Exception e) {
clientException = e;
}
}
}
}
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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
......@@ -28,7 +28,7 @@
/*
* @test
* @bug 4366807
* @bug 4366807
* @summary Need new APIs to get/set session timeout and session cache size.
* @run main/othervm SessionCacheSizeTests
*/
......@@ -108,36 +108,47 @@ public class SessionCacheSizeTests {
void doServerSide(int serverPort, int serverConns) throws Exception {
SSLServerSocket sslServerSocket =
(SSLServerSocket) sslssf.createServerSocket(serverPort);
serverPorts[createdPorts++] = sslServerSocket.getLocalPort();
try (SSLServerSocket sslServerSocket =
(SSLServerSocket) sslssf.createServerSocket(serverPort)) {
/*
* Signal Client, we're ready for his connect.
*/
if (createdPorts == serverPorts.length) {
serverReady = true;
}
int read = 0;
int nConnections = 0;
/*
* Divide the max connections among the available server ports.
* The use of more than one server port ensures creation of more
* than one session.
*/
SSLSession sessions [] = new SSLSession [serverConns];
SSLSessionContext sessCtx = sslctx.getServerSessionContext();
while (nConnections < serverConns) {
SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
InputStream sslIS = sslSocket.getInputStream();
OutputStream sslOS = sslSocket.getOutputStream();
read = sslIS.read();
sessions[nConnections] = sslSocket.getSession();
sslOS.write(85);
sslOS.flush();
sslSocket.close();
nConnections++;
// timeout to accept a connection
sslServerSocket.setSoTimeout(45000);
// make sure createdPorts++ is atomic
synchronized(serverPorts) {
serverPorts[createdPorts++] = sslServerSocket.getLocalPort();
/*
* Signal Client, we're ready for his connect.
*/
if (createdPorts == serverPorts.length) {
serverReady = true;
}
}
int read = 0;
int nConnections = 0;
/*
* Divide the max connections among the available server ports.
* The use of more than one server port ensures creation of more
* than one session.
*/
SSLSession sessions [] = new SSLSession [serverConns];
SSLSessionContext sessCtx = sslctx.getServerSessionContext();
while (nConnections < serverConns) {
try (SSLSocket sslSocket =
(SSLSocket)sslServerSocket.accept()) {
sslSocket.setSoTimeout(90000); // timeout to read
InputStream sslIS = sslSocket.getInputStream();
OutputStream sslOS = sslSocket.getOutputStream();
read = sslIS.read();
sessions[nConnections] = sslSocket.getSession();
sslOS.write(85);
sslOS.flush();
nConnections++;
}
}
}
}
......@@ -263,8 +274,8 @@ public class SessionCacheSizeTests {
* Using four ports (one per each connection), we are able to create
* alteast four sessions.
*/
volatile int serverPorts[] = new int[]{0, 0, 0, 0};
volatile int createdPorts = 0;
int serverPorts[] = new int[]{0, 0, 0, 0}; // MAX_ACTIVE_CONNECTIONS: 4
int createdPorts = 0;
static SSLServerSocketFactory sslssf;
static SSLSocketFactory sslsf;
static SSLContext sslctx;
......
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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
......@@ -36,6 +36,7 @@ import java.net.*;
import javax.net.ssl.*;
import java.util.*;
import java.security.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Session reuse time-out tests cover the cases below:
......@@ -79,7 +80,7 @@ public class SessionTimeOutTests {
/*
* Is the server ready to serve?
*/
volatile static int serverReady = PORTS;
AtomicInteger serverReady = new AtomicInteger(PORTS);
/*
* Turn on SSL debugging?
......@@ -98,7 +99,7 @@ public class SessionTimeOutTests {
/*
* Define the server side of the test.
*
* If the server prematurely exits, serverReady will be set to true
* If the server prematurely exits, serverReady will be set to zero
* to avoid infinite hangs.
*/
......@@ -111,12 +112,13 @@ public class SessionTimeOutTests {
SSLServerSocket sslServerSocket =
(SSLServerSocket) sslssf.createServerSocket(serverPort);
serverPorts[createdPorts++] = sslServerSocket.getLocalPort();
int slot = createdPorts.getAndIncrement();
serverPorts[slot] = sslServerSocket.getLocalPort();
/*
* Signal Client, we're ready for his connect.
*/
serverReady--;
serverReady.getAndDecrement();
int read = 0;
int nConnections = 0;
SSLSession sessions [] = new SSLSession [serverConns];
......@@ -137,7 +139,7 @@ public class SessionTimeOutTests {
/*
* Define the client side of the test.
*
* If the server prematurely exits, serverReady will be set to true
* If the server prematurely exits, serverReady will be set to zero
* to avoid infinite hangs.
*/
void doClientSide() throws Exception {
......@@ -145,7 +147,7 @@ public class SessionTimeOutTests {
/*
* Wait for server to get started.
*/
while (serverReady > 0) {
while (serverReady.get() > 0) {
Thread.sleep(50);
}
......@@ -287,8 +289,8 @@ public class SessionTimeOutTests {
* The remainder is just support stuff
*/
volatile int serverPorts[] = new int[PORTS];
volatile int createdPorts = 0;
int serverPorts[] = new int[PORTS];
AtomicInteger createdPorts = new AtomicInteger(0);
static SSLServerSocketFactory sslssf;
static SSLSocketFactory sslsf;
static SSLContext sslctx;
......@@ -447,7 +449,7 @@ public class SessionTimeOutTests {
*/
System.err.println("Server died...");
e.printStackTrace();
serverReady = 0;
serverReady.set(0);
serverException = e;
}
}
......@@ -459,7 +461,7 @@ public class SessionTimeOutTests {
} catch (Exception e) {
serverException = e;
} finally {
serverReady = 0;
serverReady.set(0);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册