Merge
authorprr
Mon, 21 Mar 2016 09:36:54 -0700
changeset 36895 083dcdaa0c18
parent 36894 12569df8755e (current diff)
parent 36645 dd51a5761eec (diff)
child 36896 d854fedad94e
Merge
--- a/jdk/test/java/nio/channels/AsyncCloseAndInterrupt.java	Fri Mar 18 11:07:25 2016 -0700
+++ b/jdk/test/java/nio/channels/AsyncCloseAndInterrupt.java	Mon Mar 21 09:36:54 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -23,6 +23,7 @@
 
 /* @test
  * @bug 4460583 4470470 4840199 6419424 6710579 6596323 6824135 6395224 7142919
+ *      8151582
  * @run main/othervm AsyncCloseAndInterrupt
  * @summary Comprehensive test of asynchronous closing and interruption
  * @author Mark Reinhold
@@ -89,7 +90,7 @@
 
     private static void initRefuser() throws IOException {
         refuser = ServerSocketChannel.open();
-        refuser.socket().bind(wildcardAddress);
+        refuser.bind(wildcardAddress, 1);      // use minimum backlog
     }
 
     // Dead pipe source and sink
@@ -349,7 +350,7 @@
 
     static final Op CONNECT = new Op("connect") {
             void setup() {
-                waitPump("connect wait for pumping refuser ...");
+                waitPump("connect waiting for pumping refuser ...");
             }
             void doIO(InterruptibleChannel ich) throws IOException {
                 SocketChannel sc = (SocketChannel)ich;
@@ -361,7 +362,7 @@
 
     static final Op FINISH_CONNECT = new Op("finishConnect") {
             void setup() {
-                waitPump("finishConnect wait for pumping refuser ...");
+                waitPump("finishConnect waiting for pumping refuser ...");
             }
             void doIO(InterruptibleChannel ich) throws IOException {
                 SocketChannel sc = (SocketChannel)ich;
@@ -498,12 +499,11 @@
     private static volatile boolean pumpReady = false;
 
     private static void waitPump(String msg){
-        pumpReady = false;
         log.println(msg);
-
         while (!pumpReady){
             sleep(200);
         }
+        log.println(msg + " done");
     }
 
     // Create a pump thread dedicated to saturate refuser's connection backlog
@@ -520,28 +520,34 @@
 
                 // Saturate the refuser's connection backlog so that further connection
                 // attempts will be blocked
+                pumpReady = false;
                 while (!pumpDone) {
                     SocketChannel sc = SocketChannel.open();
                     sc.configureBlocking(false);
                     boolean connected = sc.connect(refuser.socket().getLocalSocketAddress());
 
                     // Assume that the connection backlog is saturated if a
-                    // client cannot connect to the refuser within 50 miliseconds
+                    // client cannot connect to the refuser within 50 milliseconds
                     long start = System.currentTimeMillis();
-                    while (!connected && (System.currentTimeMillis() - start < 50)) {
+                    while (!pumpReady && !connected
+                            && (System.currentTimeMillis() - start < 50)) {
                         connected = sc.finishConnect();
                     }
 
                     if (connected) {
                         // Retain so that finalizer doesn't close
                         refuserClients.add(sc);
-                        pumpReady = false;
                     } else {
                         sc.close();
                         pumpReady = true;
                     }
                 }
 
+                for (SocketChannel sc : refuserClients) {
+                    sc.close();
+                }
+                refuser.close();
+
                 log.println("Stop pumping refuser ...");
                 return refuserClients.size();
             }
@@ -565,8 +571,6 @@
             sleep(50);
         } while (!t.ready);
 
-        sleep(100);
-
         switch (test) {
 
         case TEST_INTR:
--- a/jdk/test/javax/net/ssl/templates/SSLSocketSSLEngineTemplate.java	Fri Mar 18 11:07:25 2016 -0700
+++ b/jdk/test/javax/net/ssl/templates/SSLSocketSSLEngineTemplate.java	Mon Mar 21 09:36:54 2016 -0700
@@ -101,9 +101,6 @@
     private static final boolean debug = false;
     private final SSLContext sslc;
     private SSLEngine serverEngine;     // server-side SSLEngine
-    private SSLSocket sslSocket;        // client-side socket
-    private ServerSocket serverSocket;  // server-side Socket, generates the...
-    private Socket socket;              // server-side socket that will read
 
     private final byte[] serverMsg =
         "Hi there Client, I'm a Server.".getBytes();
@@ -217,132 +214,128 @@
     private void runTest(boolean direct) throws Exception {
         boolean serverClose = direct;
 
-        serverSocket = new ServerSocket();
-        serverSocket.setReuseAddress(false);
-        serverSocket.bind(null);
-        int port = serverSocket.getLocalPort();
-        Thread thread = createClientThread(port, serverClose);
+        // generates the server-side Socket
+        try (ServerSocket serverSocket = new ServerSocket()) {
+            serverSocket.setReuseAddress(false);
+            serverSocket.bind(null);
+            int port = serverSocket.getLocalPort();
+            Thread thread = createClientThread(port, serverClose);
 
-        socket = serverSocket.accept();
-        socket.setSoTimeout(500);
-        serverSocket.close();
-
-        createSSLEngine();
-        createBuffers(direct);
-
-        try {
-            boolean closed = false;
-            // will try to read one more time in case client message
-            // is fragmented to multiple pieces
-            boolean retry = true;
+            createSSLEngine();
+            createBuffers(direct);
 
-            InputStream is = socket.getInputStream();
-            OutputStream os = socket.getOutputStream();
-
-            SSLEngineResult serverResult;   // results from last operation
+            // server-side socket that will read
+            try (Socket socket = serverSocket.accept()) {
+                socket.setSoTimeout(500);
 
-            /*
-             * Examining the SSLEngineResults could be much more involved,
-             * and may alter the overall flow of the application.
-             *
-             * For example, if we received a BUFFER_OVERFLOW when trying
-             * to write to the output pipe, we could reallocate a larger
-             * pipe, but instead we wait for the peer to drain it.
-             */
-            byte[] inbound = new byte[8192];
-            byte[] outbound = new byte[8192];
+                boolean closed = false;
+                // will try to read one more time in case client message
+                // is fragmented to multiple pieces
+                boolean retry = true;
 
