use of sun.net.spi.nameservice.NameService in project hadoop by apache.
the class TestDFSClientFailover method testFileContextDoesntDnsResolveLogicalURI.
/**
* Same test as above, but for FileContext.
*/
@Test
public void testFileContextDoesntDnsResolveLogicalURI() throws Exception {
FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);
NameService spyNS = spyOnNameService();
String logicalHost = fs.getUri().getHost();
Configuration haClientConf = fs.getConf();
FileContext fc = FileContext.getFileContext(haClientConf);
Path root = new Path("/");
fc.listStatus(root);
fc.listStatus(fc.makeQualified(root));
fc.getDefaultFileSystem().getCanonicalServiceName();
// Ensure that the logical hostname was never resolved.
Mockito.verify(spyNS, Mockito.never()).lookupAllHostAddr(Mockito.eq(logicalHost));
}
use of sun.net.spi.nameservice.NameService in project hadoop by apache.
the class TestDFSClientFailover method testCreateProxyDoesntDnsResolveLogicalURI.
/**
* Test that creating proxy doesn't ever try to DNS-resolve the logical URI.
* Regression test for HDFS-9364.
*/
@Test(timeout = 60000)
public void testCreateProxyDoesntDnsResolveLogicalURI() throws IOException {
final NameService spyNS = spyOnNameService();
final Configuration conf = new HdfsConfiguration();
final String service = "nameservice1";
final String namenode = "namenode113";
conf.set(DFSConfigKeys.DFS_NAMESERVICES, service);
conf.set(FileSystem.FS_DEFAULT_NAME_KEY, "hdfs://" + service);
conf.set(HdfsClientConfigKeys.Failover.PROXY_PROVIDER_KEY_PREFIX + "." + service, "org.apache.hadoop.hdfs.server.namenode.ha." + "ConfiguredFailoverProxyProvider");
conf.set(DFSConfigKeys.DFS_HA_NAMENODES_KEY_PREFIX + "." + service, namenode);
conf.set(DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY + "." + service + "." + namenode, "localhost:9820");
// call createProxy implicitly and explicitly
Path p = new Path("/");
p.getFileSystem(conf);
NameNodeProxiesClient.createProxyWithClientProtocol(conf, FileSystem.getDefaultUri(conf), null);
NameNodeProxies.createProxy(conf, FileSystem.getDefaultUri(conf), NamenodeProtocol.class, null);
// Ensure that the logical hostname was never resolved.
Mockito.verify(spyNS, Mockito.never()).lookupAllHostAddr(Mockito.eq(service));
}
use of sun.net.spi.nameservice.NameService in project hadoop by apache.
the class TestDFSClientFailover method testDoesntDnsResolveLogicalURI.
/**
* Test that the client doesn't ever try to DNS-resolve the logical URI.
* Regression test for HADOOP-9150.
*/
@Test
public void testDoesntDnsResolveLogicalURI() throws Exception {
FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);
NameService spyNS = spyOnNameService();
String logicalHost = fs.getUri().getHost();
Path qualifiedRoot = fs.makeQualified(new Path("/"));
// Make a few calls against the filesystem.
fs.getCanonicalServiceName();
fs.listStatus(qualifiedRoot);
// Ensure that the logical hostname was never resolved.
Mockito.verify(spyNS, Mockito.never()).lookupAllHostAddr(Mockito.eq(logicalHost));
}
use of sun.net.spi.nameservice.NameService in project hadoop by apache.
the class TestDFSClientFailover method spyOnNameService.
/**
* Spy on the Java DNS infrastructure.
* This likely only works on Sun-derived JDKs, but uses JUnit's
* Assume functionality so that any tests using it are skipped on
* incompatible JDKs.
*/
private NameService spyOnNameService() {
try {
Field f = InetAddress.class.getDeclaredField("nameServices");
f.setAccessible(true);
Assume.assumeNotNull(f);
@SuppressWarnings("unchecked") List<NameService> nsList = (List<NameService>) f.get(null);
NameService ns = nsList.get(0);
Log log = LogFactory.getLog("NameServiceSpy");
ns = Mockito.mock(NameService.class, new GenericTestUtils.DelegateAnswer(log, ns));
nsList.set(0, ns);
return ns;
} catch (Throwable t) {
LOG.info("Unable to spy on DNS. Skipping test.", t);
// In case the JDK we're testing on doesn't work like Sun's, just
// skip the test.
Assume.assumeNoException(t);
throw new RuntimeException(t);
}
}
Aggregations