Author: pferraro
Date: 2009-05-29 11:27:51 -0400 (Fri, 29 May 2009)
New Revision: 2461
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/advertise/MulticastSocketFactoryImplTestCase.java
Log:
Update to test specifically for cross-talking on linux.
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
14:55:40 UTC (rev 2460)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/advertise/MulticastSocketFactoryImplTestCase.java 2009-05-29
15:27:51 UTC (rev 2461)
@@ -41,10 +41,11 @@
public class MulticastSocketFactoryImplTestCase
{
private static final String ADVERTISE_GROUP = "224.0.1.106";
+ private static final String OTHER_GROUP = "224.0.1.107";
private static final int ADVERTISE_PORT = 23365;
@Test
- public void testMulticastSocketNotLinux() throws IOException
+ public void testMulticastSocket() throws IOException
{
String os = System.getProperty("os.name");
@@ -52,12 +53,15 @@
try
{
+ this.testMulticastSocket(false);
+
if (linux)
{
+ // Validate cross-talking behavior on linux
System.setProperty("os.name", "OtherOS");
+
+ this.testMulticastSocket(true);
}
-
- this.testMulticastSocketAsLinux();
}
finally
{
@@ -68,19 +72,21 @@
}
}
- @Test
- public void testMulticastSocketAsLinux() throws IOException
+ public void testMulticastSocket(boolean allowCrossTalking) throws IOException
{
InetAddress groupAddress = InetAddress.getByName(ADVERTISE_GROUP);
- MulticastSocketFactory factory = new MulticastSocketFactoryImpl();
- MulticastSocket factorySocket = factory.createMulticastSocket(groupAddress,
ADVERTISE_PORT);
+ MulticastSocket factorySocket = new
MulticastSocketFactoryImpl().createMulticastSocket(groupAddress, ADVERTISE_PORT);
+ factorySocket.setSoTimeout(5000);
+
try
{
factorySocket.joinGroup(groupAddress);
- testMulticastSocket(factorySocket, groupAddress);
+ this.testMulticastSocket(factorySocket, groupAddress, true);
+ // Test for cross-talking
+ this.testMulticastSocket(factorySocket, InetAddress.getByName(OTHER_GROUP),
allowCrossTalking);
factorySocket.leaveGroup(groupAddress);
}
@@ -90,9 +96,9 @@
}
}
- public void testMulticastSocket(MulticastSocket factorySocket, InetAddress
groupAddress) throws IOException
+ public void testMulticastSocket(MulticastSocket factorySocket, InetAddress
groupAddress, boolean expectSuccessfulRead) throws IOException
{
- MulticastSocket socket = new MulticastSocket(ADVERTISE_PORT);
+ MulticastSocket socket = new
MulticastSocketFactoryImpl().createMulticastSocket(groupAddress, ADVERTISE_PORT);
try
{
@@ -118,10 +124,27 @@
packet = new DatagramPacket(buffer, buffer.length);
- factorySocket.receive(packet);
+ try
+ {
+ factorySocket.receive(packet);
+
+ if (expectSuccessfulRead)
+ {
+ Assert.assertArrayEquals(buffer, data.getBytes());
+ }
+ else
+ {
+ Assert.fail("Unexpected multicast cross-talking");
+ }
+ }
+ catch (IOException e)
+ {
+ if (expectSuccessfulRead)
+ {
+ Assert.fail(e.getMessage());
+ }
+ }
- Assert.assertArrayEquals(buffer, data.getBytes());
-
socket.leaveGroup(groupAddress);
}
finally
Show replies by date