8144313: Test SessionTimeOutTests can be timeout
authorxuelei
Wed, 02 Dec 2015 15:22:50 +0000
changeset 34387 92a5f8d50d1a
parent 34386 80c21b82e467
child 34388 ab5f741f776a
8144313: Test SessionTimeOutTests can be timeout Reviewed-by: mullan
jdk/test/javax/net/ssl/SSLSession/SessionTimeOutTests.java
--- a/jdk/test/javax/net/ssl/SSLSession/SessionTimeOutTests.java	Wed Dec 02 10:15:26 2015 -0500
+++ b/jdk/test/javax/net/ssl/SSLSession/SessionTimeOutTests.java	Wed Dec 02 15:22:50 2015 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015, 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 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 @@
     /*
      * Is the server ready to serve?
      */
-    volatile static int serverReady = PORTS;
+    AtomicInteger serverReady = new AtomicInteger(PORTS);
 
     /*
      * Turn on SSL debugging?
@@ -98,7 +99,7 @@
     /*
      * 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.
      */
 
@@ -116,7 +117,7 @@
         /*
          * Signal Client, we're ready for his connect.
          */
-        serverReady--;
+        serverReady.getAndDecrement();
         int read = 0;
         int nConnections = 0;
         SSLSession sessions [] = new SSLSession [serverConns];
@@ -137,7 +138,7 @@
     /*
      * 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 +146,7 @@
         /*
          * Wait for server to get started.
          */
-        while (serverReady > 0) {
+        while (serverReady.get() > 0) {
             Thread.sleep(50);
         }
 
@@ -447,7 +448,7 @@
                          */
                         System.err.println("Server died...");
                         e.printStackTrace();
-                        serverReady = 0;
+                        serverReady.set(0);
                         serverException = e;
                     }
                 }
@@ -459,7 +460,7 @@
             } catch (Exception e) {
                 serverException = e;
             } finally {
-                serverReady = 0;
+                serverReady.set(0);
             }
         }
     }