Fix DatagramMulticastTest failure
- Also: - Unwrap InvocationTargetException
This commit is contained in:
parent
b47b54df37
commit
9abc88583c
@ -22,6 +22,7 @@ import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
|
||||
import io.netty.testsuite.util.TestUtils;
|
||||
import io.netty.util.SocketAddresses;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
@ -44,7 +45,7 @@ public abstract class AbstractDatagramTest {
|
||||
protected volatile Bootstrap cb;
|
||||
protected volatile InetSocketAddress addr;
|
||||
|
||||
protected void run() throws Exception {
|
||||
protected void run() throws Throwable {
|
||||
int i = 0;
|
||||
for (Entry<Factory<Bootstrap>, Factory<Bootstrap>> e: COMBO) {
|
||||
sb = e.getKey().newInstance();
|
||||
@ -60,6 +61,8 @@ public abstract class AbstractDatagramTest {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), Bootstrap.class, Bootstrap.class);
|
||||
m.invoke(this, sb, cb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
} finally {
|
||||
sb.shutdown();
|
||||
cb.shutdown();
|
||||
|
@ -23,6 +23,7 @@ import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
|
||||
import io.netty.testsuite.util.TestUtils;
|
||||
import io.netty.util.SocketAddresses;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
@ -61,6 +62,8 @@ public abstract class AbstractSocketTest {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);
|
||||
m.invoke(this, sb, cb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
} finally {
|
||||
sb.shutdown();
|
||||
cb.shutdown();
|
||||
|
@ -43,8 +43,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
|
||||
public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable {
|
||||
MulticastTestHandler mhandler = new MulticastTestHandler();
|
||||
|
||||
sb.handler(mhandler);
|
||||
cb.handler(new ChannelInboundMessageHandlerAdapter<DatagramPacket>() {
|
||||
sb.handler(new ChannelInboundMessageHandlerAdapter<DatagramPacket>() {
|
||||
@Override
|
||||
public void messageReceived(
|
||||
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.SO_REUSEADDR, true);
|
||||
cb.option(ChannelOption.IP_MULTICAST_IF, SocketAddresses.LOOPBACK_IF);
|
||||
cb.option(ChannelOption.SO_REUSEADDR, true);
|
||||
cb.localAddress(addr);
|
||||
cb.localAddress(addr.getPort());
|
||||
|
||||
Channel sc = sb.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();
|
||||
assertTrue(mhandler.await());
|
||||
sc.write(new DatagramPacket(ChannelBuffers.copyInt(1), groupAddress)).sync();
|
||||
|
||||
// leave the group
|
||||
cc.leaveGroup(groupAddress, SocketAddresses.LOOPBACK_IF).sync();
|
||||
|
@ -2,6 +2,7 @@ package io.netty.testsuite.transport.socket;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.socket.InternetProtocolFamily;
|
||||
import io.netty.channel.socket.nio.NioDatagramChannel;
|
||||
import io.netty.channel.socket.nio.NioEventLoop;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
@ -94,7 +95,8 @@ final class SocketTestPermutation {
|
||||
bfs.add(new Factory<Bootstrap>() {
|
||||
@Override
|
||||
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>() {
|
||||
|
Loading…
Reference in New Issue
Block a user