@Test public void testMXCatches() throws Exception { doAnswer(new ZoneCacheLookupRecordsAnswer(loadZone("test-zone.com."))) .when(mockedCache).lookupRecords(any(Name.class), anyInt(), anyInt()); dnsServer.setCache(mockedCache); Collection<String> res = dnsServer.findMXRecords("test-zone.com."); try { res.add(""); fail("MX Collection should not be modifiable"); } catch (UnsupportedOperationException e) { LOGGER.info("Ignored error", e); } assertThat(res.size()).isEqualTo(1); assertThat(res.iterator().next()).isEqualTo("mail.test-zone.com."); }
@Override public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException { TimeMetric timeMetric = metricFactory.timer("findMXRecords"); List<String> servers = new ArrayList<>(); try { servers = findMXRecordsRaw(hostname); return Collections.unmodifiableCollection(servers); } finally { if (servers.size() == 0) { LOGGER.info("Couldn't resolve MX records for domain {}.", hostname); try { getByName(hostname); servers.add(hostname); } catch (UnknownHostException uhe) { LOGGER.error("Couldn't resolve IP address for host {}.", hostname, uhe); } } timeMetric.stopAndPublish(); } }
DNSJavaService implements DNSService, DNSServiceMBean, Configurable { @Override public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException { TimeMetric timeMetric = metricFactory.timer("findMXRecords"); List<String> servers = new ArrayList<>(); try { servers = findMXRecordsRaw(hostname); return Collections.unmodifiableCollection(servers); } finally { if (servers.size() == 0) { LOGGER.info("Couldn't resolve MX records for domain {}.", hostname); try { getByName(hostname); servers.add(hostname); } catch (UnknownHostException uhe) { LOGGER.error("Couldn't resolve IP address for host {}.", hostname, uhe); } } timeMetric.stopAndPublish(); } } }
DNSJavaService implements DNSService, DNSServiceMBean, Configurable { @Override public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException { TimeMetric timeMetric = metricFactory.timer("findMXRecords"); List<String> servers = new ArrayList<>(); try { servers = findMXRecordsRaw(hostname); return Collections.unmodifiableCollection(servers); } finally { if (servers.size() == 0) { LOGGER.info("Couldn't resolve MX records for domain {}.", hostname); try { getByName(hostname); servers.add(hostname); } catch (UnknownHostException uhe) { LOGGER.error("Couldn't resolve IP address for host {}.", hostname, uhe); } } timeMetric.stopAndPublish(); } } @Inject  DNSJavaService(MetricFactory metricFactory); }
DNSJavaService implements DNSService, DNSServiceMBean, Configurable { @Override public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException { TimeMetric timeMetric = metricFactory.timer("findMXRecords"); List<String> servers = new ArrayList<>(); try { servers = findMXRecordsRaw(hostname); return Collections.unmodifiableCollection(servers); } finally { if (servers.size() == 0) { LOGGER.info("Couldn't resolve MX records for domain {}.", hostname); try { getByName(hostname); servers.add(hostname); } catch (UnknownHostException uhe) { LOGGER.error("Couldn't resolve IP address for host {}.", hostname, uhe); } } timeMetric.stopAndPublish(); } } @Inject  DNSJavaService(MetricFactory metricFactory); @Override void configure(HierarchicalConfiguration<ImmutableNode> configuration); @PostConstruct void init(); @Override String[] getDNSServers(); Name[] getSearchPaths(); @Override Collection<String> findMXRecords(String hostname); @Override InetAddress getByName(String host); @Override Collection<InetAddress> getAllByName(String host); @Override Collection<String> findTXTRecords(String hostname); @Override String getHostName(InetAddress addr); @Override InetAddress getLocalHost(); @Override int getMaximumCacheSize(); @Override int getCurrentCacheSize(); @Override void clearCache(); }
DNSJavaService implements DNSService, DNSServiceMBean, Configurable { @Override public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException { TimeMetric timeMetric = metricFactory.timer("findMXRecords"); List<String> servers = new ArrayList<>(); try { servers = findMXRecordsRaw(hostname); return Collections.unmodifiableCollection(servers); } finally { if (servers.size() == 0) { LOGGER.info("Couldn't resolve MX records for domain {}.", hostname); try { getByName(hostname); servers.add(hostname); } catch (UnknownHostException uhe) { LOGGER.error("Couldn't resolve IP address for host {}.", hostname, uhe); } } timeMetric.stopAndPublish(); } } @Inject  DNSJavaService(MetricFactory metricFactory); @Override void configure(HierarchicalConfiguration<ImmutableNode> configuration); @PostConstruct void init(); @Override String[] getDNSServers(); Name[] getSearchPaths(); @Override Collection<String> findMXRecords(String hostname); @Override InetAddress getByName(String host); @Override Collection<InetAddress> getAllByName(String host); @Override Collection<String> findTXTRecords(String hostname); @Override String getHostName(InetAddress addr); @Override InetAddress getLocalHost(); @Override int getMaximumCacheSize(); @Override int getCurrentCacheSize(); @Override void clearCache();  }