testHandlerRemovedOnlyCalledWhenHandlerAddedCalled() — netty Function Reference
Architecture documentation for the testHandlerRemovedOnlyCalledWhenHandlerAddedCalled() function in DefaultChannelPipelineTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 64e2dc51_466a_c1e7_2efe_42bfee4417bd["testHandlerRemovedOnlyCalledWhenHandlerAddedCalled()"] 666d912b_4166_a807_ed10_ba12f328a7b2["DefaultChannelPipelineTest"] 64e2dc51_466a_c1e7_2efe_42bfee4417bd -->|defined in| 666d912b_4166_a807_ed10_ba12f328a7b2 2d2a762a_b2a7_b92f_c9a9_231778acb218["run()"] 64e2dc51_466a_c1e7_2efe_42bfee4417bd -->|calls| 2d2a762a_b2a7_b92f_c9a9_231778acb218 19bd3906_4c8c_ae23_6c05_b7a84d367379["shutdownGracefully()"] 64e2dc51_466a_c1e7_2efe_42bfee4417bd -->|calls| 19bd3906_4c8c_ae23_6c05_b7a84d367379 76d0323d_6adb_0c4c_dee1_48f5476bd522["close()"] 64e2dc51_466a_c1e7_2efe_42bfee4417bd -->|calls| 76d0323d_6adb_0c4c_dee1_48f5476bd522 style 64e2dc51_466a_c1e7_2efe_42bfee4417bd fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java lines 1644–1707
@Test
public void testHandlerRemovedOnlyCalledWhenHandlerAddedCalled() throws Exception {
final EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory());
try {
final AtomicReference<Error> errorRef = new AtomicReference<Error>();
// As this only happens via a race we will verify 500 times. This was good enough to have it failed most of
// the time.
for (int i = 0; i < 500; i++) {
ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel()).sync();
final CountDownLatch latch = new CountDownLatch(1);
pipeline.addLast(new ChannelInboundHandlerAdapter() {
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
// Block just for a bit so we have a chance to trigger the race mentioned in the issue.
latch.await(50, TimeUnit.MILLISECONDS);
}
});
// Close the pipeline which will call destroy0(). This will remove each handler in the pipeline and
// should call handlerRemoved(...) if and only if handlerAdded(...) was called for the handler before.
pipeline.close();
pipeline.addLast(new ChannelInboundHandlerAdapter() {
private boolean handerAddedCalled;
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
handerAddedCalled = true;
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) {
if (!handerAddedCalled) {
errorRef.set(new AssertionError(
"handlerRemoved(...) called without handlerAdded(...) before"));
}
}
});
latch.countDown();
pipeline.channel().closeFuture().syncUninterruptibly();
// Schedule something on the EventLoop to ensure all other scheduled tasks had a chance to complete.
pipeline.channel().eventLoop().submit(new Runnable() {
@Override
public void run() {
// NOOP
}
}).syncUninterruptibly();
Error error = errorRef.get();
if (error != null) {
throw error;
}
}
} finally {
group.shutdownGracefully();
}
}
Domain
Subdomains
Source
Frequently Asked Questions
What does testHandlerRemovedOnlyCalledWhenHandlerAddedCalled() do?
testHandlerRemovedOnlyCalledWhenHandlerAddedCalled() is a function in the netty codebase, defined in transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java.
Where is testHandlerRemovedOnlyCalledWhenHandlerAddedCalled() defined?
testHandlerRemovedOnlyCalledWhenHandlerAddedCalled() is defined in transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java at line 1644.
What does testHandlerRemovedOnlyCalledWhenHandlerAddedCalled() call?
testHandlerRemovedOnlyCalledWhenHandlerAddedCalled() calls 3 function(s): close, run, shutdownGracefully.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free