testWriteWhilePeerIsClosedReleaseObjectAndFailPromise() — netty Function Reference
Architecture documentation for the testWriteWhilePeerIsClosedReleaseObjectAndFailPromise() function in LocalChannelTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 18485282_3d01_ac4c_986e_a6de8a7bb348["testWriteWhilePeerIsClosedReleaseObjectAndFailPromise()"] d7e5442a_9b99_814d_2bd6_0be57237db65["LocalChannelTest"] 18485282_3d01_ac4c_986e_a6de8a7bb348 -->|defined in| d7e5442a_9b99_814d_2bd6_0be57237db65 78d57abe_e210_5c12_8165_f993bbe41a48["LatchChannelFutureListener()"] 18485282_3d01_ac4c_986e_a6de8a7bb348 -->|calls| 78d57abe_e210_5c12_8165_f993bbe41a48 d3c8aa54_ac5d_6944_e789_c2c22ce16089["closeChannel()"] 18485282_3d01_ac4c_986e_a6de8a7bb348 -->|calls| d3c8aa54_ac5d_6944_e789_c2c22ce16089 c89c9d89_4030_c998_7504_cb2fa2ef2bc8["channelRead()"] 18485282_3d01_ac4c_986e_a6de8a7bb348 -->|calls| c89c9d89_4030_c998_7504_cb2fa2ef2bc8 style 18485282_3d01_ac4c_986e_a6de8a7bb348 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
transport/src/test/java/io/netty/channel/local/LocalChannelTest.java lines 693–798
@Test
public void testWriteWhilePeerIsClosedReleaseObjectAndFailPromise() throws InterruptedException {
Bootstrap cb = new Bootstrap();
ServerBootstrap sb = new ServerBootstrap();
final CountDownLatch serverMessageLatch = new CountDownLatch(1);
final LatchChannelFutureListener serverChannelCloseLatch = new LatchChannelFutureListener(1);
final LatchChannelFutureListener clientChannelCloseLatch = new LatchChannelFutureListener(1);
final CountDownLatch writeFailLatch = new CountDownLatch(1);
final ByteBuf data = Unpooled.wrappedBuffer(new byte[1024]);
final ByteBuf data2 = Unpooled.wrappedBuffer(new byte[512]);
final CountDownLatch serverChannelLatch = new CountDownLatch(1);
final AtomicReference<Channel> serverChannelRef = new AtomicReference<Channel>();
try {
cb.group(group1)
.channel(LocalChannel.class)
.handler(new TestHandler());
sb.group(group2)
.channel(LocalServerChannel.class)
.childHandler(new ChannelInitializer<LocalChannel>() {
@Override
public void initChannel(LocalChannel ch) throws Exception {
ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (data.equals(msg)) {
ReferenceCountUtil.safeRelease(msg);
serverMessageLatch.countDown();
} else {
super.channelRead(ctx, msg);
}
}
});
serverChannelRef.set(ch);
serverChannelLatch.countDown();
}
});
Channel sc = null;
Channel cc = null;
try {
// Start server
sc = sb.bind(TEST_ADDRESS).syncUninterruptibly().channel();
// Connect to the server
cc = cb.connect(sc.localAddress()).syncUninterruptibly().channel();
assertTrue(serverChannelLatch.await(5, SECONDS));
final Channel ccCpy = cc;
final Channel serverChannelCpy = serverChannelRef.get();
serverChannelCpy.closeFuture().addListener(serverChannelCloseLatch);
ccCpy.closeFuture().addListener(clientChannelCloseLatch);
// Make sure a write operation is executed in the eventloop
cc.pipeline().lastContext().executor().execute(new Runnable() {
@Override
public void run() {
ccCpy.writeAndFlush(data.retainedDuplicate(), ccCpy.newPromise())
.addListener(future -> {
serverChannelCpy.eventLoop().execute(new Runnable() {
@Override
public void run() {
// The point of this test is to write while the peer is closed, so we should
// ensure the peer is actually closed before we write.
int waitCount = 0;
while (ccCpy.isOpen()) {
try {
Thread.sleep(50);
} catch (InterruptedException ignored) {
// ignored
}
if (++waitCount > 5) {
fail();
}
}
serverChannelCpy.writeAndFlush(data2.retainedDuplicate(),
serverChannelCpy.newPromise())
.addListener(f -> {
if (!f.isSuccess() &&
f.cause() instanceof ClosedChannelException) {
Domain
Subdomains
Source
Frequently Asked Questions
What does testWriteWhilePeerIsClosedReleaseObjectAndFailPromise() do?
testWriteWhilePeerIsClosedReleaseObjectAndFailPromise() is a function in the netty codebase, defined in transport/src/test/java/io/netty/channel/local/LocalChannelTest.java.
Where is testWriteWhilePeerIsClosedReleaseObjectAndFailPromise() defined?
testWriteWhilePeerIsClosedReleaseObjectAndFailPromise() is defined in transport/src/test/java/io/netty/channel/local/LocalChannelTest.java at line 693.
What does testWriteWhilePeerIsClosedReleaseObjectAndFailPromise() call?
testWriteWhilePeerIsClosedReleaseObjectAndFailPromise() calls 3 function(s): LatchChannelFutureListener, channelRead, closeChannel.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free