harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r512257 - in /harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net: DatagramPacketTest.java DatagramSocketTest.java MulticastSocketTest.java
Date Tue, 27 Feb 2007 14:04:07 GMT
Author: ayza
Date: Tue Feb 27 06:04:04 2007
New Revision: 512257

URL: http://svn.apache.org/viewvc?view=rev&rev=512257
Log:
Applying patch from HARMONY-3046 ([classli][luni] intermittent failures of tests.api.java.net.DatagramSocketTest)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramPacketTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramPacketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramPacketTest.java?view=diff&rev=512257&r1=512256&r2=512257
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramPacketTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramPacketTest.java
Tue Feb 27 06:04:04 2007
@@ -174,7 +174,8 @@
 		} catch (UnknownHostException e) {
 			fail("Unexpected UnknownHostException : " + e.getMessage());
 		}
-		final int port = Support_PortManager.getNextPort();
+		int[] ports = Support_PortManager.getNextPortsForUDP(2);
+		final int port = ports[0];
 		final Object lock = new Object();
 
 		Thread thread = new Thread(new Runnable() {
@@ -203,7 +204,7 @@
 
 		DatagramSocket socket = null;
 		try {
-			socket = new DatagramSocket(Support_PortManager.getNextPort());
+			socket = new DatagramSocket(ports[1]);
 			socket.setSoTimeout(3000);
 			DatagramPacket packet = new DatagramPacket(new byte[] { 1, 2, 3, 4,
 					5, 6 }, 6, localhost, port);
@@ -326,7 +327,7 @@
 
 			// now validate we can construct
 			InetSocketAddress theAddress = new InetSocketAddress(InetAddress
-					.getLocalHost(), Support_PortManager.getNextPort());
+					.getLocalHost(), Support_PortManager.getNextPortForUDP());
 			DatagramPacket thePacket = new DatagramPacket(buf, 1, theAddress);
 			assertTrue("Socket address not set correctly (1)", theAddress
 					.equals(thePacket.getSocketAddress()));
@@ -370,7 +371,7 @@
 
 			// now validate we can construct
 			InetSocketAddress theAddress = new InetSocketAddress(InetAddress
-					.getLocalHost(), Support_PortManager.getNextPort());
+					.getLocalHost(), Support_PortManager.getNextPortForUDP());
 			DatagramPacket thePacket = new DatagramPacket(buf, 1, 1, theAddress);
 			assertTrue("Socket address not set correctly (1)", theAddress
 					.equals(thePacket.getSocketAddress()));
@@ -393,7 +394,7 @@
 
 			// validate get returns the value we set
 			InetSocketAddress theAddress = new InetSocketAddress(InetAddress
-					.getLocalHost(), Support_PortManager.getNextPort());
+					.getLocalHost(), Support_PortManager.getNextPortForUDP());
 			thePacket = new DatagramPacket(buf, 1);
 			thePacket.setSocketAddress(theAddress);
 			assertTrue("Socket address not set correctly (1)", theAddress
@@ -436,7 +437,7 @@
 
 			// now validate we can set it correctly
 			InetSocketAddress theAddress = new InetSocketAddress(InetAddress
-					.getLocalHost(), Support_PortManager.getNextPort());
+					.getLocalHost(), Support_PortManager.getNextPortForUDP());
 			thePacket = new DatagramPacket(buf, 1);
 			thePacket.setSocketAddress(theAddress);
 			assertTrue("Socket address not set correctly (1)", theAddress

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java?view=diff&rev=512257&r1=512256&r2=512257
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java
Tue Feb 27 06:04:04 2007
@@ -113,7 +113,7 @@
 	public void test_ConstructorI() {
 		// Test for method java.net.DatagramSocket(int)
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds = new java.net.DatagramSocket(portNumber);
 			assertTrue("Created socket with incorrect port",
 					ds.getLocalPort() == portNumber);
@@ -128,7 +128,7 @@
 	public void test_ConstructorILjava_net_InetAddress() {
 		// Test for method java.net.DatagramSocket(int, java.net.InetAddress)
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds = new java.net.DatagramSocket(portNumber, InetAddress
 					.getLocalHost());
 			assertTrue("Created socket with incorrect port",
@@ -146,7 +146,7 @@
 	public void test_close() {
 		// Test for method void java.net.DatagramSocket.close()
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds = new java.net.DatagramSocket(portNumber);
 			dp = new DatagramPacket("Test String".getBytes(), 11, InetAddress
 					.getLocalHost(), 0);
@@ -165,7 +165,7 @@
 		try {
 			ds = new java.net.DatagramSocket();
 			InetAddress inetAddress = InetAddress.getLocalHost();
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds.connect(inetAddress, portNumber);
 			assertTrue("Incorrect InetAddress", ds.getInetAddress().equals(
 					inetAddress));
@@ -183,7 +183,7 @@
 				ds = new java.net.DatagramSocket();
 				InetAddress inetAddress = InetAddress
 						.getByName(Support_Configuration.IPv6GlobalAddressJcl4);
-				int portNumber = Support_PortManager.getNextPort();
+				int portNumber = Support_PortManager.getNextPortForUDP();
 				ds.connect(inetAddress, portNumber);
 				assertTrue("Incorrect InetAddress", ds.getInetAddress().equals(
 						inetAddress));
@@ -264,7 +264,7 @@
 		try {
 			ds = new java.net.DatagramSocket();
 			InetAddress inetAddress = InetAddress.getLocalHost();
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds.connect(inetAddress, portNumber);
 			DatagramPacket send = new DatagramPacket(new byte[10], 10);
 			ds.send(send);
@@ -284,11 +284,12 @@
 		// validate that we can send/receive with datagram sockets connected at
 		// the native level
 		DatagramServer server = null;
-		int serverPortNumber = Support_PortManager.getNextPort();
+		int[] ports = Support_PortManager.getNextPortsForUDP(3);
+		int serverPortNumber = ports[0];
 		try {
 			InetAddress localHost = InetAddress.getLocalHost();
-			DatagramSocket ds = new DatagramSocket();
-			DatagramSocket ds2 = new DatagramSocket();
+			DatagramSocket ds = new DatagramSocket(ports[1]);
+			DatagramSocket ds2 = new DatagramSocket(ports[2]);
 
 			try {
 				server = new DatagramServer(serverPortNumber, localHost);
@@ -333,7 +334,7 @@
 		try {
 			ds = new java.net.DatagramSocket();
 			InetAddress inetAddress = InetAddress.getLocalHost();
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds.connect(inetAddress, portNumber);
 			ds.disconnect();
 			ds.close();
@@ -346,7 +347,7 @@
 		try {
 			ds = new java.net.DatagramSocket();
 			InetAddress inetAddress = InetAddress.getLocalHost();
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds.connect(inetAddress, portNumber);
 			DatagramPacket send = new DatagramPacket(new byte[10], 10,
 					inetAddress, portNumber + 1);
@@ -364,11 +365,12 @@
 		// validate that we can connect, then disconnect, then connect then
 		// send/recv
 		server = null;
-		serverPortNumber = Support_PortManager.getNextPort();
+		ports = Support_PortManager.getNextPortsForUDP(3);
+		serverPortNumber = ports[0];
 		try {
 			InetAddress localHost = InetAddress.getLocalHost();
-			DatagramSocket ds = new DatagramSocket();
-			DatagramSocket ds2 = new DatagramSocket();
+			DatagramSocket ds = new DatagramSocket(ports[1]);
+			DatagramSocket ds2 = new DatagramSocket(ports[2]);
 
 			try {
 				server = new DatagramServer(serverPortNumber, localHost);
@@ -416,11 +418,12 @@
 
 		// validate that we can connect/disconnect then send/recv to any address
 		server = null;
-		serverPortNumber = Support_PortManager.getNextPort();
+		ports = Support_PortManager.getNextPortsForUDP(3);
+		serverPortNumber = ports[0];
 		try {
 			InetAddress localHost = InetAddress.getLocalHost();
-			DatagramSocket ds = new DatagramSocket();
-			DatagramSocket ds2 = new DatagramSocket();
+			DatagramSocket ds = new DatagramSocket(ports[1]);
+			DatagramSocket ds2 = new DatagramSocket(ports[2]);
 
 			try {
 				server = new DatagramServer(serverPortNumber, localHost);
@@ -467,11 +470,12 @@
 		// validate that we can connect on an allready connected socket and then
 		// send/recv
 		server = null;
-		serverPortNumber = Support_PortManager.getNextPort();
+		ports = Support_PortManager.getNextPortsForUDP(3);
+		serverPortNumber = ports[0];
 		try {
 			InetAddress localHost = InetAddress.getLocalHost();
-			DatagramSocket ds = new DatagramSocket();
-			DatagramSocket ds2 = new DatagramSocket();
+			DatagramSocket ds = new DatagramSocket(ports[1]);
+			DatagramSocket ds2 = new DatagramSocket(ports[2]);
 
 			try {
 				server = new DatagramServer(serverPortNumber, localHost);
@@ -522,7 +526,7 @@
 			ds = new java.net.DatagramSocket();
 			byte[] addressBytes = { 0, 0, 0, 0 };
 			InetAddress inetAddress = InetAddress.getByAddress(addressBytes);
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds.connect(inetAddress, portNumber);
 		} catch (Exception e) {
 			fail(
@@ -539,7 +543,7 @@
 						0, 0, 0 };
 				InetAddress inetAddress = InetAddress
 						.getByAddress(addressBytes);
-				int portNumber = Support_PortManager.getNextPort();
+				int portNumber = Support_PortManager.getNextPortForUDP();
 				ds.connect(inetAddress, portNumber);
 			} catch (Exception e) {
 				fail(
@@ -556,7 +560,7 @@
 		try {
 			ds = new java.net.DatagramSocket();
 			InetAddress inetAddress = InetAddress.getLocalHost();
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds.connect(inetAddress, portNumber);
 			ds.disconnect();
 			assertNull("Incorrect InetAddress", ds.getInetAddress());
@@ -573,7 +577,7 @@
 				ds = new java.net.DatagramSocket();
 				InetAddress inetAddress = InetAddress
 						.getByName(Support_Configuration.IPv6GlobalAddressJcl4);
-				int portNumber = Support_PortManager.getNextPort();
+				int portNumber = Support_PortManager.getNextPortForUDP();
 				ds.connect(inetAddress, portNumber);
 				ds.disconnect();
 				assertNull("Incorrect InetAddress", ds.getInetAddress());
@@ -600,7 +604,7 @@
 		// java.net.DatagramSocket.getLocalAddress()
 		InetAddress local = null;
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			local = InetAddress.getLocalHost();
 			ds = new java.net.DatagramSocket(portNumber, local);
 			assertTrue("Returned incorrect address. Got:"
@@ -644,7 +648,7 @@
 	public void test_getLocalPort() {
 		// Test for method int java.net.DatagramSocket.getLocalPort()
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds = new java.net.DatagramSocket(portNumber);
 			assertTrue("Returned incorrect port",
 					ds.getLocalPort() == portNumber);
@@ -658,7 +662,7 @@
 	 */
 	public void test_getPort() {
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			DatagramSocket theSocket = new DatagramSocket(portNumber);
 			assertEquals("Expected -1 for remote port as not connected",
 					-1, theSocket.getPort());
@@ -678,7 +682,7 @@
 	 */
 	public void test_getReceiveBufferSize() {
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds = new java.net.DatagramSocket(portNumber);
 			ds.setReceiveBufferSize(130);
 			assertTrue("Incorrect buffer size",
@@ -694,7 +698,7 @@
 	 */
 	public void test_getSendBufferSize() {
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds = new java.net.DatagramSocket(portNumber);
 			ds.setSendBufferSize(134);
 			assertTrue("Incorrect buffer size", ds.getSendBufferSize() >= 134);
@@ -710,7 +714,7 @@
 	public void test_getSoTimeout() {
 		// Test for method int java.net.DatagramSocket.getSoTimeout()
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds = new java.net.DatagramSocket(portNumber);
 			ds.setSoTimeout(100);
 			assertEquals("Returned incorrect timeout", 100, ds.getSoTimeout());
@@ -728,8 +732,8 @@
 		// java.net.DatagramSocket.receive(java.net.DatagramPacket)
 
 		receive_oversize_java_net_DatagramPacket();
-
-		final int portNumber = Support_PortManager.getNextPort();
+		final int[] ports = Support_PortManager.getNextPortsForUDP(2);
+		final int portNumber = ports[0];
 
 		class TestDGRcv implements Runnable {
 			public void run() {
@@ -737,8 +741,7 @@
 				try {
 					localHost = InetAddress.getLocalHost();
 					Thread.sleep(1000);
-					DatagramSocket sds = new DatagramSocket(Support_PortManager
-							.getNextPort());
+					DatagramSocket sds = new DatagramSocket(ports[1]);
 					DatagramPacket rdp = new DatagramPacket("Test String"
 							.getBytes(), 11, localHost, portNumber);
 					sds.send(rdp);
@@ -810,8 +813,9 @@
 			} while (thread.isAlive());
 
 			interrupted = false;
-			final int portNum = Support_PortManager.getNextPort();
-			final DatagramSocket ds2 = new DatagramSocket();
+			int[] ports1 = Support_PortManager.getNextPortsForUDP(2);
+			final int portNum = ports[0];
+			final DatagramSocket ds2 = new DatagramSocket(ports[1]);
 			ds2.setSoTimeout(12000);
 			Runnable runnable2 = new Runnable() {
 				public void run() {
@@ -871,8 +875,8 @@
 	public void test_sendLjava_net_DatagramPacket() throws Exception {
 		// Test for method void
 		// java.net.DatagramSocket.send(java.net.DatagramPacket)
-
-		final int portNumber = Support_PortManager.getNextPort();
+		int[] ports = Support_PortManager.getNextPortsForUDP(2);
+		final int portNumber = ports[0];
 
 		class TestDGSend implements Runnable {
 			Thread pThread;
@@ -905,7 +909,7 @@
 		try {
 			new Thread(new TestDGSend(Thread.currentThread()), "DGServer")
 					.start();
-			ds = new java.net.DatagramSocket();
+			ds = new java.net.DatagramSocket(ports[1]);
 			dp = new DatagramPacket(testString.getBytes(), testString.length(),
 					InetAddress.getLocalHost(), portNumber);
 			// Wait to allow send to occur
@@ -980,7 +984,7 @@
 	 */
 	public void test_setSendBufferSizeI() {
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds = new java.net.DatagramSocket(portNumber);
 			ds.setSendBufferSize(134);
 			assertTrue("Incorrect buffer size", ds.getSendBufferSize() >= 134);
@@ -995,7 +999,7 @@
 	 */
 	public void test_setReceiveBufferSizeI() {
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds = new java.net.DatagramSocket(portNumber);
 			ds.setReceiveBufferSize(130);
 			assertTrue("Incorrect buffer size",
@@ -1012,7 +1016,7 @@
 	public void test_setSoTimeoutI() {
 		// Test for method void java.net.DatagramSocket.setSoTimeout(int)
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds = new java.net.DatagramSocket(portNumber);
 			ds.setSoTimeout(100);
 			assertTrue("Set incorrect timeout", ds.getSoTimeout() >= 100);
@@ -1051,7 +1055,7 @@
 
 		try {
 			try {
-				int portNumber = Support_PortManager.getNextPort();
+				int portNumber = Support_PortManager.getNextPortForUDP();
 				ds = new java.net.DatagramSocket(new InetSocketAddress(
 						InetAddress.getLocalHost(), portNumber));
                 assertTrue(ds.getBroadcast());
@@ -1064,7 +1068,7 @@
 			}
 
 			try {
-				int portNumber = Support_PortManager.getNextPort();
+				int portNumber = Support_PortManager.getNextPortForUDP();
 				ds = new java.net.DatagramSocket(new mySocketAddress());
 				fail(
 						"No exception when constucting datagramSocket with unsupported SocketAddress type");
@@ -1093,8 +1097,9 @@
 		DatagramServer server = null;
 		try {
 			// now create a socket that is not bound and then bind it
-			int portNumber = Support_PortManager.getNextPort();
-			int serverPortNumber = Support_PortManager.getNextPort();
+			int[] ports = Support_PortManager.getNextPortsForUDP(3);
+			int portNumber = ports[0];
+			int serverPortNumber = ports[1];
 			DatagramSocket theSocket = new DatagramSocket(
 					new InetSocketAddress(InetAddress.getLocalHost(),
 							portNumber));
@@ -1113,7 +1118,7 @@
 			// now make sure that datagrams sent from this socket appear to come
 			// from the address we bound to
 			InetAddress localHost = InetAddress.getLocalHost();
-			portNumber = Support_PortManager.getNextPort();
+			portNumber = ports[2];
 			DatagramSocket ds = new DatagramSocket(null);
 			ds.bind(new InetSocketAddress(localHost, portNumber));
 
@@ -1159,19 +1164,19 @@
 						.bind(new InetSocketAddress(
 								InetAddress
 										.getByAddress(Support_Configuration.nonLocalAddressBytes),
-								Support_PortManager.getNextPort()));
+								Support_PortManager.getNextPortForUDP()));
 				fail("No exception when binding to bad address");
 			} catch (SocketException ex) {
 			}
 			theSocket.close();
 
 			// Address that we have allready bound to
+			ports = Support_PortManager.getNextPortsForUDP(2);
 			theSocket = new DatagramSocket(null);
-			DatagramSocket theSocket2 = new DatagramSocket();
+			DatagramSocket theSocket2 = new DatagramSocket(ports[0]);
 			try {
 				InetSocketAddress theAddress = new InetSocketAddress(
-						InetAddress.getLocalHost(), Support_PortManager
-								.getNextPort());
+						InetAddress.getLocalHost(), ports[1]);
 				theSocket.bind(theAddress);
 				theSocket2.bind(theAddress);
 				fail("No exception binding to address that is not available");
@@ -1208,7 +1213,7 @@
 		try {
 			ds = new java.net.DatagramSocket();
 			InetAddress inetAddress = InetAddress.getLocalHost();
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds.connect(new InetSocketAddress(inetAddress, portNumber));
 			DatagramPacket send = new DatagramPacket(new byte[10], 10);
 			ds.send(send);
@@ -1228,11 +1233,12 @@
 		// validate that we can send/receive with datagram sockets connected at
 		// the native level
 		DatagramServer server = null;
-		int serverPortNumber = Support_PortManager.getNextPort();
+		int[] ports = Support_PortManager.getNextPortsForUDP(3);
+		int serverPortNumber = ports[0];
 		try {
 			InetAddress localHost = InetAddress.getLocalHost();
-			DatagramSocket ds = new DatagramSocket();
-			DatagramSocket ds2 = new DatagramSocket();
+			DatagramSocket ds = new DatagramSocket(ports[1]);
+			DatagramSocket ds2 = new DatagramSocket(ports[2]);
 
 			try {
 				server = new DatagramServer(serverPortNumber, localHost);
@@ -1277,7 +1283,7 @@
 		try {
 			ds = new java.net.DatagramSocket();
 			InetAddress inetAddress = InetAddress.getLocalHost();
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds.connect(new InetSocketAddress(inetAddress, portNumber));
 			ds.disconnect();
 			ds.close();
@@ -1290,7 +1296,7 @@
 		try {
 			ds = new java.net.DatagramSocket();
 			InetAddress inetAddress = InetAddress.getLocalHost();
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			ds.connect(new InetSocketAddress(inetAddress, portNumber));
 			DatagramPacket send = new DatagramPacket(new byte[10], 10,
 					inetAddress, portNumber + 1);
@@ -1308,11 +1314,12 @@
 		// validate that we can connect, then disconnect, then connect then
 		// send/recv
 		server = null;
-		serverPortNumber = Support_PortManager.getNextPort();
+		ports = Support_PortManager.getNextPortsForUDP(3);
+		serverPortNumber = ports[0];
 		try {
 			InetAddress localHost = InetAddress.getLocalHost();
-			DatagramSocket ds = new DatagramSocket();
-			DatagramSocket ds2 = new DatagramSocket();
+			DatagramSocket ds = new DatagramSocket(ports[1]);
+			DatagramSocket ds2 = new DatagramSocket(ports[2]);
 
 			try {
 				server = new DatagramServer(serverPortNumber, localHost);
@@ -1360,11 +1367,12 @@
 
 		// validate that we can connect/disconnect then send/recv to any address
 		server = null;
-		serverPortNumber = Support_PortManager.getNextPort();
+		ports = Support_PortManager.getNextPortsForUDP(3);
+		serverPortNumber = ports[0];
 		try {
 			InetAddress localHost = InetAddress.getLocalHost();
-			DatagramSocket ds = new DatagramSocket();
-			DatagramSocket ds2 = new DatagramSocket();
+			DatagramSocket ds = new DatagramSocket(ports[1]);
+			DatagramSocket ds2 = new DatagramSocket(ports[2]);
 
 			try {
 				server = new DatagramServer(serverPortNumber, localHost);
@@ -1411,11 +1419,12 @@
 		// validate that we can connect on an allready connected socket and then
 		// send/recv
 		server = null;
-		serverPortNumber = Support_PortManager.getNextPort();
+		ports = Support_PortManager.getNextPortsForUDP(3);
+		serverPortNumber = ports[0];
 		try {
 			InetAddress localHost = InetAddress.getLocalHost();
-			DatagramSocket ds = new DatagramSocket();
-			DatagramSocket ds2 = new DatagramSocket();
+			DatagramSocket ds = new DatagramSocket(ports[1]);
+			DatagramSocket ds2 = new DatagramSocket(ports[2]);
 
 			try {
 				server = new DatagramServer(serverPortNumber, localHost);
@@ -1467,7 +1476,7 @@
 			ds = new java.net.DatagramSocket();
 			byte[] addressBytes = { 0, 0, 0, 0 };
 			InetAddress inetAddress = InetAddress.getByAddress(addressBytes);
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			InetAddress localHost = InetAddress.getLocalHost();
 			ds.connect(new InetSocketAddress(inetAddress, portNumber));
 			assertTrue("Is not connected after connect to inaddr any", ds
@@ -1492,9 +1501,10 @@
 	public void test_isBound() {
 		try {
 			InetAddress addr = InetAddress.getLocalHost();
-			int port = Support_PortManager.getNextPort();
+			int[] ports = Support_PortManager.getNextPortsForUDP(3);
+			int port = ports[0];
 
-			DatagramSocket theSocket = new DatagramSocket();
+			DatagramSocket theSocket = new DatagramSocket(ports[1]);
 			assertTrue("Socket indicated  not bound when it should be (1)",
 					theSocket.isBound());
 			theSocket.close();
@@ -1518,8 +1528,7 @@
 
 			// now test when we bind explicitely
 			InetSocketAddress theLocalAddress = new InetSocketAddress(
-					InetAddress.getLocalHost(), Support_PortManager
-							.getNextPort());
+					InetAddress.getLocalHost(), ports[2]);
 			theSocket = new DatagramSocket(null);
 			assertFalse("Socket indicated bound when it should not be (2)",
 					theSocket.isBound());
@@ -1540,10 +1549,11 @@
 	public void test_isConnected() {
 		try {
 			InetAddress addr = InetAddress.getLocalHost();
-			int port = Support_PortManager.getNextPort();
+			int[] ports = Support_PortManager.getNextPortsForUDP(4);
+			int port = ports[0];
 
 			// base test
-			DatagramSocket theSocket = new DatagramSocket();
+			DatagramSocket theSocket = new DatagramSocket(ports[1]);
 			assertFalse("Socket indicated connected when it should not be",
 					theSocket.isConnected());
 			theSocket.connect(new InetSocketAddress(addr, port));
@@ -1551,8 +1561,7 @@
 					theSocket.isConnected());
 
 			// reconnect the socket and make sure we get the right answer
-			theSocket.connect(new InetSocketAddress(addr, Support_PortManager
-					.getNextPort()));
+			theSocket.connect(new InetSocketAddress(addr, ports[2]));
 			assertTrue("Socket indicated  not connected when it should be",
 					theSocket.isConnected());
 
@@ -1563,7 +1572,7 @@
 			theSocket.close();
 
 			// now check behavior when socket is closed when connected
-			theSocket = new DatagramSocket();
+			theSocket = new DatagramSocket(ports[3]);
 			theSocket.connect(new InetSocketAddress(addr, port));
 			theSocket.close();
 			assertTrue("Socket indicated  not connected when it should be",
@@ -1578,8 +1587,9 @@
 	 */
 	public void test_getRemoteSocketAddress() {
 		try {
-			int sport = Support_PortManager.getNextPort();
-			int portNumber = Support_PortManager.getNextPort();
+			int[] ports = Support_PortManager.getNextPortsForUDP(3);
+			int sport = ports[0];
+			int portNumber = ports[1];
 			DatagramSocket s = new DatagramSocket(new InetSocketAddress(
 					InetAddress.getLocalHost(), portNumber));
 			s.connect(new InetSocketAddress(InetAddress.getLocalHost(), sport));
@@ -1593,7 +1603,7 @@
 			// now create one that is not connected and validate that we get the
 			// right answer
 			DatagramSocket theSocket = new DatagramSocket(null);
-			portNumber = Support_PortManager.getNextPort();
+			portNumber = ports[2];
 			theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(),
 					portNumber));
 			assertNull(
@@ -1622,7 +1632,7 @@
 	public void test_getLocalSocketAddress() {
 
 		try {
-			int portNumber = Support_PortManager.getNextPort();
+			int portNumber = Support_PortManager.getNextPortForUDP();
 			DatagramSocket s = new DatagramSocket(new InetSocketAddress(
 					InetAddress.getLocalHost(), portNumber));
 			assertTrue("Returned incorrect InetSocketAddress(1):"
@@ -1646,7 +1656,7 @@
 					theSocket.getLocalSocketAddress());
 
 			// now bind the socket and make sure we get the right answer
-			portNumber = Support_PortManager.getNextPort();
+			portNumber = Support_PortManager.getNextPortForUDP();
 			theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(),
 					portNumber));
 			assertTrue("Returned incorrect InetSocketAddress(2):"
@@ -1700,7 +1710,7 @@
 			try {
 				InetSocketAddress theAddress = new InetSocketAddress(
 						InetAddress.getLocalHost(), Support_PortManager
-								.getNextPort());
+								.getNextPortForUDP());
 				theSocket1 = new DatagramSocket(null);
 				theSocket2 = new DatagramSocket(null);
 				theSocket1.setReuseAddress(false);
@@ -1721,7 +1731,7 @@
 			try {
 				InetSocketAddress theAddress = new InetSocketAddress(
 						InetAddress.getLocalHost(), Support_PortManager
-								.getNextPort());
+								.getNextPortForUDP());
 				theSocket1 = new DatagramSocket(null);
 				theSocket2 = new DatagramSocket(null);
 				theSocket1.setReuseAddress(true);
@@ -1742,7 +1752,7 @@
 			try {
 				InetSocketAddress theAddress = new InetSocketAddress(
 						InetAddress.getLocalHost(), Support_PortManager
-								.getNextPort());
+								.getNextPortForUDP());
 				theSocket1 = new DatagramSocket(null);
 				theSocket2 = new DatagramSocket(null);
 				theSocket1.bind(theAddress);
@@ -1786,7 +1796,8 @@
 	public void test_setBroadcastZ() {
 
 		try {
-			DatagramSocket theSocket = new DatagramSocket();
+			int[] ports = Support_PortManager.getNextPortsForUDP(3);
+			DatagramSocket theSocket = new DatagramSocket(ports[0]);
 			theSocket.setBroadcast(false);
 			byte theBytes[] = { -1, -1, -1, -1 };
 
@@ -1794,8 +1805,7 @@
 			// setBroadcast is false
 			try {
 				theSocket.connect(new InetSocketAddress(InetAddress
-						.getByAddress(theBytes), Support_PortManager
-						.getNextPort()));
+						.getByAddress(theBytes), ports[1]));
 				assertFalse(
 						"No exception when connecting to broadcast address with setBroadcast(false)",
 						theSocket.getBroadcast());
@@ -1807,8 +1817,7 @@
 			theSocket.setBroadcast(true);
 			theSocket
 					.connect(new InetSocketAddress(InetAddress
-							.getByAddress(theBytes), Support_PortManager
-							.getNextPort()));
+							.getByAddress(theBytes), ports[2]));
 			ensureExceptionThrownIfOptionIsUnsupportedOnOS(SO_BROADCAST);
 		} catch (Exception e) {
 			handleException(e, SO_BROADCAST);
@@ -1842,10 +1851,11 @@
 			int IPTOS_RELIABILTY = 0x4;
 			int IPTOS_THROUGHPUT = 0x8;
 			int IPTOS_LOWDELAY = 0x10;
+			int[] ports = Support_PortManager.getNextPortsForUDP(2);
 
 			new InetSocketAddress(InetAddress.getLocalHost(),
-					Support_PortManager.getNextPort());
-			DatagramSocket theSocket = new DatagramSocket();
+					ports[0]);
+			DatagramSocket theSocket = new DatagramSocket(ports[1]);
 
 			// validate that value set must be between 0 and 255
 			try {
@@ -1878,10 +1888,11 @@
 			int IPTOS_RELIABILTY = 0x4;
 			int IPTOS_THROUGHPUT = 0x8;
 			int IPTOS_LOWDELAY = 0x10;
+			int[] ports = Support_PortManager.getNextPortsForUDP(2);
 
 			new InetSocketAddress(InetAddress.getLocalHost(),
-					Support_PortManager.getNextPort());
-			DatagramSocket theSocket = new DatagramSocket();
+					ports[0]);
+			DatagramSocket theSocket = new DatagramSocket(ports[1]);
 
 			/*
 			 * we cannot actually check that the values are set as if a platform
@@ -1909,7 +1920,7 @@
 					.isClosed());
 
 			InetSocketAddress theAddress = new InetSocketAddress(InetAddress
-					.getLocalHost(), Support_PortManager.getNextPort());
+					.getLocalHost(), Support_PortManager.getNextPortForUDP());
 			theSocket = new DatagramSocket(theAddress);
 			assertFalse("Socket should indicate it is not closed(2):",
 					theSocket.isClosed());
@@ -1949,8 +1960,8 @@
 	}
 
 	protected void receive_oversize_java_net_DatagramPacket() {
-
-		final int portNumber = Support_PortManager.getNextPort();
+		final int[] ports = Support_PortManager.getNextPortsForUDP(2);
+		final int portNumber = ports[0];
 
 		class TestDGRcvOver implements Runnable {
 			public void run() {
@@ -1958,8 +1969,7 @@
 				try {
 					localHost = InetAddress.getLocalHost();
 					Thread.sleep(1000);
-					DatagramSocket sds = new DatagramSocket(Support_PortManager
-							.getNextPort());
+					DatagramSocket sds = new DatagramSocket(ports[1]);
 					DatagramPacket rdp = new DatagramPacket("0123456789"
 							.getBytes(), 10, localHost, portNumber);
 					sds.send(rdp);

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java?view=diff&rev=512257&r1=512256&r2=512257
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java
Tue Feb 27 06:04:04 2007
@@ -149,7 +149,7 @@
 		// java.net.MulticastSocket.getInterface()
 		assertTrue("Used for testing.", true);
 
-		int groupPort = Support_PortManager.getNextPort();
+		int groupPort = Support_PortManager.getNextPortForUDP();
 		try {
 			if (atLeastOneInterface) {
 				// validate that we get the expected response when one was not
@@ -187,7 +187,7 @@
 									+ mss.getInterface(), firstAddress
 									.equals(mss.getInterface()));
 
-					groupPort = Support_PortManager.getNextPort();
+					groupPort = Support_PortManager.getNextPortForUDP();
 					mss = new MulticastSocket(groupPort);
 					mss.setNetworkInterface(networkInterface1);
 					assertTrue(
@@ -208,7 +208,7 @@
 	 * @tests java.net.MulticastSocket#getNetworkInterface()
 	 */
 	public void test_getNetworkInterface() {
-		int groupPort = Support_PortManager.getNextPort();
+		int groupPort = Support_PortManager.getNextPortForUDP();
 		try {
 			if (atLeastOneInterface) {
 
@@ -256,7 +256,7 @@
 							networkInterface2.equals(mss.getNetworkInterface()));
 				}
 
-				groupPort = Support_PortManager.getNextPort();
+				groupPort = Support_PortManager.getNextPortForUDP();
 				mss = new MulticastSocket(groupPort);
 				if (IPV6networkInterface1 != null) {
 					mss.setNetworkInterface(IPV6networkInterface1);
@@ -268,7 +268,7 @@
 
 				// validate that we get the expected response when we set via
 				// setInterface
-				groupPort = Support_PortManager.getNextPort();
+				groupPort = Support_PortManager.getNextPortForUDP();
 				mss = new MulticastSocket(groupPort);
 				Enumeration addresses = networkInterface1.getInetAddresses();
 				if (addresses != null) {
@@ -328,14 +328,15 @@
 		// java.net.MulticastSocket.joinGroup(java.net.InetAddress)
 		String msg = null;
 		InetAddress group = null;
-		int groupPort = Support_PortManager.getNextPort();
+		int[] ports = Support_PortManager.getNextPortsForUDP(2);
+		int groupPort = ports[0];
 		try {
 			group = InetAddress.getByName("224.0.0.3");
 			server = new MulticastServer(group, groupPort);
 			server.start();
 			Thread.sleep(1000);
 			msg = "Hello World";
-			mss = new MulticastSocket(Support_PortManager.getNextPort());
+			mss = new MulticastSocket(ports[1]);
 			DatagramPacket sdp = new DatagramPacket(msg.getBytes(), msg
 					.length(), group, groupPort);
 			mss.send(sdp, (byte) 10);
@@ -364,8 +365,9 @@
 		String msg = null;
 		InetAddress group = null;
 		SocketAddress groupSockAddr = null;
-		int groupPort = Support_PortManager.getNextPort();
-		int serverPort = Support_PortManager.getNextPort();
+		int[] ports = Support_PortManager.getNextPortsForUDP(2);
+		int groupPort = ports[0];
+		int serverPort = ports[1];
 
 		try {
 			Enumeration theInterfaces = NetworkInterface.getNetworkInterfaces();
@@ -404,8 +406,9 @@
 			if (atLeastOneInterface) {
 				// now validate that we can properly join a group with a null
 				// network interface
-				groupPort = Support_PortManager.getNextPort();
-				serverPort = Support_PortManager.getNextPort();
+				ports = Support_PortManager.getNextPortsForUDP(2);
+				groupPort = ports[0];
+				serverPort = ports[1];
 				mss = new MulticastSocket(groupPort);
 				mss.joinGroup(groupSockAddr, null);
 				mss.setTimeToLive(2);
@@ -433,13 +436,14 @@
 				// now validate that we handled the case were we join a
 				// different multicast address.
 				// verify we do not receive the data
-				serverPort = Support_PortManager.getNextPort();
+				ports = Support_PortManager.getNextPortsForUDP(2);
+				serverPort = ports[0];
 				server = new MulticastServer(groupSockAddr, serverPort,
 						networkInterface1);
 				server.start();
 				Thread.sleep(1000);
 
-				groupPort = Support_PortManager.getNextPort();
+				groupPort = ports[1];
 				mss = new MulticastSocket(groupPort);
 				InetAddress group2 = InetAddress.getByName("224.0.0.4");
 				mss.setTimeToLive(10);
@@ -513,8 +517,9 @@
 										.nextElement();
 							}
 
-							serverPort = Support_PortManager.getNextPort();
-							groupPort = Support_PortManager.getNextPort();
+							ports = Support_PortManager.getNextPortsForUDP(2);
+							serverPort = ports[0];
+							groupPort = ports[1];
 							groupSockAddr = new InetSocketAddress(group,
 									serverPort);
 							server = new MulticastServer(groupSockAddr,
@@ -555,7 +560,7 @@
 
 					// validate that we can join the same address on two
 					// different interfaces but not on the same interface
-					groupPort = Support_PortManager.getNextPort();
+					groupPort = Support_PortManager.getNextPortForUDP();
 					mss = new MulticastSocket(groupPort);
 					mss.joinGroup(groupSockAddr, networkInterface1);
 					mss.joinGroup(groupSockAddr, networkInterface2);
@@ -582,12 +587,13 @@
 		String msg = null;
 		boolean except = false;
 		InetAddress group = null;
-		int groupPort = Support_PortManager.getNextPort();
+		int[] ports = Support_PortManager.getNextPortsForUDP(2);
+		int groupPort = ports[0];
 
 		try {
 			group = InetAddress.getByName("224.0.0.3");
 			msg = "Hello World";
-			mss = new MulticastSocket();
+			mss = new MulticastSocket(ports[1]);
 			DatagramPacket sdp = new DatagramPacket(msg.getBytes(), msg
 					.length(), group, groupPort);
 			mss.send(sdp, (byte) 10);
@@ -620,7 +626,7 @@
 
 		String msg = null;
 		InetAddress group = null;
-		int groupPort = Support_PortManager.getNextPort();
+		int groupPort = Support_PortManager.getNextPortForUDP();
 		SocketAddress groupSockAddr = null;
 		SocketAddress groupSockAddr2 = null;
 
@@ -661,7 +667,7 @@
 			if (atLeastOneInterface) {
 
 				// now test that we can join and leave a group successfully
-				groupPort = Support_PortManager.getNextPort();
+				groupPort = Support_PortManager.getNextPortForUDP();
 				mss = new MulticastSocket(groupPort);
 				groupSockAddr = new InetSocketAddress(group, groupPort);
 				mss.joinGroup(groupSockAddr, null);
@@ -712,11 +718,12 @@
 
 		String msg = "Hello World";
 		InetAddress group = null;
-		int groupPort = Support_PortManager.getNextPort();
+		int[] ports = Support_PortManager.getNextPortsForUDP(2);
+		int groupPort = ports[0];
 
 		try {
 			group = InetAddress.getByName("224.0.0.3");
-			mss = new MulticastSocket();
+			mss = new MulticastSocket(ports[1]);
 			server = new MulticastServer(group, groupPort);
 			server.start();
 			Thread.sleep(200);
@@ -803,8 +810,9 @@
 	public void test_setNetworkInterfaceLjava_net_NetworkInterface() {
 		String msg = null;
 		InetAddress group = null;
-		int groupPort = Support_PortManager.getNextPort();
-		int serverPort = Support_PortManager.getNextPort();
+		int[] ports = Support_PortManager.getNextPortsForUDP(2);
+		int groupPort = ports[0];
+		int serverPort = ports[1];
 		try {
 			if (atLeastOneInterface) {
 				// validate that null interface is handled ok
@@ -819,7 +827,7 @@
 				}
 
 				// validate that we can get and set the interface
-				groupPort = Support_PortManager.getNextPort();
+				groupPort = Support_PortManager.getNextPortForUDP();
 				mss = new MulticastSocket(groupPort);
 				mss.setNetworkInterface(networkInterface1);
 				assertTrue(
@@ -844,7 +852,8 @@
 								// Pseudo interface that was set
 								(Support_NetworkInterface
 										.useInterface(thisInterface) == true)) {
-							serverPort = Support_PortManager.getNextPort();
+							ports = Support_PortManager.getNextPortsForUDP(2);
+							serverPort = ports[0];
 							server = new MulticastServer(group, serverPort);
 							server.start();
 							// give the server some time to start up
@@ -854,7 +863,7 @@
 							// source address in the received packet
 							// should be one of the addresses for the interface
 							// set
-							groupPort = Support_PortManager.getNextPort();
+							groupPort = ports[1];
 							mss = new MulticastSocket(groupPort);
 							mss.setNetworkInterface(thisInterface);
 							msg = thisInterface.getName();
@@ -935,19 +944,19 @@
         assertTrue("should not be bound", !ms.isBound() && !ms.isClosed()
                 && !ms.isConnected());
         ms.bind(new InetSocketAddress(InetAddress.getLocalHost(),
-                Support_PortManager.getNextPort()));
+                Support_PortManager.getNextPortForUDP()));
         assertTrue("should be bound", ms.isBound() && !ms.isClosed()
                 && !ms.isConnected());
         ms.close();
         assertTrue("should be closed", ms.isClosed());
         ms = new MulticastSocket(new InetSocketAddress(InetAddress
-                .getLocalHost(), Support_PortManager.getNextPort()));
+                .getLocalHost(), Support_PortManager.getNextPortForUDP()));
         assertTrue("should be bound", ms.isBound() && !ms.isClosed()
                 && !ms.isConnected());
         ms.close();
         assertTrue("should be closed", ms.isClosed());
         ms = new MulticastSocket(new InetSocketAddress("localhost",
-                Support_PortManager.getNextPort()));
+                Support_PortManager.getNextPortForUDP()));
         assertTrue("should be bound", ms.isBound() && !ms.isClosed()
                 && !ms.isConnected());
         ms.close();
@@ -955,7 +964,7 @@
         boolean exception = false;
         try {
             ms = new MulticastSocket(new InetSocketAddress("unresolvedname",
-                    Support_PortManager.getNextPort()));
+                    Support_PortManager.getNextPortForUDP()));
         } catch (IOException e) {
             exception = true;
         }
@@ -1009,7 +1018,7 @@
      */
     public void test_setLoopbackModeSendReceive() throws IOException{
         final String ADDRESS = "224.1.2.3";
-        final int PORT = 6789;
+        final int PORT = Support_PortManager.getNextPortForUDP();
         final String message = "Hello, world!";
 
         // test send receive
@@ -1055,7 +1064,7 @@
 			try {
 				InetSocketAddress theAddress = new InetSocketAddress(
 						InetAddress.getLocalHost(), Support_PortManager
-								.getNextPort());
+								.getNextPortForUDP());
 				theSocket1 = new MulticastSocket(null);
 				theSocket2 = new MulticastSocket(null);
 				theSocket1.setReuseAddress(false);
@@ -1076,7 +1085,7 @@
 			try {
 				InetSocketAddress theAddress = new InetSocketAddress(
 						InetAddress.getLocalHost(), Support_PortManager
-								.getNextPort());
+								.getNextPortForUDP());
 				theSocket1 = new MulticastSocket(null);
 				theSocket2 = new MulticastSocket(null);
 				theSocket1.setReuseAddress(true);
@@ -1097,7 +1106,7 @@
 			try {
 				InetSocketAddress theAddress = new InetSocketAddress(
 						InetAddress.getLocalHost(), Support_PortManager
-								.getNextPort());
+								.getNextPortForUDP());
 				theSocket1 = new MulticastSocket(null);
 				theSocket2 = new MulticastSocket(null);
 				theSocket1.bind(theAddress);



Mime
View raw message