-            while (!isEngineClosed(serverEngine)) {
-                int len;
+                InputStream is = socket.getInputStream();
+                OutputStream os = socket.getOutputStream();
 
-                // Inbound data
-                log("================");
+                SSLEngineResult serverResult;   // results from last operation
 
-                // Read from the Client side.
-                try {
-                    len = is.read(inbound);
-                    if (len == -1) {
-                        throw new Exception("Unexpected EOF");
-                    }
-                    cTOs.put(inbound, 0, len);
-                } catch (SocketTimeoutException ste) {
-                    // swallow.  Nothing yet, probably waiting on us.
-                }
-
-                cTOs.flip();
-
-                serverResult = serverEngine.unwrap(cTOs, serverIn);
-                log("server unwrap: ", serverResult);
-                runDelegatedTasks(serverResult, serverEngine);
-                cTOs.compact();
-
-                // Outbound data
-                log("----");
-
-                serverResult = serverEngine.wrap(serverOut, sTOc);
-                log("server wrap: ", serverResult);
-                runDelegatedTasks(serverResult, serverEngine);
-
-                sTOc.flip();
+                /*
+                 * Examining the SSLEngineResults could be much more involved,
+                 * and may alter the overall flow of the application.
+                 *
+                 * For example, if we received a BUFFER_OVERFLOW when trying
+                 * to write to the output pipe, we could reallocate a larger
+                 * pipe, but instead we wait for the peer to drain it.
+                 */
+                byte[] inbound = new byte[8192];
+                byte[] outbound = new byte[8192];
 
-                if ((len = sTOc.remaining()) != 0) {
-                    sTOc.get(outbound, 0, len);
-                    os.write(outbound, 0, len);
-                    // Give the other side a chance to process
-                }
+                while (!isEngineClosed(serverEngine)) {
+                    int len;
 
-                sTOc.compact();
-
-                if (!closed && (serverOut.remaining() == 0)) {
-                    closed = true;
+                    // Inbound data
+                    log("================");
 
-                    /*
-                     * We'll alternate initiatating the shutdown.
-                     * When the server initiates, it will take one more
-                     * loop, but tests the orderly shutdown.
-                     */
-                    if (serverClose) {
-                        serverEngine.closeOutbound();
-                    }
-                    serverIn.flip();
-
-                    /*
-                     * A sanity check to ensure we got what was sent.
-                     */
-                    if (serverIn.remaining() !=  clientMsg.length) {
-                        if (retry && serverIn.remaining() < clientMsg.length) {
-                            log("Need to read more from client");
-                            retry = false;
-                            continue;
-                        } else {
-                            throw new Exception("Client:  Data length error");
+                    // Read from the Client side.
+                    try {
+                        len = is.read(inbound);
+                        if (len == -1) {
+                            throw new Exception("Unexpected EOF");
                         }
+                        cTOs.put(inbound, 0, len);
+                    } catch (SocketTimeoutException ste) {
+                        // swallow.  Nothing yet, probably waiting on us.
                     }
 
-                    for (int i = 0; i < clientMsg.length; i++) {
-                        if (clientMsg[i] != serverIn.get()) {
-                            throw new Exception("Client:  Data content error");
+                    cTOs.flip();
+
+                    serverResult = serverEngine.unwrap(cTOs, serverIn);
+                    log("server unwrap: ", serverResult);
+                    runDelegatedTasks(serverResult, serverEngine);
+                    cTOs.compact();
+
+                    // Outbound data
+                    log("----");
+
+                    serverResult = serverEngine.wrap(serverOut, sTOc);
+                    log("server wrap: ", serverResult);
+                    runDelegatedTasks(serverResult, serverEngine);
+
+                    sTOc.flip();
+
+                    if ((len = sTOc.remaining()) != 0) {
+                        sTOc.get(outbound, 0, len);
+                        os.write(outbound, 0, len);
+                        // Give the other side a chance to process
+                    }
+
+                    sTOc.compact();
+
+                    if (!closed && (serverOut.remaining() == 0)) {
+                        closed = true;
+
+                        /*
+                         * We'll alternate initiatating the shutdown.
+                         * When the server initiates, it will take one more
+                         * loop, but tests the orderly shutdown.
+                         */
+                        if (serverClose) {
+                            serverEngine.closeOutbound();
                         }
+                        serverIn.flip();
+
+                        /*
+                         * A sanity check to ensure we got what was sent.
+                         */
+                        if (serverIn.remaining() !=  clientMsg.length) {
+                            if (retry &&
+                                    serverIn.remaining() < clientMsg.length) {
+                                log("Need to read more from client");
+                                retry = false;
+                                continue;
+                            } else {
+                                throw new Exception(
+                                        "Client: Data length error");
+                            }
+                        }
+
+                        for (int i = 0; i < clientMsg.length; i++) {
+                            if (clientMsg[i] != serverIn.get()) {
+                                throw new Exception(
+                                        "Client: Data content error");
+                            }
+                        }
+                        serverIn.compact();
                     }
-                    serverIn.compact();
+                }
+            } catch (Exception e) {
+                serverException = e;
+            } finally {
+                // Wait for the client to join up with us.
+                if (thread != null) {
+                    thread.join();
                 }
             }
-        } catch (Exception e) {
-            serverException = e;
         } finally {
-            if (socket != null) {
-                socket.close();
-            }
-
-            // Wait for the client to join up with us.
-            if (thread != null) {
-                thread.join();
-            }
-
-            if (sslSocket != null) {
-                sslSocket.close();
-            }
-
             if (serverException != null) {
                 if (clientException != null) {
                     serverException.initCause(clientException);
@@ -369,11 +362,9 @@
 
             @Override
             public void run() {
-                try {
-                    Thread.sleep(1000);  // Give server time to finish setup.
-
-                    sslSocket = (SSLSocket) sslc.getSocketFactory().
-                            createSocket("localhost", port);
+                // client-side socket
+                try (SSLSocket sslSocket = (SSLSocket)sslc.getSocketFactory().
+                            createSocket("localhost", port)) {
                     OutputStream os = sslSocket.getOutputStream();
                     InputStream is = sslSocket.getInputStream();
 
--- a/jdk/test/javax/net/ssl/templates/SSLSocketTemplate.java	Fri Mar 18 11:07:25 2016 -0700
+++ b/jdk/test/javax/net/ssl/templates/SSLSocketTemplate.java	Mon Mar 21 09:36:54 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2015, 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
@@ -85,26 +85,26 @@
      */
     void doServerSide() throws Exception {
         SSLServerSocketFactory sslssf =
-            (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
-        SSLServerSocket sslServerSocket =
-            (SSLServerSocket) sslssf.createServerSocket(serverPort);
+            (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
+        try (SSLServerSocket sslServerSocket =
+                (SSLServerSocket)sslssf.createServerSocket(serverPort)) {
 
-        serverPort = sslServerSocket.getLocalPort();
+            serverPort = sslServerSocket.getLocalPort();
 
-        /*
-         * Signal Client, we're ready for his connect.
-         */
-        serverReady = true;
+            /*
+             * Signal Client, we're ready for his connect.
+             */
+            serverReady = true;
 
-        SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
-        InputStream sslIS = sslSocket.getInputStream();
-        OutputStream sslOS = sslSocket.getOutputStream();
+            try (SSLSocket sslSocket = (SSLSocket)sslServerSocket.accept()) {
+                InputStream sslIS = sslSocket.getInputStream();
+                OutputStream sslOS = sslSocket.getOutputStream();
 
-        sslIS.read();
-        sslOS.write(85);
-        sslOS.flush();
-
-        sslSocket.close();
+                sslIS.read();
+                sslOS.write(85);
+                sslOS.flush();
+            }
+        }
     }
 
     /*
@@ -123,18 +123,17 @@
         }
 
         SSLSocketFactory sslsf =
-            (SSLSocketFactory) SSLSocketFactory.getDefault();
-        SSLSocket sslSocket = (SSLSocket)
-            sslsf.createSocket("localhost", serverPort);
+            (SSLSocketFactory)SSLSocketFactory.getDefault();
+        try (SSLSocket sslSocket =
+                (SSLSocket)sslsf.createSocket("localhost", serverPort)) {
 
-        InputStream sslIS = sslSocket.getInputStream();
-        OutputStream sslOS = sslSocket.getOutputStream();
+            InputStream sslIS = sslSocket.getInputStream();
+            OutputStream sslOS = sslSocket.getOutputStream();
 
-        sslOS.write(280);
-        sslOS.flush();
-        sslIS.read();
-
-        sslSocket.close();
+            sslOS.write(280);
+            sslOS.flush();
+            sslIS.read();
+        }
     }
 
     /*
--- a/jdk/test/jdk/internal/jline/console/StripAnsiTest.java	Fri Mar 18 11:07:25 2016 -0700
+++ b/jdk/test/jdk/internal/jline/console/StripAnsiTest.java	Mon Mar 21 09:36:54 2016 -0700
@@ -23,14 +23,16 @@
 
 /**
  * @test
- * @bug 8080679
- * @modules jdk.internal.le/jdk.internal.jline.console
+ * @bug 8080679 8131913
+ * @modules jdk.internal.le/jdk.internal.jline
+ *          jdk.internal.le/jdk.internal.jline.console
  * @summary Verify ConsoleReader.stripAnsi strips escape sequences from its input correctly.
  */
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.lang.reflect.Method;
+import jdk.internal.jline.UnsupportedTerminal;
 import jdk.internal.jline.console.ConsoleReader;
 
 public class StripAnsiTest {
@@ -41,7 +43,7 @@
     void run() throws Exception {
         ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        ConsoleReader reader = new ConsoleReader(in, out);
+        ConsoleReader reader = new ConsoleReader(in, out, new UnsupportedTerminal());
 
         String withAnsi = "0\033[s1\033[2J2\033[37;4m3";
         String expected = "0123";
--- a/jdk/test/sun/net/idn/TestStringPrep.java	Fri Mar 18 11:07:25 2016 -0700
+++ b/jdk/test/sun/net/idn/TestStringPrep.java	Mon Mar 21 09:36:54 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -24,7 +24,7 @@
 /*
  * @test
  * @summary Unit test for sun.net.idn.Punycode
- * @bug 4737170
+ * @bug 4737170 8060097
  * @modules java.base/sun.net.idn java.base/sun.text.normalizer
  * @library .
  * @compile -XDignore.symbol.file TestStringPrep.java NFS4StringPrep.java
@@ -41,6 +41,7 @@
 
 import java.text.ParseException;
 import java.io.InputStream;
+import java.util.Locale;
 
 import sun.net.idn.StringPrep;
 import sun.text.normalizer.UCharacterIterator;
@@ -209,7 +210,7 @@
             src = "THISISATEST";
             byte[] dest = NFS4StringPrep.cs_prepare(src.getBytes("UTF-8"), false);
             String destStr = new String(dest, "UTF-8");
-            if(!src.toLowerCase().equals(destStr)){
+            if(!src.toLowerCase(Locale.ROOT).equals(destStr)){
                 fail("Did not get expected output. Expected: "+ prettify(src)+
                       " Got: " + prettify(destStr));
             }
@@ -274,7 +275,7 @@
 
     private static String hex(char ch) {
         StringBuffer result = new StringBuffer();
-        String foo = Integer.toString(ch,16).toUpperCase();
+        String foo = Integer.toString(ch,16).toUpperCase(Locale.ROOT);
         for (int i = foo.length(); i < 4; ++i) {
             result.append('0');
         }