DnsCacheManipulator { public static void loadDnsCacheConfig() { final String DCM_CONFIG_FILE_NAME_KEY = "dcm.config.filename"; final String dcmConfigFileName = System.getProperty(DCM_CONFIG_FILE_NAME_KEY, "dns-cache.properties"); loadDnsCacheConfig(dcmConfigFileName); } private  DnsCacheManipulator(); static void setDnsCache(String host, String... ips); static void setDnsCache(long expireMillis, String host, String... ips); static void setDnsCache(Properties properties); static void loadDnsCacheConfig(); static void loadDnsCacheConfig(String propertiesFileName); @Nullable static DnsCacheEntry getDnsCache(String host); @Deprecated static List<DnsCacheEntry> getAllDnsCache(); static List<DnsCacheEntry> listDnsCache(); static DnsCache getWholeDnsCache(); static void removeDnsCache(String host); static void clearDnsCache(); static int getDnsCachePolicy(); static void setDnsCachePolicy(int cacheSeconds); static int getDnsNegativeCachePolicy(); static void setDnsNegativeCachePolicy(int negativeCacheSeconds);  }
@Test public void test_loadDnsCacheConfig() throws Exception { DnsCacheManipulator.loadDnsCacheConfig(); final String ip = InetAddress.getByName(DOMAIN1).getHostAddress(); assertEquals(IP1, ip); }
@Test public void test_loadDnsCacheConfig_from_D_Option() throws Exception { final String key = "dcm.config.filename"; System.setProperty(key, "customized-dns-cache.properties"); DnsCacheManipulator.loadDnsCacheConfig(); final String ip = InetAddress.getByName(DOMAIN_CUSTOMIZED).getHostAddress(); assertEquals(IP_CUSTOMIZED, ip); System.clearProperty(key); }
@Test public void test_loadDnsCacheConfig_fromMyConfig() throws Exception { DnsCacheManipulator.loadDnsCacheConfig("my-dns-cache.properties"); final String ip = InetAddress.getByName(DOMAIN2).getHostAddress(); assertEquals(IP2, ip); }
@Test public void test_configNotFound() throws Exception { try { DnsCacheManipulator.loadDnsCacheConfig("not-existed.properties"); fail(); } catch (DnsCacheManipulatorException expected) { assertEquals("Fail to find not-existed.properties on classpath!", expected.getMessage()); } }