Fix DatagramMulticastTest failure

- Also:
  - Unwrap InvocationTargetException
This commit is contained in:
Trustin Lee 2012-06-03 03:11:56 -07:00
parent b47b54df37
commit 9abc88583c
4 changed files with 14 additions and 6 deletions

View File

@ -22,6 +22,7 @@ import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.SocketAddresses; import io.netty.util.SocketAddresses;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.List; import java.util.List;
@ -44,7 +45,7 @@ public abstract class AbstractDatagramTest {
protected volatile Bootstrap cb; protected volatile Bootstrap cb;
protected volatile InetSocketAddress addr; protected volatile InetSocketAddress addr;
protected void run() throws Exception { protected void run() throws Throwable {
int i = 0; int i = 0;
for (Entry<Factory<Bootstrap>, Factory<Bootstrap>> e: COMBO) { for (Entry<Factory<Bootstrap>, Factory<Bootstrap>> e: COMBO) {
sb = e.getKey().newInstance(); sb = e.getKey().newInstance();
@ -60,6 +61,8 @@ public abstract class AbstractDatagramTest {
Method m = getClass().getDeclaredMethod( Method m = getClass().getDeclaredMethod(
testName.getMethodName(), Bootstrap.class, Bootstrap.class); testName.getMethodName(), Bootstrap.class, Bootstrap.class);
m.invoke(this, sb, cb); m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
} finally { } finally {
sb.shutdown(); sb.shutdown();
cb.shutdown(); cb.shutdown();

View File

@ -23,6 +23,7 @@ import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.SocketAddresses; import io.netty.util.SocketAddresses;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.List; import java.util.List;
@ -61,6 +62,8 @@ public abstract class AbstractSocketTest {
Method m = getClass().getDeclaredMethod( Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class); testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);
m.invoke(this, sb, cb); m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
} finally { } finally {
sb.shutdown(); sb.shutdown();
cb.shutdown(); cb.shutdown();

View File

@ -43,8 +43,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable { public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable {
MulticastTestHandler mhandler = new MulticastTestHandler(); MulticastTestHandler mhandler = new MulticastTestHandler();
sb.handler(mhandler); sb.handler(new ChannelInboundMessageHandlerAdapter<DatagramPacket>() {
cb.handler(new ChannelInboundMessageHandlerAdapter<DatagramPacket>() {
@Override @Override
public void messageReceived( public void messageReceived(
ChannelInboundHandlerContext<DatagramPacket> ctx, ChannelInboundHandlerContext<DatagramPacket> ctx,
@ -53,11 +52,13 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
} }
}); });
cb.handler(mhandler);
sb.option(ChannelOption.IP_MULTICAST_IF, SocketAddresses.LOOPBACK_IF); sb.option(ChannelOption.IP_MULTICAST_IF, SocketAddresses.LOOPBACK_IF);
sb.option(ChannelOption.SO_REUSEADDR, true); sb.option(ChannelOption.SO_REUSEADDR, true);
cb.option(ChannelOption.IP_MULTICAST_IF, SocketAddresses.LOOPBACK_IF); cb.option(ChannelOption.IP_MULTICAST_IF, SocketAddresses.LOOPBACK_IF);
cb.option(ChannelOption.SO_REUSEADDR, true); cb.option(ChannelOption.SO_REUSEADDR, true);
cb.localAddress(addr); cb.localAddress(addr.getPort());
Channel sc = sb.bind().sync().channel(); Channel sc = sb.bind().sync().channel();
DatagramChannel cc = (DatagramChannel) cb.bind().sync().channel(); DatagramChannel cc = (DatagramChannel) cb.bind().sync().channel();
@ -69,7 +70,6 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
sc.write(new DatagramPacket(ChannelBuffers.copyInt(1), groupAddress)).sync(); sc.write(new DatagramPacket(ChannelBuffers.copyInt(1), groupAddress)).sync();
assertTrue(mhandler.await()); assertTrue(mhandler.await());
sc.write(new DatagramPacket(ChannelBuffers.copyInt(1), groupAddress)).sync();
// leave the group // leave the group
cc.leaveGroup(groupAddress, SocketAddresses.LOOPBACK_IF).sync(); cc.leaveGroup(groupAddress, SocketAddresses.LOOPBACK_IF).sync();

View File

@ -2,6 +2,7 @@ package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.channel.socket.nio.NioEventLoop; import io.netty.channel.socket.nio.NioEventLoop;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
@ -94,7 +95,8 @@ final class SocketTestPermutation {
bfs.add(new Factory<Bootstrap>() { bfs.add(new Factory<Bootstrap>() {
@Override @Override
public Bootstrap newInstance() { public Bootstrap newInstance() {
return new Bootstrap().eventLoop(new NioEventLoop()).channel(new NioDatagramChannel()); return new Bootstrap().eventLoop(new NioEventLoop()).channel(
new NioDatagramChannel(InternetProtocolFamily.IPv4));
} }
}); });
bfs.add(new Factory<Bootstrap>() { bfs.add(new Factory<Bootstrap>() {