Search in sources :

Example 1 with NameService

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));
}
Also used : Path(org.apache.hadoop.fs.Path) NameService(sun.net.spi.nameservice.NameService) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) FileContext(org.apache.hadoop.fs.FileContext) Test(org.junit.Test)

Example 2 with NameService

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));
}
Also used : Path(org.apache.hadoop.fs.Path) NameService(sun.net.spi.nameservice.NameService) Configuration(org.apache.hadoop.conf.Configuration) Test(org.junit.Test)

Example 3 with NameService

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));
}
Also used : Path(org.apache.hadoop.fs.Path) NameService(sun.net.spi.nameservice.NameService) FileSystem(org.apache.hadoop.fs.FileSystem) Test(org.junit.Test)

Example 4 with NameService

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);
    }
}
Also used : Field(java.lang.reflect.Field) NameService(sun.net.spi.nameservice.NameService) Log(org.apache.commons.logging.Log) List(java.util.List)

Aggregations

NameService (sun.net.spi.nameservice.NameService)4 Path (org.apache.hadoop.fs.Path)3 Test (org.junit.Test)3 Configuration (org.apache.hadoop.conf.Configuration)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Field (java.lang.reflect.Field)1 List (java.util.List)1 Log (org.apache.commons.logging.Log)1 FileContext (org.apache.hadoop.fs.FileContext)1