001/* 002 * Copyright 2015-2020 the original author or authors 003 * 004 * This software is licensed under the Apache License, Version 2.0, 005 * the GNU Lesser General Public License version 2 or later ("LGPL") 006 * and the WTFPL. 007 * You may choose either license to govern your use of this software only 008 * upon the condition that you accept all of the terms of either 009 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL. 010 */ 011package org.minidns.integrationtest; 012 013import static org.junit.jupiter.api.Assertions.assertTrue; 014 015import java.io.IOException; 016 017import org.minidns.dnsname.DnsName; 018import org.minidns.dnssec.DnssecClient; 019import org.minidns.dnssec.DnssecQueryResult; 020import org.minidns.integrationtest.IntegrationTestTools.CacheConfig; 021import org.minidns.iterative.ReliableDnsClient.Mode; 022import org.minidns.record.Record.TYPE; 023import org.minidns.source.NetworkDataSourceWithAccounting; 024 025public class IterativeDnssecTest { 026 027 private static final DnsName DNSSEC_DOMAIN = IntegrationTestHelper.DNSSEC_DOMAIN; 028 private static final TYPE RR_TYPE = IntegrationTestHelper.RR_TYPE; 029 030 @IntegrationTest 031 public static void shouldRequireLessQueries() throws IOException { 032 DnssecClient normalCacheClient = getClient(CacheConfig.normal); 033 DnssecQueryResult normalCacheResult = normalCacheClient.queryDnssec(DNSSEC_DOMAIN, RR_TYPE); 034 assertTrue(normalCacheResult.isAuthenticData()); 035 NetworkDataSourceWithAccounting normalCacheNdswa = NetworkDataSourceWithAccounting.from(normalCacheClient); 036 037 DnssecClient extendedCacheClient = getClient(CacheConfig.extended); 038 DnssecQueryResult extendedCacheResult = extendedCacheClient.queryDnssec(DNSSEC_DOMAIN, RR_TYPE); 039 assertTrue(extendedCacheResult.isAuthenticData()); 040 NetworkDataSourceWithAccounting extendedCacheNdswa = NetworkDataSourceWithAccounting.from(extendedCacheClient); 041 042 final int normalCacheSuccessfulQueries = normalCacheNdswa.getStats().successfulQueries; 043 final int extendedCacheSuccessfulQueries = extendedCacheNdswa.getStats().successfulQueries; 044 assertTrue( 045 normalCacheSuccessfulQueries > extendedCacheSuccessfulQueries, 046 "Extend cache successful query count " + extendedCacheSuccessfulQueries 047 + " is not less than normal cache successful query count " + normalCacheSuccessfulQueries); 048 } 049 050 private static DnssecClient getClient(CacheConfig cacheConfig) { 051 DnssecClient client = IntegrationTestTools.getClient(cacheConfig); 052 client.setMode(Mode.iterativeOnly); 053 return client; 054 } 055}