Author: pferraro
Date: 2009-05-29 13:54:27 -0400 (Fri, 29 May 2009)
New Revision: 2463
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/advertise/MulticastSocketFactoryImplTestCase.java
Log:
code cleanup
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
16:05:16 UTC (rev 2462)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/advertise/MulticastSocketFactoryImplTestCase.java 2009-05-29
17:54:27 UTC (rev 2463)
@@ -26,6 +26,7 @@
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
+import java.net.SocketTimeoutException;
import java.util.Arrays;
import org.jboss.modcluster.advertise.impl.AdvertiseListenerImpl;
@@ -40,16 +41,16 @@
*/
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;
+ private static final String GROUP1 = "224.0.1.106";
+ private static final String GROUP2 = "224.0.1.107";
+ private static final int PORT = 23365;
@Test
public void testMulticastSocket() throws IOException
{
String os = System.getProperty("os.name");
- boolean linux = os.trim().toLowerCase().startsWith("linux");
+ boolean linux = (os != null) &&
os.trim().toLowerCase().startsWith("linux");
try
{
@@ -74,43 +75,45 @@
public void testMulticastSocket(boolean allowCrossTalking) throws IOException
{
- InetAddress groupAddress = InetAddress.getByName(ADVERTISE_GROUP);
+ InetAddress address = InetAddress.getByName(GROUP1);
- MulticastSocket factorySocket = new
MulticastSocketFactoryImpl().createMulticastSocket(groupAddress, ADVERTISE_PORT);
+ MulticastSocket socket = new
MulticastSocketFactoryImpl().createMulticastSocket(address, PORT);
- factorySocket.setSoTimeout(5000);
+ socket.setSoTimeout(1000);
try
{
- factorySocket.joinGroup(groupAddress);
+ socket.joinGroup(address);
- this.testMulticastSocket(factorySocket, groupAddress, true);
+ this.testMulticastSocket(socket, address, address, true);
// Test for cross-talking
- this.testMulticastSocket(factorySocket, InetAddress.getByName(OTHER_GROUP),
allowCrossTalking);
+ this.testMulticastSocket(socket, address, InetAddress.getByName(GROUP2),
allowCrossTalking);
- factorySocket.leaveGroup(groupAddress);
+ socket.leaveGroup(address);
}
finally
{
- factorySocket.close();
+ socket.close();
}
}
- public void testMulticastSocket(MulticastSocket factorySocket, InetAddress
groupAddress, boolean expectSuccessfulRead) throws IOException
+ public void testMulticastSocket(MulticastSocket receiveSocket, InetAddress
receiveAddress, InetAddress sendAddress, boolean expectSuccessfulRead) throws IOException
{
- MulticastSocket socket = new
MulticastSocketFactoryImpl().createMulticastSocket(groupAddress, ADVERTISE_PORT);
+ MulticastSocket sendSocket = new
MulticastSocketFactoryImpl().createMulticastSocket(sendAddress, PORT);
try
{
- socket.joinGroup(groupAddress);
+ sendSocket.joinGroup(sendAddress);
String data = "1234567890";
byte[] buffer = data.getBytes();
- DatagramPacket packet = new DatagramPacket(buffer, buffer.length, groupAddress,
ADVERTISE_PORT);
+ DatagramPacket packet = new DatagramPacket(buffer, buffer.length, sendAddress,
PORT);
- socket.send(packet);
+// this.describe(sendSocket);
+ sendSocket.send(packet);
+
try
{
Thread.sleep(20);
@@ -126,7 +129,7 @@
try
{
- factorySocket.receive(packet);
+ receiveSocket.receive(packet);
if (expectSuccessfulRead)
{
@@ -134,22 +137,42 @@
}
else
{
- Assert.fail("Unexpected multicast cross-talking");
+ Assert.fail("Unexpected multicast group cross-talking");
}
}
- catch (IOException e)
+ catch (SocketTimeoutException e)
{
- if (expectSuccessfulRead)
+ if (!expectSuccessfulRead)
{
- Assert.fail(e.getMessage());
+ throw e;
}
}
- socket.leaveGroup(groupAddress);
+ sendSocket.leaveGroup(sendAddress);
}
finally
{
- socket.close();
+ 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