Print out the actual cause when an assertion failure happens during DatagramUnicastTest.testSimpleSendWithConnect
Motivation: We recently saw an assertion failure when running DatagramUnicastTest.testSimpleSendWithConnect. Modifications: - Adding more debug infos - Ensure we always correctly release the buffers. Result: More informations when tests fail.
This commit is contained in:
parent
a739d89792
commit
c0396818ca
|
@ -146,6 +146,10 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
|
|||
private void testSimpleSend0(Bootstrap sb, Bootstrap cb, ByteBuf buf, boolean bindClient,
|
||||
final byte[] bytes, int count, WrapType wrapType)
|
||||
throws Throwable {
|
||||
Channel sc = null;
|
||||
Channel cc = null;
|
||||
|
||||
try {
|
||||
cb.handler(new SimpleChannelInboundHandler<Object>() {
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, Object msgs) throws Exception {
|
||||
|
@ -154,9 +158,7 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
|
|||
});
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(count);
|
||||
Channel sc = setupServerChannel(sb, bytes, latch);
|
||||
|
||||
Channel cc;
|
||||
sc = setupServerChannel(sb, bytes, latch);
|
||||
if (bindClient) {
|
||||
cc = cb.bind(newSocketAddress()).sync().channel();
|
||||
} else {
|
||||
|
@ -183,21 +185,27 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
|
|||
}
|
||||
}
|
||||
// release as we used buf.retain() before
|
||||
buf.release();
|
||||
cc.flush();
|
||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
} finally {
|
||||
// release as we used buf.retain() before
|
||||
buf.release();
|
||||
|
||||
sc.close().sync();
|
||||
cc.close().sync();
|
||||
closeChannel(cc);
|
||||
closeChannel(sc);
|
||||
}
|
||||
}
|
||||
|
||||
private void testSimpleSendWithConnect(Bootstrap sb, Bootstrap cb, ByteBuf buf, final byte[] bytes, int count)
|
||||
throws Throwable {
|
||||
try {
|
||||
for (WrapType type : WrapType.values()) {
|
||||
testSimpleSendWithConnect0(sb, cb, buf.retain(), bytes, count, type);
|
||||
}
|
||||
} finally {
|
||||
assertTrue(buf.release());
|
||||
}
|
||||
}
|
||||
|
||||
private void testSimpleSendWithConnect0(Bootstrap sb, Bootstrap cb, ByteBuf buf, final byte[] bytes, int count,
|
||||
WrapType wrapType) throws Throwable {
|
||||
|
@ -208,10 +216,11 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
|
|||
}
|
||||
});
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(count);
|
||||
Channel sc = setupServerChannel(sb, bytes, latch);
|
||||
Channel sc = null;
|
||||
DatagramChannel cc = null;
|
||||
try {
|
||||
final CountDownLatch latch = new CountDownLatch(count);
|
||||
sc = setupServerChannel(sb, bytes, latch);
|
||||
cc = (DatagramChannel) cb.connect(sc.localAddress()).sync().channel();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
@ -243,15 +252,14 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
|
|||
|
||||
ChannelFuture future = cc.writeAndFlush(
|
||||
buf.retain().duplicate()).awaitUninterruptibly();
|
||||
assertTrue(future.cause() instanceof NotYetConnectedException);
|
||||
assertTrue("NotYetConnectedException expected, got: " + future.cause(),
|
||||
future.cause() instanceof NotYetConnectedException);
|
||||
} finally {
|
||||
// release as we used buf.retain() before
|
||||
buf.release();
|
||||
|
||||
sc.close().sync();
|
||||
if (cc != null) {
|
||||
cc.close().sync();
|
||||
}
|
||||
closeChannel(cc);
|
||||
closeChannel(sc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,4 +284,10 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
|
|||
});
|
||||
return sb.bind(newSocketAddress()).sync().channel();
|
||||
}
|
||||
|
||||
private static void closeChannel(Channel channel) throws Exception {
|
||||
if (channel != null) {
|
||||
channel.close().sync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user