Debian Codegraph @

minidns-integration-test/src/main/java/org/minidns/integrationtest/AsyncApiTest.java

raw
1 /*
2 * Copyright 2015-2020 the original author or authors
3 *
4 * This software is licensed under the Apache License, Version 2.0,
5 * the GNU Lesser General Public License version 2 or later ("LGPL")
6 * and the WTFPL.
7 * You may choose either license to govern your use of this software only
8 * upon the condition that you accept all of the terms of either
9 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL.
10 */
11 package org.minidns.integrationtest;
12
13 import static org.junit.jupiter.api.Assertions.assertEquals;
14
15 import java.io.IOException;
16
17 import org.minidns.DnsClient;
18 import org.minidns.record.Record;
19 import org.minidns.MiniDnsFuture;
20 import org.minidns.dnsmessage.DnsMessage.RESPONSE_CODE;
21 import org.minidns.dnsqueryresult.DnsQueryResult;
22 import org.minidns.source.AbstractDnsDataSource;
23 import org.minidns.source.AbstractDnsDataSource.QueryMode;
24 import org.minidns.source.async.AsyncNetworkDataSource;
25
26 public class AsyncApiTest {
27
28 public static void main(String[] args) throws IOException {
29 tcpAsyncApiTest();
30 }
31
32 public static void simpleAsyncApiTest() throws IOException {
33 DnsClient client = new DnsClient();
34 client.setDataSource(new AsyncNetworkDataSource());
35 client.getDataSource().setTimeout(60 * 60 * 1000);
36
37 MiniDnsFuture<DnsQueryResult, IOException> future = client.queryAsync("example.com", Record.TYPE.NS);
38 DnsQueryResult result = future.getOrThrow();
39 assertEquals(RESPONSE_CODE.NO_ERROR, result.response.responseCode);
40 }
41
42 public static void tcpAsyncApiTest() throws IOException {
43 AbstractDnsDataSource dataSource = new AsyncNetworkDataSource();
44 dataSource.setTimeout(60 * 60 * 1000);
45 dataSource.setUdpPayloadSize(256);
46 dataSource.setQueryMode(QueryMode.tcp);
47
48 DnsClient client = new DnsClient();
49 client.setDataSource(dataSource);
50 client.setAskForDnssec(true);
51
52 MiniDnsFuture<DnsQueryResult, IOException> future = client.queryAsync("google.com", Record.TYPE.AAAA);
53 DnsQueryResult result = future.getOrThrow();
54 assertEquals(RESPONSE_CODE.NO_ERROR, result.response.responseCode);
55 }
56 }