Search in sources :

Example 1 with DNSDataSource

use of org.minidns.source.DNSDataSource in project minidns by MiniDNS.

the class DNSClientTest method testReturnNullSource.

@Test
public void testReturnNullSource() throws IOException {
    class NullSource extends DNSDataSource {

        boolean queried = false;

        @Override
        public DNSMessage query(DNSMessage message, InetAddress address, int port) {
            queried = true;
            return null;
        }
    }
    DNSClient client = new DNSClient(new LRUCache(0));
    NullSource source = new NullSource();
    client.setDataSource(source);
    DNSMessage message = client.query("www.example.com", TYPE.A);
    assertNull(message);
    assertTrue(source.queried);
}
Also used : DNSDataSource(org.minidns.source.DNSDataSource) LRUCache(org.minidns.cache.LRUCache) InetAddress(java.net.InetAddress) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 2 with DNSDataSource

use of org.minidns.source.DNSDataSource in project minidns by MiniDNS.

the class AsyncApiTest method tcpAsyncApiTest.

public static void tcpAsyncApiTest() throws IOException {
    DNSDataSource dataSource = new AsyncNetworkDataSource();
    dataSource.setTimeout(60 * 60 * 1000);
    dataSource.setUdpPayloadSize(256);
    dataSource.setQueryMode(QueryMode.tcp);
    DNSClient client = new DNSClient();
    client.setDataSource(dataSource);
    client.setAskForDnssec(true);
    MiniDnsFuture<DNSMessage, IOException> future = client.queryAsync("google.com", Record.TYPE.AAAA);
    DNSMessage response = future.getOrThrow();
    assertEquals(RESPONSE_CODE.NO_ERROR, response.responseCode);
}
Also used : DNSDataSource(org.minidns.source.DNSDataSource) DNSClient(org.minidns.DNSClient) IOException(java.io.IOException) AsyncNetworkDataSource(org.minidns.source.async.AsyncNetworkDataSource) DNSMessage(org.minidns.dnsmessage.DNSMessage)

Aggregations

DNSMessage (org.minidns.dnsmessage.DNSMessage)2 DNSDataSource (org.minidns.source.DNSDataSource)2 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 Test (org.junit.Test)1 DNSClient (org.minidns.DNSClient)1 LRUCache (org.minidns.cache.LRUCache)1 AsyncNetworkDataSource (org.minidns.source.async.AsyncNetworkDataSource)1