harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r426436 - /incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java
Date Fri, 28 Jul 2006 08:37:55 GMT
Author: pyang
Date: Fri Jul 28 01:37:54 2006
New Revision: 426436

URL: http://svn.apache.org/viewvc?rev=426436&view=rev
Log:
Fix for HARMONY-991([classlib][nio] An unstable test in o.a.h.tests.java.nio.channels.DatagramChannelTest)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java?rev=426436&r1=426435&r2=426436&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java
Fri Jul 28 01:37:54 2006
@@ -1427,8 +1427,18 @@
             String expectedString) throws IOException {
         try {
             ByteBuffer buf = ByteBuffer.wrap(new byte[bufSize]);
-            InetSocketAddress returnAddr = (InetSocketAddress) this.channel1
-                    .receive(buf);
+            InetSocketAddress returnAddr = null;
+            long startTime = System.currentTimeMillis();
+            do {
+                returnAddr = (InetSocketAddress) this.channel1.receive(buf);
+                // continue loop when channel1 is non-blocking and no data was
+                // received.
+                if (channel1.isBlocking() || null != returnAddr) {
+                    break;
+                }
+                // avoid dead loop
+                assertTimeout(startTime, 10000);
+            } while (true);
             int length = returnAddr.getAddress().getAddress().length;
             for (int i = 0; i < length; i++) {
                 assertEquals(returnAddr.getAddress().getAddress()[i],
@@ -1440,6 +1450,17 @@
                     expectedString);
         } finally {
             this.channel1.close();
+        }
+    }
+    
+    /*
+     * Fails if the difference between current time and start time is greater
+     * than timeout.
+     */
+    private void assertTimeout(long startTime, long timeout) {
+        long currentTime = System.currentTimeMillis();
+        if ((currentTime - startTime) > timeout) {
+            fail("Timeout");
         }
     }
 



Mime
View raw message