DatagramMulticastTest Class — netty Architecture
Architecture documentation for the DatagramMulticastTest class in DatagramMulticastTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 7bb89696_7318_cc89_132f_ac17760ac2ee["DatagramMulticastTest"] 59f725b3_d71e_0340_9cb3_ab94afb3f68f["DatagramMulticastTest.java"] 7bb89696_7318_cc89_132f_ac17760ac2ee -->|defined in| 59f725b3_d71e_0340_9cb3_ab94afb3f68f c496a4c9_7f31_8752_7bed_c1ba7a389589["testMulticast()"] 7bb89696_7318_cc89_132f_ac17760ac2ee -->|method| c496a4c9_7f31_8752_7bed_c1ba7a389589 99b0c451_2d1e_0959_11d6_ca8f3bece750["assertInterfaceAddress()"] 7bb89696_7318_cc89_132f_ac17760ac2ee -->|method| 99b0c451_2d1e_0959_11d6_ca8f3bece750 273062d5_da05_63e4_b7c2_8ca682c86863["newFactories()"] 7bb89696_7318_cc89_132f_ac17760ac2ee -->|method| 273062d5_da05_63e4_b7c2_8ca682c86863 e15de1c5_0b2f_2ddf_bf4b_ed4c413c2482["InetSocketAddress()"] 7bb89696_7318_cc89_132f_ac17760ac2ee -->|method| e15de1c5_0b2f_2ddf_bf4b_ed4c413c2482 9e6b8f94_acf2_dfd0_61f9_40caaa752ff5["NetworkInterface()"] 7bb89696_7318_cc89_132f_ac17760ac2ee -->|method| 9e6b8f94_acf2_dfd0_61f9_40caaa752ff5 c8a13f80_abcc_d665_8462_96bfe944efd6["String()"] 7bb89696_7318_cc89_132f_ac17760ac2ee -->|method| c8a13f80_abcc_d665_8462_96bfe944efd6
Relationship Graph
Source Code
testsuite/src/main/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java lines 52–249
public class DatagramMulticastTest extends AbstractDatagramTest {
@Test
public void testMulticast(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testMulticast(bootstrap, bootstrap2);
}
});
}
public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable {
NetworkInterface iface = multicastNetworkInterface();
assumeTrue(iface != null, "No NetworkInterface found that supports multicast and " +
socketInternetProtocalFamily());
MulticastTestHandler mhandler = new MulticastTestHandler();
sb.handler(new SimpleChannelInboundHandler<Object>() {
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
// Nothing will be sent.
}
@Override
public boolean isSharable() {
return true;
}
});
cb.handler(mhandler);
sb.option(ChannelOption.IP_MULTICAST_IF, iface);
sb.option(ChannelOption.SO_REUSEADDR, true);
cb.option(ChannelOption.IP_MULTICAST_IF, iface);
cb.option(ChannelOption.SO_REUSEADDR, true);
DatagramChannel sc = null;
int attempts = 5;
ChannelFuture clientFuture;
do {
if (sc != null) {
sc.close().sync();
}
sc = (DatagramChannel) sb.bind(newSocketAddress(iface)).sync().channel();
if (sc instanceof OioDatagramChannel) {
// skip the test for OIO, as it fails because of
// No route to host which makes no sense.
// Maybe a JDK bug ?
sc.close().awaitUninterruptibly();
return;
}
assertEquals(iface, sc.config().getNetworkInterface());
assertInterfaceAddress(iface, sc.config().getInterface());
InetSocketAddress addr = sc.localAddress();
cb.localAddress(addr.getPort());
clientFuture = cb.bind().await();
} while (!clientFuture.isSuccess() && --attempts > 0);
DatagramChannel cc = (DatagramChannel) clientFuture.sync().channel();
assertEquals(iface, cc.config().getNetworkInterface());
assertInterfaceAddress(iface, cc.config().getInterface());
InetSocketAddress groupAddress = SocketUtils.socketAddress(groupAddress(), sc.localAddress().getPort());
cc.joinGroup(groupAddress, iface).sync();
sc.writeAndFlush(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
assertTrue(mhandler.await());
// leave the group
cc.leaveGroup(groupAddress, iface).sync();
// sleep a second to make sure we left the group
Thread.sleep(1000);
// we should not receive a message anymore as we left the group before
sc.writeAndFlush(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
Source
Frequently Asked Questions
What is the DatagramMulticastTest class?
DatagramMulticastTest is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java.
Where is DatagramMulticastTest defined?
DatagramMulticastTest is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java at line 52.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free