|
@@ -142,7 +142,8 @@ public class TestConfiguredFailoverProxyProvider {
|
|
|
* Add more DNS related settings to the passed in configuration.
|
|
|
* @param config Configuration file to add settings to.
|
|
|
*/
|
|
|
- private void addDNSSettings(Configuration config, boolean hostResolvable) {
|
|
|
+ private void addDNSSettings(Configuration config,
|
|
|
+ boolean hostResolvable, boolean useFQDN) {
|
|
|
config.set(
|
|
|
HdfsClientConfigKeys.DFS_HA_NAMENODES_KEY_PREFIX + "." + ns3, "nn");
|
|
|
String domain = hostResolvable
|
|
@@ -163,6 +164,10 @@ public class TestConfiguredFailoverProxyProvider {
|
|
|
config.setBoolean(
|
|
|
HdfsClientConfigKeys.Failover.RANDOM_ORDER + "." + ns3,
|
|
|
true);
|
|
|
+ config.setBoolean(
|
|
|
+ HdfsClientConfigKeys.Failover.RESOLVE_ADDRESS_TO_FQDN + "." + ns3,
|
|
|
+ useFQDN
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -250,17 +255,18 @@ public class TestConfiguredFailoverProxyProvider {
|
|
|
nn1Count.get() + nn2Count.get() + nn3Count.get());
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- public void testResolveDomainNameUsingDNS() throws Exception {
|
|
|
+ private void testResolveDomainNameUsingDNS(boolean useFQDN) throws Exception {
|
|
|
Configuration dnsConf = new Configuration(conf);
|
|
|
- addDNSSettings(dnsConf, true);
|
|
|
+ addDNSSettings(dnsConf, true, useFQDN);
|
|
|
|
|
|
// Mock ClientProtocol
|
|
|
Map<InetSocketAddress, ClientProtocol> proxyMap = new HashMap<>();
|
|
|
final AtomicInteger nn1Count = addClientMock(
|
|
|
- MockDomainNameResolver.BYTE_ADDR_1, proxyMap);
|
|
|
+ useFQDN ? MockDomainNameResolver.FQDN_1 : MockDomainNameResolver.ADDR_1,
|
|
|
+ proxyMap);
|
|
|
final AtomicInteger nn2Count = addClientMock(
|
|
|
- MockDomainNameResolver.BYTE_ADDR_2, proxyMap);
|
|
|
+ useFQDN ? MockDomainNameResolver.FQDN_2 : MockDomainNameResolver.ADDR_2,
|
|
|
+ proxyMap);
|
|
|
|
|
|
// Get a client multiple times
|
|
|
final Map<String, AtomicInteger> proxyResults = new HashMap<>();
|
|
@@ -280,16 +286,18 @@ public class TestConfiguredFailoverProxyProvider {
|
|
|
proxy.getStats();
|
|
|
}
|
|
|
|
|
|
+ String resolvedHost1 = useFQDN ?
|
|
|
+ MockDomainNameResolver.FQDN_1 : "/" + MockDomainNameResolver.ADDR_1;
|
|
|
+ String resolvedHost2 = useFQDN ?
|
|
|
+ MockDomainNameResolver.FQDN_2 : "/" + MockDomainNameResolver.ADDR_2;
|
|
|
// Check we got the proper addresses
|
|
|
assertEquals(2, proxyResults.size());
|
|
|
assertTrue(
|
|
|
"nn1 wasn't returned: " + proxyResults,
|
|
|
- proxyResults.containsKey(
|
|
|
- "/" + MockDomainNameResolver.ADDR_1 + ":8020"));
|
|
|
+ proxyResults.containsKey(resolvedHost1 + ":8020"));
|
|
|
assertTrue(
|
|
|
"nn2 wasn't returned: " + proxyResults,
|
|
|
- proxyResults.containsKey(
|
|
|
- "/" + MockDomainNameResolver.ADDR_2 + ":8020"));
|
|
|
+ proxyResults.containsKey(resolvedHost2 + ":8020"));
|
|
|
|
|
|
// Check that the Namenodes were invoked
|
|
|
assertEquals(NUM_ITERATIONS, nn1Count.get() + nn2Count.get());
|
|
@@ -304,10 +312,18 @@ public class TestConfiguredFailoverProxyProvider {
|
|
|
nn2Count.get() > 0);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testResolveDomainNameUsingDNS() throws Exception {
|
|
|
+ // test resolving to IP
|
|
|
+ testResolveDomainNameUsingDNS(false);
|
|
|
+ // test resolving to FQDN
|
|
|
+ testResolveDomainNameUsingDNS(true);
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testResolveDomainNameUsingDNSUnknownHost() throws Exception {
|
|
|
Configuration dnsConf = new Configuration(conf);
|
|
|
- addDNSSettings(dnsConf, false);
|
|
|
+ addDNSSettings(dnsConf, false, false);
|
|
|
|
|
|
Map<InetSocketAddress, ClientProtocol> proxyMap = new HashMap<>();
|
|
|
exception.expect(RuntimeException.class);
|
|
@@ -321,19 +337,18 @@ public class TestConfiguredFailoverProxyProvider {
|
|
|
|
|
|
/**
|
|
|
* Add a ClientProtocol mock for the proxy.
|
|
|
- * @param addr IP address for the destination.
|
|
|
+ * @param host host name for the destination.
|
|
|
* @param proxyMap Map containing the client for each target address.
|
|
|
* @return The counter for the number of calls to this target.
|
|
|
* @throws Exception If the client cannot be created.
|
|
|
*/
|
|
|
private AtomicInteger addClientMock(
|
|
|
- byte[] addr, Map<InetSocketAddress, ClientProtocol> proxyMap)
|
|
|
- throws Exception {
|
|
|
+ String host, Map<InetSocketAddress, ClientProtocol> proxyMap)
|
|
|
+ throws Exception {
|
|
|
|
|
|
final AtomicInteger counter = new AtomicInteger(0);
|
|
|
- InetAddress inetAddr = InetAddress.getByAddress(addr);
|
|
|
InetSocketAddress inetSockerAddr =
|
|
|
- new InetSocketAddress(inetAddr, rpcPort);
|
|
|
+ new InetSocketAddress(host, rpcPort);
|
|
|
|
|
|
final ClientProtocol cpMock = mock(ClientProtocol.class);
|
|
|
when(cpMock.getStats()).thenAnswer(createAnswer(counter, 1));
|