harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r510607 - in /harmony/enhanced/classlib/trunk: modules/nio/make/ modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ support/src/test/java/tests/support/
Date Thu, 22 Feb 2007 18:02:53 GMT
Author: ayza
Date: Thu Feb 22 10:02:52 2007
New Revision: 510607

URL: http://svn.apache.org/viewvc?view=rev&rev=510607
Log:
Applying patch from HARMONY-2860 ([classlib][nio] Intermittent fails of DatagramChannelTest
and SelectionKeyTest). DatagramChannelTest was removed from the intermittent exclude list.


Modified:
    harmony/enhanced/classlib/trunk/modules/nio/make/exclude.windows.x86.drl.interm
    harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
    harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_PortManager.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/make/exclude.windows.x86.drl.interm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/make/exclude.windows.x86.drl.interm?view=diff&rev=510607&r1=510606&r2=510607
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/make/exclude.windows.x86.drl.interm (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/make/exclude.windows.x86.drl.interm Thu Feb
22 10:02:52 2007
@@ -1,2 +0,0 @@
-#2860
-org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java?view=diff&rev=510607&r1=510606&r2=510607
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
Thu Feb 22 10:02:52 2007
@@ -68,16 +68,19 @@
 
     private DatagramSocket datagramSocket2;
 
+    // The port to be used in test cases.
+    private int testPort;
+
     protected void setUp() throws Exception {
         super.setUp();
         this.channel1 = DatagramChannel.open();
         this.channel2 = DatagramChannel.open();
-        this.localAddr1 = new InetSocketAddress("127.0.0.1",
-                Support_PortManager.getNextPort());
-        this.localAddr2 = new InetSocketAddress("127.0.0.1",
-                Support_PortManager.getNextPort());
-        this.datagramSocket1 = new DatagramSocket(0);
-        this.datagramSocket2 = new DatagramSocket(0);
+        int[] ports = Support_PortManager.getNextPortsForUDP(5);
+        this.localAddr1 = new InetSocketAddress("127.0.0.1", ports[0]);
+        this.localAddr2 = new InetSocketAddress("127.0.0.1", ports[1]);
+        this.datagramSocket1 = new DatagramSocket(ports[2]);
+        this.datagramSocket2 = new DatagramSocket(ports[3]);
+        testPort = ports[4];
     }
 
     protected void tearDown() throws Exception {
@@ -1282,7 +1285,7 @@
 
     public void testReceiveSend_Normal_S2S() throws Exception {
         String msg = "normal string in testReceiveSend_Normal_S2S";
-        this.datagramSocket1 = new DatagramSocket(0);
+        this.datagramSocket1 = new DatagramSocket(testPort);
         DatagramPacket rdp = new DatagramPacket(msg.getBytes(), msg.length(),
                 localAddr2);
         datagramSocket2 = new DatagramSocket(localAddr2.getPort());
@@ -1338,7 +1341,7 @@
 
     public void testReceiveSend_Empty_S2S() throws Exception {
         String msg = "";
-        this.datagramSocket1 = new DatagramSocket(0);
+        this.datagramSocket1 = new DatagramSocket(testPort);
         DatagramPacket rdp = new DatagramPacket(msg.getBytes(), msg.length(),
                 localAddr2);
         datagramSocket2 = new DatagramSocket(localAddr2.getPort());
@@ -1414,7 +1417,7 @@
 
     private void sendByDatagramSocket(String data, InetSocketAddress address)
             throws Exception {
-        this.datagramSocket1 = new DatagramSocket(0);
+        this.datagramSocket1 = new DatagramSocket(testPort);
         DatagramPacket rdp = new DatagramPacket(data.getBytes(), data.length(),
                 address);
         this.datagramSocket1.send(rdp);
@@ -1506,8 +1509,7 @@
     public void testRead_Security() throws Exception {        
         ByteBuffer buf = ByteBuffer.allocate(CAPACITY_NORMAL);
         String strHello = "hello";
-        localAddr1 = new InetSocketAddress("127.0.0.1", Support_PortManager
-                .getNextPort());
+        localAddr1 = new InetSocketAddress("127.0.0.1", testPort);
         this.channel1.socket().bind(localAddr1);
         this.channel2.socket().bind(localAddr2);
         this.channel1.connect(localAddr2);
@@ -1526,8 +1528,7 @@
     public void testReceive_Peek_Security_Nonblocking() throws Exception {        
         ByteBuffer buf = ByteBuffer.allocate(CAPACITY_NORMAL);
         String strHello = "hello";
-        localAddr1 = new InetSocketAddress("127.0.0.1", Support_PortManager
-                .getNextPort());
+        localAddr1 = new InetSocketAddress("127.0.0.1", testPort);
         this.channel1.socket().bind(localAddr1);
         sendByChannel(strHello, localAddr1);
         final SecurityManager sm = System.getSecurityManager();

Modified: harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_PortManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_PortManager.java?view=diff&rev=510607&r1=510606&r2=510607
==============================================================================
--- harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_PortManager.java
(original)
+++ harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_PortManager.java
Thu Feb 22 10:02:52 2007
@@ -17,6 +17,7 @@
 
 package tests.support;
 
+import java.net.DatagramSocket;
 import java.net.ServerSocket;
 import java.util.Calendar;
 import java.util.TimeZone;
@@ -39,6 +40,40 @@
             }
         }
         return getNextPort_unsafe();
+    }
+
+    /**
+     * Returns 1 free ports to be used.
+     */
+    public static synchronized int getNextPortForUDP() {
+        return getNextPortsForUDP(1)[0];
+    }
+
+    /**
+     * Returns the specified number of free ports to be used.
+     */
+    public static synchronized int[] getNextPortsForUDP(int num) {
+        if (num <= 0) {
+            throw new IllegalArgumentException("Invalid ports number: " + num);
+        }
+        DatagramSocket[] dss = new DatagramSocket[num];
+        int[] ports = new int[num];
+
+        try {
+            for (int i = 0; i < num; ++i) {
+                dss[i] = new DatagramSocket(0);
+                ports[i] = dss[i].getLocalPort();
+            }
+        } catch (Exception ex) {
+            throw new Error("Unable to get " + num + " ports for UDP: " + ex);
+        } finally {
+            for (int i = 0; i < num; ++i) {
+                if (dss[i] != null) {
+                    dss[i].close();
+                }
+            }
+        }
+        return ports;
     }
 
     public static synchronized int getNextPort_unsafe() {



Mime
View raw message