Skip to content

Commit f16cd9b

Browse files
committed
Changed write to writeAndFlush in DnsCodecTest
1 parent ef5c715 commit f16cd9b

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

codec/src/test/java/io/netty/handler/codec/dns/DnsCodecTest.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import io.netty.bootstrap.Bootstrap;
1919
import io.netty.channel.Channel;
2020
import io.netty.channel.ChannelHandlerContext;
21-
import io.netty.channel.ChannelInboundHandlerAdapter;
2221
import io.netty.channel.ChannelInitializer;
2322
import io.netty.channel.ChannelOption;
2423
import io.netty.channel.EventLoopGroup;
24+
import io.netty.channel.SimpleChannelInboundHandler;
2525
import io.netty.channel.nio.NioEventLoopGroup;
2626
import io.netty.channel.socket.nio.NioDatagramChannel;
2727

@@ -45,7 +45,7 @@ public void sendQuery() throws Exception {
4545
.handler(new Initializer());
4646
Channel ch = b.connect(address).sync().channel();
4747
DnsQuery query = new DnsQuery(15305);
48-
query.addQuestion(new Question("1.0.0.127.in-addr.arpa", DnsEntry.TYPE_PTR));
48+
query.addQuestion(new Question("206.226.125.74.in-addr.arpa", DnsEntry.TYPE_PTR)); // Google IP
4949
Assert.assertEquals("Invalid question count, expected 1.", 1, query.getHeader().questionCount());
5050
Assert.assertEquals("Invalid answer count, expected 0.", 0, query.getHeader().answerCount());
5151
Assert.assertEquals("Invalid authority resource record count, expected 0.", 0, query.getHeader()
@@ -54,7 +54,7 @@ public void sendQuery() throws Exception {
5454
.additionalResourceCount());
5555
Assert.assertEquals("Invalid type, should be TYPE_QUERY (0)", DnsHeader.TYPE_QUERY, query.getHeader()
5656
.getType());
57-
ch.write(query).sync();
57+
ch.writeAndFlush(query).sync();
5858
if (!ch.closeFuture().await(5000)) {
5959
System.err.println("DNS request timed out.");
6060
}
@@ -72,29 +72,26 @@ protected void initChannel(NioDatagramChannel ch) throws Exception {
7272
}
7373
}
7474

75-
class Handler extends ChannelInboundHandlerAdapter {
75+
class Handler extends SimpleChannelInboundHandler<DnsResponse> {
7676

7777
@Override
78-
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
78+
public void channelRead0(ChannelHandlerContext ctx, DnsResponse response) throws Exception {
7979
try {
80-
if (msg instanceof DnsResponse) {
81-
DnsResponse response = (DnsResponse) msg;
82-
DnsResponseHeader header = response.getHeader();
83-
Assert.assertEquals("Invalid response code, expected TYPE_RESPONSE (1).", DnsHeader.TYPE_RESPONSE,
84-
header.getType());
85-
Assert.assertFalse("Server response was truncated.", header.isTruncated());
86-
Assert.assertTrue("Inconsistency between recursion" + "desirability and availability.",
87-
header.isRecursionDesired() == header.isRecursionAvailable());
88-
Assert.assertEquals("Invalid ID returned from server.", 15305, response.getHeader().getId());
89-
Assert.assertEquals("Question count in response not 1.", 1, response.getHeader().questionCount());
90-
Assert.assertTrue("Server didn't send any resources.", response.getHeader().answerCount()
91-
+ response.getHeader().authorityResourceCount()
92-
+ response.getHeader().additionalResourceCount() > 0);
93-
List<Resource> answers = response.getAnswers();
94-
for (Resource answer : answers) {
95-
if (answer.type() == DnsEntry.TYPE_PTR) {
96-
System.out.println(DnsResponseDecoder.readName(answer.content()));
97-
}
80+
DnsResponseHeader header = response.getHeader();
81+
Assert.assertEquals("Invalid response code, expected TYPE_RESPONSE (1).", DnsHeader.TYPE_RESPONSE,
82+
header.getType());
83+
Assert.assertFalse("Server response was truncated.", header.isTruncated());
84+
Assert.assertTrue("Inconsistency between recursion" + "desirability and availability.",
85+
header.isRecursionDesired() == header.isRecursionAvailable());
86+
Assert.assertEquals("Invalid ID returned from server.", 15305, response.getHeader().getId());
87+
Assert.assertEquals("Question count in response not 1.", 1, response.getHeader().questionCount());
88+
Assert.assertTrue("Server didn't send any resources.", response.getHeader().answerCount()
89+
+ response.getHeader().authorityResourceCount()
90+
+ response.getHeader().additionalResourceCount() > 0);
91+
List<Resource> answers = response.getAnswers();
92+
for (Resource answer : answers) {
93+
if (answer.type() == DnsEntry.TYPE_PTR) {
94+
System.out.println(DnsResponseDecoder.readName(answer.content()));
9895
}
9996
}
10097
} finally {

0 commit comments

Comments
 (0)