16
16
17
17
public class TunnelingJdkSocketTest {
18
18
19
- private static final AtomicBoolean is_server_running = new AtomicBoolean (false );
20
- private final int client_timeout = 1000 ;
21
- private final int test_timeout = 3000 ;
19
+ private static final AtomicBoolean isServerRunning = new AtomicBoolean (false );
20
+ private final int clientTimeout = 1000 ;
21
+ private final int testTimeout = 3000 ;
22
22
23
23
@ Test
24
24
public void testTimeout () throws Exception {
@@ -28,10 +28,10 @@ public void testTimeout() throws Exception {
28
28
TunnelingJdkSocket clientSocket = createClient (socketPath );
29
29
30
30
assertTimeoutPreemptively (
31
- Duration .ofMillis (test_timeout ), () -> clientSocket .getInputStream ().read ());
31
+ Duration .ofMillis (testTimeout ), () -> clientSocket .getInputStream ().read ());
32
32
33
33
clientSocket .close ();
34
- is_server_running .set (false );
34
+ isServerRunning .set (false );
35
35
}
36
36
37
37
private Path getSocketPath () throws IOException {
@@ -48,22 +48,36 @@ private static void startServer(UnixDomainSocketAddress socketAddress) {
48
48
try (ServerSocketChannel serverChannel =
49
49
ServerSocketChannel .open (StandardProtocolFamily .UNIX )) {
50
50
serverChannel .bind (socketAddress );
51
- is_server_running .set (true );
51
+ isServerRunning .set (true );
52
52
53
- while (is_server_running .get ()) {
53
+ synchronized (isServerRunning ) {
54
+ isServerRunning .notifyAll ();
55
+ }
56
+
57
+ while (isServerRunning .get ()) {
54
58
SocketChannel clientChannel = serverChannel .accept ();
55
59
}
56
60
} catch (IOException e ) {
57
61
throw new RuntimeException (e );
58
62
}
59
63
});
60
64
serverThread .start ();
65
+
66
+ synchronized (isServerRunning ) {
67
+ while (!isServerRunning .get ()) {
68
+ try {
69
+ isServerRunning .wait ();
70
+ } catch (InterruptedException e ) {
71
+ throw new RuntimeException (e );
72
+ }
73
+ }
74
+ }
61
75
}
62
76
63
77
private TunnelingJdkSocket createClient (Path socketPath ) throws IOException {
64
78
TunnelingJdkSocket clientSocket = new TunnelingJdkSocket (socketPath );
65
79
clientSocket .connect (new InetSocketAddress ("localhost" , 0 ));
66
- clientSocket .setSoTimeout (client_timeout );
80
+ clientSocket .setSoTimeout (clientTimeout );
67
81
return clientSocket ;
68
82
}
69
83
}
0 commit comments