LocalTransportThreadModelTest2 Class — netty Architecture
Architecture documentation for the LocalTransportThreadModelTest2 class in LocalTransportThreadModelTest2.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 466017c7_8ea0_bf8a_7ded_086ed4918c64["LocalTransportThreadModelTest2"] 7d5242f2_35c4_1a04_7c50_3abd776f4bb9["LocalTransportThreadModelTest2.java"] 466017c7_8ea0_bf8a_7ded_086ed4918c64 -->|defined in| 7d5242f2_35c4_1a04_7c50_3abd776f4bb9 48439426_aca2_f365_76b8_0bb2924f04f9["testSocketReuse()"] 466017c7_8ea0_bf8a_7ded_086ed4918c64 -->|method| 48439426_aca2_f365_76b8_0bb2924f04f9 babd54f5_2738_3d21_8934_12868f2e6b96["close()"] 466017c7_8ea0_bf8a_7ded_086ed4918c64 -->|method| babd54f5_2738_3d21_8934_12868f2e6b96
Relationship Graph
Source Code
transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest2.java lines 35–127
public class LocalTransportThreadModelTest2 {
private static final String LOCAL_CHANNEL = LocalTransportThreadModelTest2.class.getName();
static final int messageCountPerRun = 4;
@Test
@Timeout(value = 15000, unit = TimeUnit.MILLISECONDS)
public void testSocketReuse() throws InterruptedException {
ServerBootstrap serverBootstrap = new ServerBootstrap();
LocalHandler serverHandler = new LocalHandler("SERVER");
serverBootstrap
.group(new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory()))
.channel(LocalServerChannel.class)
.childHandler(serverHandler);
Bootstrap clientBootstrap = new Bootstrap();
LocalHandler clientHandler = new LocalHandler("CLIENT");
clientBootstrap
.group(new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory()))
.channel(LocalChannel.class)
.remoteAddress(new LocalAddress(LOCAL_CHANNEL)).handler(clientHandler);
serverBootstrap.bind(new LocalAddress(LOCAL_CHANNEL)).sync();
int count = 100;
for (int i = 1; i < count + 1; i ++) {
Channel ch = clientBootstrap.connect().sync().channel();
// SPIN until we get what we are looking for.
int target = i * messageCountPerRun;
while (serverHandler.count.get() != target || clientHandler.count.get() != target) {
Thread.sleep(50);
}
close(ch, clientHandler);
}
assertEquals(count * 2 * messageCountPerRun, serverHandler.count.get() +
clientHandler.count.get());
serverBootstrap.config().group().shutdownGracefully().sync();
clientBootstrap.config().group().shutdownGracefully().sync();
}
public void close(final Channel localChannel, final LocalHandler localRegistrationHandler) {
// we want to make sure we actually shutdown IN the event loop
if (localChannel.eventLoop().inEventLoop()) {
// Wait until all messages are flushed before closing the channel.
if (localRegistrationHandler.lastWriteFuture != null) {
localRegistrationHandler.lastWriteFuture.awaitUninterruptibly();
}
localChannel.close();
return;
}
localChannel.eventLoop().execute(new Runnable() {
@Override
public void run() {
close(localChannel, localRegistrationHandler);
}
});
// Wait until the connection is closed or the connection attempt fails.
localChannel.closeFuture().awaitUninterruptibly();
}
@Sharable
static class LocalHandler extends ChannelInboundHandlerAdapter {
private final String name;
public volatile ChannelFuture lastWriteFuture;
public final AtomicInteger count = new AtomicInteger(0);
LocalHandler(String name) {
this.name = name;
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
for (int i = 0; i < messageCountPerRun; i ++) {
Source
Frequently Asked Questions
What is the LocalTransportThreadModelTest2 class?
LocalTransportThreadModelTest2 is a class in the netty codebase, defined in transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest2.java.
Where is LocalTransportThreadModelTest2 defined?
LocalTransportThreadModelTest2 is defined in transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest2.java at line 35.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free