Author: pferraro
Date: 2009-05-29 17:25:56 -0400 (Fri, 29 May 2009)
New Revision: 2465
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/advertise/MulticastSocketFactoryImplTestCase.java
Log:
Separate single test method into allow vs disallow cross-talking
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/advertise/MulticastSocketFactoryImplTestCase.java
===================================================================
---
trunk/mod_cluster/src/test/java/org/jboss/modcluster/advertise/MulticastSocketFactoryImplTestCase.java 2009-05-29
20:55:57 UTC (rev 2464)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/advertise/MulticastSocketFactoryImplTestCase.java 2009-05-29
21:25:56 UTC (rev 2465)
@@ -29,15 +29,15 @@
import java.net.SocketTimeoutException;
import java.util.Arrays;
-import org.jboss.modcluster.advertise.impl.AdvertiseListenerImpl;
import org.jboss.modcluster.advertise.impl.MulticastSocketFactoryImpl;
import org.junit.Assert;
import org.junit.Test;
/**
- * Tests of {@link AdvertiseListenerImpl}.
+ * Tests {@link MulticastSocketFactoryImpl}.
*
* @author Brian Stansberry
+ * @author Paul Ferraro
*/
public class MulticastSocketFactoryImplTestCase
{
@@ -46,27 +46,26 @@
private static final int PORT = 23365;
@Test
- public void testMulticastSocket() throws IOException
+ public void testMulticastSocketNoCrossTalk() throws IOException
{
+ this.testMulticastSocket(false);
+ }
+
+ @Test
+ public void testMulticastSocketAllowCrossTalk() throws IOException
+ {
String os = System.getProperty("os.name");
- boolean linux = (os != null) &&
os.trim().toLowerCase().startsWith("linux");
-
- try
+ // Validate cross-talking behavior on linux only
+ if ((os != null) && os.trim().toLowerCase().startsWith("linux"))
{
- this.testMulticastSocket(false);
+ System.setProperty("os.name", "OtherOS");
- if (linux)
+ try
{
- // Validate cross-talking behavior on linux
- System.setProperty("os.name", "OtherOS");
-
this.testMulticastSocket(true);
}
- }
- finally
- {
- if (linux)
+ finally
{
System.setProperty("os.name", os);
}
@@ -85,9 +84,9 @@
{
socket.joinGroup(address);
- this.testMulticastSocket(socket, address, address, true);
+ this.testMulticastSocket(socket, address, true);
// Test for cross-talking
- this.testMulticastSocket(socket, address, InetAddress.getByName(GROUP2),
allowCrossTalking);
+ this.testMulticastSocket(socket, InetAddress.getByName(GROUP2),
allowCrossTalking);
socket.leaveGroup(address);
}
@@ -97,7 +96,7 @@
}
}
- public void testMulticastSocket(MulticastSocket receiveSocket, InetAddress
receiveAddress, InetAddress sendAddress, boolean expectSuccessfulRead) throws IOException
+ public void testMulticastSocket(MulticastSocket receiveSocket, InetAddress
sendAddress, boolean expectSuccessfulRead) throws IOException
{
MulticastSocket sendSocket = new
MulticastSocketFactoryImpl().createMulticastSocket(sendAddress, PORT);
@@ -110,8 +109,6 @@
byte[] buffer = data.getBytes();
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, sendAddress,
PORT);
-// this.describe(sendSocket);
-
sendSocket.send(packet);
try
@@ -131,21 +128,12 @@
{
receiveSocket.receive(packet);
- if (expectSuccessfulRead)
- {
- Assert.assertArrayEquals(buffer, data.getBytes());
- }
- else
- {
- Assert.fail("Unexpected multicast group cross-talking");
- }
+ Assert.assertTrue(expectSuccessfulRead);
+ Assert.assertArrayEquals(buffer, data.getBytes());
}
catch (SocketTimeoutException e)
{
- if (!expectSuccessfulRead)
- {
- throw e;
- }
+ Assert.assertFalse(expectSuccessfulRead);
}
sendSocket.leaveGroup(sendAddress);
@@ -155,24 +143,4 @@
sendSocket.close();
}
}
-
- private void describe(MulticastSocket socket) throws IOException
- {
- System.out.println("broadcast: " + socket.getBroadcast());
- System.out.println("local port: " + socket.getLocalPort());
- System.out.println("port: " + socket.getPort());
- System.out.println("receive buffer size: " +
socket.getReceiveBufferSize());
- System.out.println("send buffer size: " + socket.getSendBufferSize());
- System.out.println("timeout: " + socket.getSoTimeout());
- System.out.println("ttl: " + socket.getTimeToLive());
- System.out.println("class: " + socket.getTrafficClass());
- System.out.println("address: " + socket.getInetAddress());
- System.out.println("interface: " + socket.getInterface());
- System.out.println("local address: " + socket.getLocalAddress());
- System.out.println("local socket address: " +
socket.getLocalSocketAddress());
- System.out.println("loopback: " + socket.getLoopbackMode());
- System.out.println("interfaces: " + socket.getNetworkInterface());
- System.out.println("remote socket address: " +
socket.getRemoteSocketAddress());
- System.out.println("reuse: " + socket.getReuseAddress());
- }
}
Show replies by date