harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r832360 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixSocketTest.java
Date Tue, 03 Nov 2009 09:29:01 GMT
Author: regisxu
Date: Tue Nov  3 09:29:01 2009
New Revision: 832360

URL: http://svn.apache.org/viewvc?rev=832360&view=rev
Log:
Apply patch for HARMONY-6365: [classlib][luni]UnixSocketTest.test_getInputStream may fail
because server close the socket before the client read the data

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixSocketTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixSocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixSocketTest.java?rev=832360&r1=832359&r2=832360&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixSocketTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixSocketTest.java
Tue Nov  3 09:29:01 2009
@@ -37,69 +37,51 @@
     public void test_getInputStream() throws IOException {
         // Simple read/write test over the IO streams
         final ServerSocket pingServer = new ServerSocket(0);
-        Runnable runnable = new Runnable() {
-            public void run() {
-                try {
-                    Socket worker = pingServer.accept();
-                    pingServer.close();
-                    InputStream in = worker.getInputStream();
-                    in.read();
-                    OutputStream out = worker.getOutputStream();
-                    out.write(new byte[42]);
-                    worker.close();
-                } catch (IOException e) {
-                    fail(e.getMessage());
-                }
-            }
-        };
-        Thread thread = new Thread(runnable, "UnixSocket.getInputStream");
-        thread.start();
-
-        Socket pingClient = new Socket(InetAddress.getLocalHost(), pingServer
-                .getLocalPort());
-
-        // Busy wait until the client is connected.
-        int c = 0;
-        while (!pingClient.isConnected()) {
-            try {
-                Thread.sleep(200);
-            } catch (InterruptedException e) {
-                // ignore
-            }
-            if (++c > 4) {
-                fail("thread is not alive");
-            }
-        }
-
-        // Write some data to the server to provoke it
-        OutputStream out = pingClient.getOutputStream();
-        out.write(new byte[256]);
+        Socket pingClient = new Socket();
 
-        InputStream in = pingClient.getInputStream();
-        in.read(new byte[42]);
         try {
-            in.read();
-            fail("Should throw SocketException");
-        } catch (SocketException e) {
-            // expected
-        }
-        in.close();
+            pingClient.connect(new InetSocketAddress(
+                    InetAddress.getLocalHost(), pingServer.getLocalPort()));
 
-        try {
+            Socket worker = pingServer.accept();
+            pingServer.close();
+
+            // Write some data to the server to provoke it
+            OutputStream clientOut = pingClient.getOutputStream();
+            clientOut.write(new byte[256]);
+            InputStream in = worker.getInputStream();
             in.read();
-            fail("Should throw SocketException");
-        } catch (SocketException e) {
-            // expected
-        }
-        try {
-            in.read(new byte[5]);
-            fail("Should throw SocketException");
-        } catch (SocketException e) {
-            // expected
-        }
 
-        pingClient.close();
-        pingServer.close();
+            OutputStream out = worker.getOutputStream();
+            out.write(new byte[42]);
+            worker.close();
+            InputStream clientIn = pingClient.getInputStream();
+            clientIn.read(new byte[42]);
+
+            try {
+                clientIn.read();
+                fail("Should throw SocketException");
+            } catch (SocketException e) {
+                // expected
+            }
+            clientIn.close();
+
+            try {
+                clientIn.read();
+                fail("Should throw SocketException");
+            } catch (SocketException e) {
+                // expected
+            }
+            try {
+                clientIn.read(new byte[5]);
+                fail("Should throw SocketException");
+            } catch (SocketException e) {
+                // expected
+            }
+        } finally {
+            pingClient.close();
+            pingServer.close();
+        }
     }
 
     public void test_connectLjava_net_SocketAddressI() throws Exception {



Mime
View raw message