Skip to content

Commit 9a713a9

Browse files
committed
5cd4fe63768715ec7be32e248e05e611ea9b557d
1 parent 8cdbe42 commit 9a713a9

File tree

5 files changed

+56
-49
lines changed

5 files changed

+56
-49
lines changed

test/jdk/javax/net/ssl/templates/TLSBase.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,10 +31,7 @@
3131
import java.security.cert.X509CertSelector;
3232
import java.util.ArrayList;
3333
import java.util.List;
34-
import java.util.concurrent.ConcurrentHashMap;
35-
import java.util.concurrent.ExecutorService;
36-
import java.util.concurrent.Executors;
37-
import java.util.concurrent.TimeUnit;
34+
import java.util.concurrent.*;
3835

3936
/**
4037
* This is a base setup for creating a server and clients. All clients will
@@ -84,14 +81,16 @@ abstract public class TLSBase {
8481
byte[] read(SSLSocket sock) throws Exception {
8582
BufferedInputStream is = new BufferedInputStream(sock.getInputStream());
8683
byte[] b = is.readNBytes(5);
87-
System.err.println("(read) " + Thread.currentThread().getName() + ": " + new String(b));
84+
System.err.println("(read) " + Thread.currentThread().getName() + ": " +
85+
new String(b));
8886
return b;
8987
}
9088

9189
// Base write operation
9290
public void write(SSLSocket sock, byte[] data) throws Exception {
9391
sock.getOutputStream().write(data);
94-
System.err.println("(write)" + Thread.currentThread().getName() + ": " + new String(data));
92+
System.err.println("(write)" + Thread.currentThread().getName() + ": " +
93+
new String(data));
9594
}
9695

9796
private static KeyManager[] getKeyManager(boolean empty) throws Exception {
@@ -148,14 +147,9 @@ static class Server extends TLSBase {
148147
// Clients sockets are kept in a hash table with the port as the key.
149148
ConcurrentHashMap<Integer, SSLSocket> clientMap =
150149
new ConcurrentHashMap<>();
151-
Thread t;
152150
List<Exception> exceptionList = new ArrayList<>();
153-
ExecutorService threadPool = Executors.newFixedThreadPool(1,
154-
r -> {
155-
Thread t = Executors.defaultThreadFactory().newThread(r);
156-
return t;
157-
});
158-
151+
ExecutorService threadPool = Executors.newFixedThreadPool(1);
152+
CountDownLatch serverLatch = new CountDownLatch(1);
159153
Server(ServerBuilder builder) {
160154
super();
161155
name = "server";
@@ -168,43 +162,45 @@ static class Server extends TLSBase {
168162
ssock.setReuseAddress(true);
169163
ssock.setNeedClientAuth(builder.clientauth);
170164
serverPort = ssock.getLocalPort();
171-
System.out.println("Server Port: " + serverPort);
165+
System.err.println("Server Port: " + serverPort);
172166
} catch (Exception e) {
173167
System.err.println("Failure during server initialization");
174168
e.printStackTrace();
175169
}
176170

177171
// Thread to allow multiple clients to connect
178-
t = new Thread(() -> {
172+
new Thread(() -> {
179173
try {
180-
while (true) {
174+
System.err.println("Server starting to accept");
175+
serverLatch.countDown();
176+
do {
181177
SSLSocket sock = (SSLSocket)ssock.accept();
182178
threadPool.submit(new ServerThread(sock));
183-
}
179+
} while (true);
184180
} catch (Exception ex) {
185181
System.err.println("Server Down");
186182
ex.printStackTrace();
187183
} finally {
188184
threadPool.close();
189185
}
190-
});
191-
t.start();
186+
}).start();
192187
}
193188

194189
class ServerThread extends Thread {
195190
SSLSocket sock;
196191

197192
ServerThread(SSLSocket s) {
198193
this.sock = s;
199-
System.err.println("ServerThread("+sock.getPort()+")");
194+
System.err.println("(Server) client connection on port " +
195+
sock.getPort());
200196
clientMap.put(sock.getPort(), sock);
201197
}
202198

203199
public void run() {
204200
try {
205201
write(sock, read(sock));
206202
} catch (Exception e) {
207-
System.out.println("Caught " + e.getMessage());
203+
System.err.println("Caught " + e.getMessage());
208204
e.printStackTrace();
209205
exceptionList.add(e);
210206
}
@@ -289,7 +285,8 @@ static class Client extends TLSBase {
289285
this.tm = tm;
290286
try {
291287
sslContext = SSLContext.getInstance("TLS");
292-
sslContext.init(TLSBase.getKeyManager(km), TLSBase.getTrustManager(tm), null);
288+
sslContext.init(TLSBase.getKeyManager(km),
289+
TLSBase.getTrustManager(tm), null);
293290
socket = createSocket();
294291
} catch (Exception ex) {
295292
ex.printStackTrace();
@@ -312,9 +309,12 @@ public SSLSocket createSocket() {
312309

313310
public SSLSocket connect() {
314311
try {
315-
socket.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), serverPort));
316-
System.err.println("Client (" + Thread.currentThread().getName() + ") connected using port " +
317-
socket.getLocalPort() + " to " + socket.getPort());
312+
socket.connect(new InetSocketAddress(
313+
InetAddress.getLoopbackAddress(), serverPort));
314+
System.err.println("Client (" +
315+
Thread.currentThread().getName() +
316+
") connected using port " + socket.getLocalPort() + " to " +
317+
socket.getPort());
318318
writeRead();
319319
} catch (Exception ex) {
320320
ex.printStackTrace();

test/jdk/sun/security/ssl/SSLSessionImpl/MultiNSTClient.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public static void main(String[] args) throws Exception {
8181
Utils.addTestJavaOpts("MultiNSTClient", "p"));
8282

8383
OutputAnalyzer output = ProcessTools.executeProcess(pb);
84-
System.out.println("I'm here");
8584
boolean pass = true;
8685
try {
8786
List<String> list = output.stderrShouldContain("MultiNST PSK").
@@ -99,10 +98,12 @@ public static void main(String[] args) throws Exception {
9998
for (int i = 0; i < 2; i++) {
10099
String svr = serverPSK.getFirst();
101100
String cli = clientPSK.getFirst();
102-
if (svr.regionMatches(svr.length() - 16, cli, cli.length() - 16, 16)) {
101+
if (svr.regionMatches(svr.length() - 16, cli,
102+
cli.length() - 16, 16)) {
103103
System.out.println("entry " + (i + 1) + " match.");
104104
} else {
105-
System.out.println("entry " + (i + 1) + " server and client PSK didn't match:");
105+
System.out.println("entry " + (i + 1) +
106+
" server and client PSK didn't match:");
106107
System.out.println(" server: " + svr);
107108
System.out.println(" client: " + cli);
108109
pass = false;
@@ -127,8 +128,8 @@ public static void main(String[] args) throws Exception {
127128
}
128129

129130
TLSBase.Server server = new TLSBase.Server();
130-
131-
System.out.println("------ Start connection");
131+
server.serverLatch.await();
132+
System.out.println("------ Server ready, starting original client.");
132133
TLSBase.Client initial = new TLSBase.Client();
133134
SSLSession initialSession = initial.connect().getSession();
134135
System.out.println("id = " + hex.formatHex(initialSession.getId()));

test/jdk/sun/security/ssl/SSLSessionImpl/MultiNSTNoSessionCreation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public static void main(String[] args) throws Exception {
7676
}
7777

7878
TLSBase.Server server = new TLSBase.Server();
79-
80-
System.out.println("------ Initial connection");
79+
server.serverLatch.await();
80+
System.out.println("------ Server ready, starting initial client.");
8181
TLSBase.Client initial = new TLSBase.Client();
8282
initial.connect();
8383
System.out.println(

test/jdk/sun/security/ssl/SSLSessionImpl/MultiNSTParallel.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static class ClientThread extends Thread {
7373
public void run() {
7474
String name = Thread.currentThread().getName();
7575
SSLSession r;
76-
System.err.println("waiting " + Thread.currentThread().getName());
76+
System.err.println(name + " is ready");
7777
try {
7878
wait.await();
7979
r = new TLSBase.Client(client).connect().getSession();
@@ -84,6 +84,7 @@ public void run() {
8484
sb.append("(").append(name).append(") id = ");
8585
sb.append(hex.formatHex(r.getId()));
8686
sb.append("\n(").append(name).append(") session = ").append(r);
87+
System.err.println(sb);
8788
if (!client.getSession().toString().equalsIgnoreCase(r.toString())) {
8889
throw new RuntimeException("(" + name +
8990
") Resumed session did not match");
@@ -133,7 +134,14 @@ public static void main(String[] args) throws Exception {
133134
serverPSK.stream().forEach(s -> System.out.println("\t" + s));
134135
System.out.println("found client: " + clientPSK.size());
135136
clientPSK.stream().forEach(s -> System.out.println("\t" + s));
136-
137+
if (list.size() == 0 || serverPSK.size() == 0) {
138+
throw new Exception("Error setting up test. No server " +
139+
"PSKs found in debug log.");
140+
}
141+
if (clientPSK.size() == 0) {
142+
throw new Exception("Error setting up test. No " +
143+
"client PSKs found in debug log.");
144+
}
137145
// Must search all results as order is not guaranteed.
138146
clientPSK.stream().forEach(cli -> {
139147
for (int i = 0; i < serverPSK.size(); i++) {
@@ -171,21 +179,20 @@ public static void main(String[] args) throws Exception {
171179
System.getProperty("jdk.tls.server.newSessionTicketCount"));
172180

173181
TLSBase.Server server = new TLSBase.Server();
174-
175-
System.out.println("------ Start connection");
176-
TLSBase.Client initial = new TLSBase.Client();
177-
SSLSession initialSession = initial.getSession();
182+
server.serverLatch.await();
183+
System.out.println("------ Server ready, starting initial client.");
184+
TLSBase.Client initialClient = new TLSBase.Client();
185+
SSLSession initialSession = initialClient.connect().getSession();
178186
System.out.println("id = " + hex.formatHex(initialSession.getId()));
179187
System.out.println("session = " + initialSession);
180-
181-
System.out.println("------ getNewSession from original client");
188+
System.out.println("------ Initial client context ready.");
182189

183190
ArrayList<Thread> slist = new ArrayList<>(ticketCount);
184191

185-
System.out.println("tx " + ticketCount);
192+
System.out.println("Client count = " + ticketCount);
186193
for (int i = 0; ticketCount > i; i++) {
187-
Thread t = new ClientThread(initial);
188-
t.setName("Iteration " + i);
194+
Thread t = new ClientThread(initialClient);
195+
t.setName("client " + i);
189196
slist.add(t);
190197
t.start();
191198
}
@@ -197,7 +204,7 @@ public static void main(String[] args) throws Exception {
197204
}
198205

199206
System.out.println("------ Closing connections");
200-
initial.close();
207+
initialClient.close();
201208
server.close();
202209
System.out.println("------ End");
203210
System.exit(0);

test/jdk/sun/security/ssl/SSLSessionImpl/MultiNSTSequence.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ public static void main(String[] args) throws Exception {
6464
"-Dtest.src=" + System.getProperty("test.src") +
6565
" -Dtest.jdk=" + System.getProperty("test.jdk") +
6666
" -Dtest.root=" + System.getProperty("test.root") +
67-
" -Djavax.net.debug=ssl,handshake " + params
68-
);
67+
" -Djavax.net.debug=ssl,handshake " + params);
6968

7069
System.out.println("test.java.opts: " +
7170
System.getProperty("test.java.opts"));
@@ -115,8 +114,8 @@ public static void main(String[] args) throws Exception {
115114
}
116115

117116
TLSBase.Server server = new TLSBase.Server();
118-
119-
System.out.println("------ Initial connection");
117+
server.serverLatch.await();
118+
System.out.println("------ Server ready, starting initial client.");
120119
TLSBase.Client initial = new TLSBase.Client();
121120

122121
SSLSession initialSession = initial.connect().getSession();

0 commit comments

Comments
 (0)