From 1425e3d37ca38b436f018caa6559afd54cdd83fc Mon Sep 17 00:00:00 2001
From: Steve Loughran <stevel@apache.org>
Date: Fri, 6 Feb 2015 13:03:30 +0000
Subject: [PATCH] HADOOP-11535 TableMapping related tests failed due to
 'successful' resolving of invalid test hostname

---
 .../hadoop-common/CHANGES.txt                 |  3 ++
 .../apache/hadoop/net/TestTableMapping.java   | 43 ++++++++++---------
 2 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index 66c2cba70a..884ba664ce 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -873,6 +873,9 @@ Release 2.7.0 - UNRELEASED
     HADOOP-11526. Memory leak in Bzip2Compressor and Bzip2Decompressor.
     (Anu Engineer via cnauroth)
 
+    HADOOP-11535 TableMapping related tests failed due to 'successful'
+    resolving of invalid test hostname. (Kai Zheng via stevel)
+
 Release 2.6.1 - UNRELEASED
 
   INCOMPATIBLE CHANGES
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestTableMapping.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestTableMapping.java
index 5281694179..a93f9ea5e4 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestTableMapping.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestTableMapping.java
@@ -34,12 +34,15 @@
 import org.junit.Test;
 
 public class TestTableMapping {
+  private String hostName1 = "1.2.3.4";
+  private String hostName2 = "5.6.7.8";
+
   @Test
   public void testResolve() throws IOException {
     File mapFile = File.createTempFile(getClass().getSimpleName() +
         ".testResolve", ".txt");
-    Files.write("a.b.c /rack1\n" +
-                "1.2.3.4\t/rack2\n", mapFile, Charsets.UTF_8);
+    Files.write(hostName1 + " /rack1\n" +
+                hostName2 + "\t/rack2\n", mapFile, Charsets.UTF_8);
     mapFile.deleteOnExit();
     TableMapping mapping = new TableMapping();
 
@@ -48,8 +51,8 @@ public void testResolve() throws IOException {
     mapping.setConf(conf);
 
     List<String> names = new ArrayList<String>();
-    names.add("a.b.c");
-    names.add("1.2.3.4");
+    names.add(hostName1);
+    names.add(hostName2);
 
     List<String> result = mapping.resolve(names);
     assertEquals(names.size(), result.size());
@@ -61,8 +64,8 @@ public void testResolve() throws IOException {
   public void testTableCaching() throws IOException {
     File mapFile = File.createTempFile(getClass().getSimpleName() +
         ".testTableCaching", ".txt");
-    Files.write("a.b.c /rack1\n" +
-                "1.2.3.4\t/rack2\n", mapFile, Charsets.UTF_8);
+    Files.write(hostName1 + " /rack1\n" +
+        hostName2 + "\t/rack2\n", mapFile, Charsets.UTF_8);
     mapFile.deleteOnExit();
     TableMapping mapping = new TableMapping();
 
@@ -71,8 +74,8 @@ public void testTableCaching() throws IOException {
     mapping.setConf(conf);
 
     List<String> names = new ArrayList<String>();
-    names.add("a.b.c");
-    names.add("1.2.3.4");
+    names.add(hostName1);
+    names.add(hostName2);
 
     List<String> result1 = mapping.resolve(names);
     assertEquals(names.size(), result1.size());
@@ -94,8 +97,8 @@ public void testNoFile() {
     mapping.setConf(conf);
 
     List<String> names = new ArrayList<String>();
-    names.add("a.b.c");
-    names.add("1.2.3.4");
+    names.add(hostName1);
+    names.add(hostName2);
 
     List<String> result = mapping.resolve(names);
     assertEquals(names.size(), result.size());
@@ -112,8 +115,8 @@ public void testFileDoesNotExist() {
     mapping.setConf(conf);
 
     List<String> names = new ArrayList<String>();
-    names.add("a.b.c");
-    names.add("1.2.3.4");
+    names.add(hostName1);
+    names.add(hostName2);
 
     List<String> result = mapping.resolve(names);
     assertEquals(names.size(), result.size());
@@ -125,8 +128,8 @@ public void testFileDoesNotExist() {
   public void testClearingCachedMappings() throws IOException {
     File mapFile = File.createTempFile(getClass().getSimpleName() +
         ".testClearingCachedMappings", ".txt");
-    Files.write("a.b.c /rack1\n" +
-                "1.2.3.4\t/rack2\n", mapFile, Charsets.UTF_8);
+    Files.write(hostName1 + " /rack1\n" +
+                hostName2 + "\t/rack2\n", mapFile, Charsets.UTF_8);
     mapFile.deleteOnExit();
 
     TableMapping mapping = new TableMapping();
@@ -136,8 +139,8 @@ public void testClearingCachedMappings() throws IOException {
     mapping.setConf(conf);
 
     List<String> names = new ArrayList<String>();
-    names.add("a.b.c");
-    names.add("1.2.3.4");
+    names.add(hostName1);
+    names.add(hostName2);
 
     List<String> result = mapping.resolve(names);
     assertEquals(names.size(), result.size());
@@ -149,8 +152,8 @@ public void testClearingCachedMappings() throws IOException {
     mapping.reloadCachedMappings();
 
     names = new ArrayList<String>();
-    names.add("a.b.c");
-    names.add("1.2.3.4");
+    names.add(hostName1);
+    names.add(hostName2);
 
     result = mapping.resolve(names);
     assertEquals(names.size(), result.size());
@@ -172,8 +175,8 @@ public void testBadFile() throws IOException {
     mapping.setConf(conf);
 
     List<String> names = new ArrayList<String>();
-    names.add("a.b.c");
-    names.add("1.2.3.4");
+    names.add(hostName1);
+    names.add(hostName2);
 
     List<String> result = mapping.resolve(names);
     assertEquals(names.size(), result.size());
