Update the ssl test so the client reads something from the server.
This is needed when cut-through feature is needed as in b/2586347.
Dr. No approved in http://b/issue?id=2511073 .

Change-Id: Id84724873522fe0435dbda342616da02783f7d6b
diff --git a/libcore/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java b/libcore/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java
index fa36d0c..aebde6b 100644
--- a/libcore/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java
+++ b/libcore/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java
@@ -500,8 +500,8 @@
     
     /** 
      * Implements a test SSL socket server. It wait for a connection on a given
-     * port, requests client authentication (if specified), and read 256 bytes
-     * from the socket. 
+     * port, requests client authentication (if specified), reads 256 bytes
+     * from the socket, and writes 256 bytes to the socket.
      */
     class TestServer implements Runnable {
 
@@ -551,16 +551,26 @@
                 
                 SSLSocket clientSocket = (SSLSocket)serverSocket.accept();
 
-                InputStream stream = clientSocket.getInputStream();
+                InputStream istream = clientSocket.getInputStream();
 
                 for (int i = 0; i < 256; i++) {
-                    int j = stream.read();
+                    int j = istream.read();
                     if (i != j) {
                         throw new RuntimeException("Error reading socket, expected " + i + ", got " + j);
                     }
                 }
                 
-                stream.close();
+                istream.close();
+
+                OutputStream ostream = clientSocket.getOutputStream();
+
+                for (int i = 0; i < 256; i++) {
+                    ostream.write(i);
+                }
+
+                ostream.flush();
+                ostream.close();
+
                 clientSocket.close();
                 serverSocket.close();
                 
@@ -581,7 +591,8 @@
 
     /** 
      * Implements a test SSL socket client. It open a connection to localhost on
-     * a given port and writes 256 bytes to the socket. 
+     * a given port, writes 256 bytes to the socket, and reads 256 bytes from the
+     * socket.
      */
     class TestClient implements Runnable {
         
@@ -614,14 +625,26 @@
                 socket.addHandshakeCompletedListener(listener);
                 socket.startHandshake();
 
-                OutputStream stream = socket.getOutputStream();
+                OutputStream ostream = socket.getOutputStream();
                 
                 for (int i = 0; i < 256; i++) {
-                    stream.write(i);
+                    ostream.write(i);
                 }
                 
-                stream.flush();
-                stream.close();
+                ostream.flush();
+                ostream.close();
+
+                InputStream istream = socket.getInputStream();
+
+                for (int i = 0; i < 256; i++) {
+                    int j = istream.read();
+                    if (i != j) {
+                        throw new RuntimeException("Error reading socket, expected " + i + ", got " + j);
+                    }
+                }
+
+                istream.close();
+
                 socket.close();
                 
             } catch (Exception ex) {
@@ -649,7 +672,7 @@
         KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
         keyStore.load(inputStream, PASSWORD.toCharArray());
         inputStream.close();
-        
+
         String algorithm = KeyManagerFactory.getDefaultAlgorithm();
         KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(algorithm);
         keyManagerFactory.init(keyStore, PASSWORD.toCharArray());
diff --git a/libcore/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java b/libcore/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java
index 430d117..384084f 100644
--- a/libcore/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java
+++ b/libcore/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java
@@ -706,8 +706,8 @@
 
     /** 
      * Implements a test SSL socket server. It waits for a connection on a given
-     * port, requests client authentication (if specified), and reads
-     * from the socket. 
+     * port, requests client authentication (if specified), reads from the socket,
+     * and writes to the socket.
      */
     class TestServer implements Runnable {
 
@@ -761,8 +761,16 @@
                 
                 SSLSocket clientSocket = (SSLSocket)serverSocket.accept();
 
+                InputStream istream = clientSocket.getInputStream();
+                byte[] buffer = new byte[1024];
+                istream.read(buffer);
+
+                OutputStream ostream = clientSocket.getOutputStream();
+                ostream.write(testData.getBytes());
+                ostream.flush();
+
                 while (notFinished) {
-                    clientSocket.getInputStream().read();
+                    Thread.currentThread().sleep(500);
                 }
 
                 clientSocket.close();
@@ -788,8 +796,8 @@
     }
 
     /** 
-     * Implements a test SSL socket client. It open a connection to localhost on
-     * a given port and writes to the socket. 
+     * Implements a test SSL socket client. It opens a connection to localhost on
+     * a given port, writes to the socket, and reads from the socket.
      */
     class TestClient implements Runnable {
         
@@ -826,6 +834,10 @@
                 ostream.write(testData.getBytes());
                 ostream.flush();
 
+                InputStream istream = socket.getInputStream();
+                byte[] buffer = new byte[1024];
+                istream.read(buffer);
+
                 clientSession = socket.getSession();
                 while (notFinished) {
                     Thread.currentThread().sleep(500);