You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by el...@apache.org on 2012/03/09 04:55:47 UTC

svn commit: r1298697 - in /hadoop/common/branches/branch-0.23/hadoop-common-project: ./ hadoop-auth/ hadoop-common/ hadoop-common/src/main/docs/ hadoop-common/src/main/java/ hadoop-common/src/main/java/org/apache/hadoop/net/ hadoop-common/src/test/core...

Author: eli
Date: Fri Mar  9 03:55:45 2012
New Revision: 1298697

URL: http://svn.apache.org/viewvc?rev=1298697&view=rev
Log:
HADOOP-8154. svn merge -c 1298696 from trunk

Modified:
    hadoop/common/branches/branch-0.23/hadoop-common-project/   (props changed)
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-auth/   (props changed)
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/   (props changed)
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt   (contents, props changed)
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/docs/   (props changed)
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/   (props changed)
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/DNS.java
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/core/   (props changed)
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestDNS.java

Propchange: hadoop/common/branches/branch-0.23/hadoop-common-project/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar  9 03:55:45 2012
@@ -1,2 +1,2 @@
 /hadoop/common/branches/branch-0.23-PB/hadoop-common-project:1227776-1294021
-/hadoop/common/trunk/hadoop-common-project:1161777,1161781,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1163981,1164255,1164301,1164339,1166009,1166402,1167383,1170379,1170459,1171297,1172916,1173402,1176550,1177487,1177531,1177859,1177864,1182189,1182205,1182214,1189613,1189932,1189982,1195575,1196113,1196129,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1212021,1212062,1212073,1212084,1213537,1213586,1213592-1213593,1213954,1214046,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227964,1229347,1230398,1231569,1231572,1231627,1231640,1233605,1234555,1235135,1235137,1235956,1236456,1239752,1240897,1240928,1243065,1243104,1244766,1245751,1245762,1293419,1295061,1295227,1295251,1298044
+/hadoop/common/trunk/hadoop-common-project:1161777,1161781,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1163981,1164255,1164301,1164339,1166009,1166402,1167383,1170379,1170459,1171297,1172916,1173402,1176550,1177487,1177531,1177859,1177864,1182189,1182205,1182214,1189613,1189932,1189982,1195575,1196113,1196129,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1212021,1212062,1212073,1212084,1213537,1213586,1213592-1213593,1213954,1214046,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227964,1229347,1230398,1231569,1231572,1231627,1231640,1233605,1234555,1235135,1235137,1235956,1236456,1239752,1240897,1240928,1243065,1243104,1244766,1245751,1245762,1293419,1295061,1295227,1295251,1298044,1298696

Propchange: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-auth/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar  9 03:55:45 2012
@@ -1,2 +1,2 @@
 /hadoop/common/branches/branch-0.23-PB/hadoop-common-project/hadoop-auth:1227776-1294021
-/hadoop/common/trunk/hadoop-common-project/hadoop-auth:1161777,1161781,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1163981,1164255,1164301,1164339,1166402,1167383,1170379,1170459,1171297,1172916,1173402,1176550,1177487,1177531,1177859,1177864,1179869,1182189,1182205,1182214,1189357,1189613,1189932,1189982,1195575,1196113,1196129,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1212021,1212062,1212073,1212084,1213537,1213586,1213592-1213593,1213954,1214046,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227964,1229347,1230398,1231569,1231572,1231627,1231640,1233605,1234555,1235135,1235137,1235956,1236456,1239752,1240897,1240928,1243065,1243104,1244766,1245751,1245762,1293419,1295061,1295227,1295251,1298044
+/hadoop/common/trunk/hadoop-common-project/hadoop-auth:1161777,1161781,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1163981,1164255,1164301,1164339,1166402,1167383,1170379,1170459,1171297,1172916,1173402,1176550,1177487,1177531,1177859,1177864,1179869,1182189,1182205,1182214,1189357,1189613,1189932,1189982,1195575,1196113,1196129,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1212021,1212062,1212073,1212084,1213537,1213586,1213592-1213593,1213954,1214046,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227964,1229347,1230398,1231569,1231572,1231627,1231640,1233605,1234555,1235135,1235137,1235956,1236456,1239752,1240897,1240928,1243065,1243104,1244766,1245751,1245762,1293419,1295061,1295227,1295251,1298044,1298696

Propchange: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar  9 03:55:45 2012
@@ -1,2 +1,2 @@
 /hadoop/common/branches/branch-0.23-PB/hadoop-common-project/hadoop-common:1227776-1294021
-/hadoop/common/trunk/hadoop-common-project/hadoop-common:1161777,1161781,1162008,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1164255,1164301,1164339,1164771,1166009,1166402,1167318,1167383,1170379,1170459,1171221,1171297,1172916,1173402,1176550,1176986,1177002,1177035,1177399,1177487,1177531,1177859,1177864,1178639,1179512,1179869,1182189,1182205,1182214,1182641,1183132,1189357,1189613,1189932,1189982,1190109,1190611,1195575,1195760,1196113,1196129,1197885,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204363,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1209246,1210208,1210319-1210320,1212004,1212021,1212062,1212073,1212084,1212615,1213537,1213586,1213592-1213593,1213598,1213619,1213954,1214046,1214114,1214499,1215358,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227861,1227964,1229347,1230
 398,1231569,1231572,1231627,1231640,1231732,1233605,1234555,1235135,1235137,1235956,1236444,1236456,1239386,1239752,1240897,1240928,1242485,1243065,1243104,1244185,1244766,1245751,1245762,1291602,1293071,1293419,1295061,1295227,1295240,1295251,1298044
+/hadoop/common/trunk/hadoop-common-project/hadoop-common:1161777,1161781,1162008,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1164255,1164301,1164339,1164771,1166009,1166402,1167318,1167383,1170379,1170459,1171221,1171297,1172916,1173402,1176550,1176986,1177002,1177035,1177399,1177487,1177531,1177859,1177864,1178639,1179512,1179869,1182189,1182205,1182214,1182641,1183132,1189357,1189613,1189932,1189982,1190109,1190611,1195575,1195760,1196113,1196129,1197885,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204363,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1209246,1210208,1210319-1210320,1212004,1212021,1212062,1212073,1212084,1212615,1213537,1213586,1213592-1213593,1213598,1213619,1213954,1214046,1214114,1214499,1215358,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227861,1227964,1229347,1230
 398,1231569,1231572,1231627,1231640,1231732,1233605,1234555,1235135,1235137,1235956,1236444,1236456,1239386,1239752,1240897,1240928,1242485,1243065,1243104,1244185,1244766,1245751,1245762,1291602,1293071,1293419,1295061,1295227,1295240,1295251,1298044,1298696

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1298697&r1=1298696&r2=1298697&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt Fri Mar  9 03:55:45 2012
@@ -117,6 +117,9 @@ Release 0.23.3 - UNRELEASED
     HADOOP-7888. TestFailoverProxy fails intermittently on trunk. (Jason Lowe
     via atm)
 
+    HADOOP-8154. DNS#getIPs shouldn't silently return the local host
+    IP for bogus interface names. (eli)
+
 Release 0.23.2 - UNRELEASED 
 
   NEW FEATURES

Propchange: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar  9 03:55:45 2012
@@ -1,6 +1,6 @@
 /hadoop/common/branches/branch-0.23-PB/hadoop-common-project/hadoop-common/CHANGES.txt:1227776-1294021
 /hadoop/common/branches/yahoo-merge/CHANGES.txt:1079157,1079163-1079164,1079167
-/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt:1161777,1161781,1162008,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1164255,1164301,1164771,1166009,1166402,1167318,1167383,1169986,1170046,1170379,1170459,1171221,1171297,1171894,1171909,1172186,1172916,1173402,1176550,1176986,1177002,1177035,1177399,1177487,1177531,1177859,1177864,1178639,1179512,1179869,1182189,1182205,1182214,1182641,1183132,1189357,1189613,1189932,1189982,1190109,1190611,1195575,1195760,1196113,1196129,1197885,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204363,1204376,1204388,1205260,1206830,1207694,1208153,1208313,1209246,1210208,1210319-1210320,1212004,1212062,1212073,1212084,1212615,1213537,1213586,1213592-1213593,1213598,1213619,1213954,1214046,1214114,1214499,1215358,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350-1226351,1227091,1227165,1227423,1227861,
 1227964,1229347,1230398,1231569,1231572,1231627,1231640,1231732,1233605,1234555,1235135,1235137,1235956,1236444,1236456,1239386,1239752,1240897,1240928,1242485,1243065,1243104,1244185,1244766,1245751,1245762,1291602,1293071,1293419,1295061,1295227,1295240,1295251,1298044
+/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt:1161777,1161781,1162008,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1164255,1164301,1164771,1166009,1166402,1167318,1167383,1169986,1170046,1170379,1170459,1171221,1171297,1171894,1171909,1172186,1172916,1173402,1176550,1176986,1177002,1177035,1177399,1177487,1177531,1177859,1177864,1178639,1179512,1179869,1182189,1182205,1182214,1182641,1183132,1189357,1189613,1189932,1189982,1190109,1190611,1195575,1195760,1196113,1196129,1197885,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204363,1204376,1204388,1205260,1206830,1207694,1208153,1208313,1209246,1210208,1210319-1210320,1212004,1212062,1212073,1212084,1212615,1213537,1213586,1213592-1213593,1213598,1213619,1213954,1214046,1214114,1214499,1215358,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350-1226351,1227091,1227165,1227423,1227861,
 1227964,1229347,1230398,1231569,1231572,1231627,1231640,1231732,1233605,1234555,1235135,1235137,1235956,1236444,1236456,1239386,1239752,1240897,1240928,1242485,1243065,1243104,1244185,1244766,1245751,1245762,1291602,1293071,1293419,1295061,1295227,1295240,1295251,1298044,1298696
 /hadoop/core/branches/branch-0.18/CHANGES.txt:727226
 /hadoop/core/branches/branch-0.19/CHANGES.txt:713112
 /hadoop/core/trunk/CHANGES.txt:776175-785643,785929-786278

Propchange: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/docs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar  9 03:55:45 2012
@@ -1,3 +1,3 @@
 /hadoop/common/branches/branch-0.23-PB/hadoop-common-project/hadoop-common/src/main/docs:1227776-1294021
-/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/docs:1161777,1161781,1162008,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1164255,1164301,1164339,1164771,1166402,1167318,1167383,1170379,1170459,1171297,1172916,1173402,1176550,1177487,1177531,1177859,1177864,1182189,1182205,1182214,1183132,1189613,1189932,1189982,1195575,1196113,1196129,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1209246,1212021,1212062,1212073,1212084,1213537,1213586,1213592-1213593,1213954,1214046,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227964,1229347,1230398,1231569,1231572,1231627,1231640,1233605,1234555,1235135,1235137,1235956,1236456,1239752,1240897,1240928,1243065,1243104,1244766,1245751,1245762,1293419,1295061,1295227,1298044
+/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/docs:1161777,1161781,1162008,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1164255,1164301,1164339,1164771,1166402,1167318,1167383,1170379,1170459,1171297,1172916,1173402,1176550,1177487,1177531,1177859,1177864,1182189,1182205,1182214,1183132,1189613,1189932,1189982,1195575,1196113,1196129,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1209246,1212021,1212062,1212073,1212084,1213537,1213586,1213592-1213593,1213954,1214046,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227964,1229347,1230398,1231569,1231572,1231627,1231640,1233605,1234555,1235135,1235137,1235956,1236456,1239752,1240897,1240928,1243065,1243104,1244766,1245751,1245762,1293419,1295061,1295227,1298044,1298696
 /hadoop/core/branches/branch-0.19/src/docs:713112

Propchange: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar  9 03:55:45 2012
@@ -1,4 +1,4 @@
 /hadoop/common/branches/branch-0.23-PB/hadoop-common-project/hadoop-common/src/main/java:1227776-1294021
-/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java:1161777,1161781,1162008,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1164255,1164301,1164339,1164771,1166402,1167318,1167383,1170379,1170459,1171221,1171297,1172916,1173402,1176550,1176986,1177002,1177035,1177399,1177487,1177531,1177859,1177864,1178639,1179512,1182189,1182205,1182214,1182641,1183132,1189613,1189932,1189982,1190109,1190611,1195575,1195760,1196113,1196129,1197885,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204363,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1210208,1210319-1210320,1212004,1212021,1212062,1212073,1212084,1212615,1213537,1213586,1213592-1213593,1213619,1213954,1214046,1214114,1214499,1215358,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227861,1227964,1229347,1230398,1231569,1231572,123162
 7,1231640,1231732,1233605,1234555,1235135,1235137,1235956,1236444,1236456,1239752,1240897,1240928,1243065,1243104,1244185,1244766,1245751,1245762,1291602,1293071,1293419,1295061,1295227,1295240,1298044
+/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java:1161777,1161781,1162008,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1164255,1164301,1164339,1164771,1166402,1167318,1167383,1170379,1170459,1171221,1171297,1172916,1173402,1176550,1176986,1177002,1177035,1177399,1177487,1177531,1177859,1177864,1178639,1179512,1182189,1182205,1182214,1182641,1183132,1189613,1189932,1189982,1190109,1190611,1195575,1195760,1196113,1196129,1197885,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204363,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1210208,1210319-1210320,1212004,1212021,1212062,1212073,1212084,1212615,1213537,1213586,1213592-1213593,1213619,1213954,1214046,1214114,1214499,1215358,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227861,1227964,1229347,1230398,1231569,1231572,123162
 7,1231640,1231732,1233605,1234555,1235135,1235137,1235956,1236444,1236456,1239752,1240897,1240928,1243065,1243104,1244185,1244766,1245751,1245762,1291602,1293071,1293419,1295061,1295227,1295240,1298044,1298696
 /hadoop/core/branches/branch-0.19/core/src/java:713112
 /hadoop/core/trunk/src/core:776175-785643,785929-786278

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/DNS.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/DNS.java?rev=1298697&r1=1298696&r2=1298697&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/DNS.java (original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/DNS.java Fri Mar  9 03:55:45 2012
@@ -96,42 +96,51 @@ public class DNS {
    * 
    * @param strInterface
    *            The name of the network interface to query (e.g. eth0)
+   *            or the string "default"
    * @return A string vector of all the IPs associated with the provided
-   *         interface
+   *         interface. The local host IP is returned if the interface
+   *         name "default" is specified or there is an I/O error looking
+   *         for the given interface.
    * @throws UnknownHostException
-   *             If an UnknownHostException is encountered in querying the
-   *             default interface
+   *             If the given interface is invalid
    * 
    */
   public static String[] getIPs(String strInterface)
     throws UnknownHostException {
+    if ("default".equals(strInterface)) {
+      return new String[] { cachedHostAddress };
+    }
+    NetworkInterface netIF;
     try {
-      NetworkInterface netIF = NetworkInterface.getByName(strInterface);
-      if (netIF == null) {
-        return new String[] { cachedHostAddress };
-      } else {
-        Vector<String> ips = new Vector<String>();
-        Enumeration e = netIF.getInetAddresses();
-        while (e.hasMoreElements()) {
-          ips.add(((InetAddress) e.nextElement()).getHostAddress());
-        }
-        return ips.toArray(new String[] {});
-      }
+      netIF = NetworkInterface.getByName(strInterface);
     } catch (SocketException e) {
-      return new String[]  { cachedHostAddress };
+      LOG.warn("I/O error finding interface " + strInterface +
+          ": " + e.getMessage());
+      return new String[] { cachedHostAddress };
+    }
+    if (netIF == null) {
+      throw new UnknownHostException("No such interface " + strInterface);
     }
+    Vector<String> ips = new Vector<String>();
+    Enumeration<InetAddress> e = netIF.getInetAddresses();
+    while (e.hasMoreElements()) {
+      ips.add(e.nextElement().getHostAddress());
+    }
+    return ips.toArray(new String[] {});
   }
 
 
-    /**
+  /**
    * Returns the first available IP address associated with the provided
-   * network interface
+   * network interface or the local host IP if "default" is given.
    *
    * @param strInterface
    *            The name of the network interface to query (e.g. eth0)
-   * @return The IP address in text form
+   *            or the string "default"
+   * @return The IP address in text form, the local host IP is returned
+   *         if the interface name "default" is specified
    * @throws UnknownHostException
-   *             If one is encountered in querying the default interface
+   *             If the given interface is invalid
    */
   public static String getDefaultIP(String strInterface)
     throws UnknownHostException {
@@ -149,21 +158,22 @@ public class DNS {
    *            The DNS host name
    * @return A string vector of all host names associated with the IPs tied to
    *         the specified interface
-   * @throws UnknownHostException if the hostname cannot be determined
+   * @throws UnknownHostException if the given interface is invalid
    */
   public static String[] getHosts(String strInterface, String nameserver)
     throws UnknownHostException {
     String[] ips = getIPs(strInterface);
     Vector<String> hosts = new Vector<String>();
-    for (int ctr = 0; ctr < ips.length; ctr++)
+    for (int ctr = 0; ctr < ips.length; ctr++) {
       try {
         hosts.add(reverseDns(InetAddress.getByName(ips[ctr]),
                              nameserver));
       } catch (UnknownHostException ignored) {
       } catch (NamingException ignored) {
       }
-
+    }
     if (hosts.isEmpty()) {
+      LOG.warn("Unable to determine hostname for interface " + strInterface);
       return new String[] { cachedHostname };
     } else {
       return hosts.toArray(new String[hosts.size()]);
@@ -181,8 +191,8 @@ public class DNS {
     try {
       localhost = InetAddress.getLocalHost().getCanonicalHostName();
     } catch (UnknownHostException e) {
-      LOG.info("Unable to determine local hostname "
-              + "-falling back to \"" + LOCALHOST + "\"", e);
+      LOG.warn("Unable to determine local hostname "
+          + "-falling back to \"" + LOCALHOST + "\"", e);
       localhost = LOCALHOST;
     }
     return localhost;
@@ -204,7 +214,7 @@ public class DNS {
       try {
         address = InetAddress.getLocalHost().getHostAddress();
       } catch (UnknownHostException e) {
-        LOG.info("Unable to determine address of the host"
+        LOG.warn("Unable to determine address of the host"
                 + "-falling back to \"" + LOCALHOST + "\" address", e);
         try {
           address = InetAddress.getByName(LOCALHOST).getHostAddress();

Propchange: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/core/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar  9 03:55:45 2012
@@ -1,4 +1,4 @@
 /hadoop/common/branches/branch-0.23-PB/hadoop-common-project/hadoop-common/src/test/core:1227776-1294021
-/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/core:1161777,1161781,1162008,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1164255,1164301,1164339,1166009,1166402,1167383,1170379,1170459,1171297,1172916,1173402,1176550,1177487,1177531,1177859,1177864,1182189,1182205,1182214,1183132,1189613,1189932,1189982,1195575,1196113,1196129,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1212021,1212062,1212073,1212084,1213537,1213586,1213592-1213593,1213954,1214046,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227964,1229347,1230398,1231569,1231572,1231627,1231640,1233605,1234555,1235135,1235137,1235956,1236456,1239752,1240897,1240928,1243065,1243104,1244766,1245751,1245762,1293419,1295061,1295227,1298044
+/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/core:1161777,1161781,1162008,1162188,1162421,1162491,1162499,1162613,1162928,1162954,1162979,1163050,1163069,1163456,1163465,1163490,1163768,1163852,1163858,1164255,1164301,1164339,1166009,1166402,1167383,1170379,1170459,1171297,1172916,1173402,1176550,1177487,1177531,1177859,1177864,1182189,1182205,1182214,1183132,1189613,1189932,1189982,1195575,1196113,1196129,1204114,1204117,1204122,1204124,1204129,1204131,1204177,1204370,1204376,1204388,1205260,1205697,1206786,1206830,1207694,1208153,1208313,1212021,1212062,1212073,1212084,1213537,1213586,1213592-1213593,1213954,1214046,1220510,1221348,1225114,1225192,1225456,1225489,1225591,1226211,1226239,1226350,1227091,1227165,1227423,1227964,1229347,1230398,1231569,1231572,1231627,1231640,1233605,1234555,1235135,1235137,1235956,1236456,1239752,1240897,1240928,1243065,1243104,1244766,1245751,1245762,1293419,1295061,1295227,1298044,1298696
 /hadoop/core/branches/branch-0.19/core/src/test/core:713112
 /hadoop/core/trunk/src/test/core:776175-785643,785929-786278

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestDNS.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestDNS.java?rev=1298697&r1=1298696&r2=1298697&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestDNS.java (original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestDNS.java Fri Mar  9 03:55:45 2012
@@ -16,39 +16,32 @@
  * limitations under the License.
  */
 
-
 package org.apache.hadoop.net;
 
-import junit.framework.TestCase;
-
 import java.net.UnknownHostException;
 import java.net.InetAddress;
 
+import javax.naming.NameNotFoundException;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.naming.NameNotFoundException;
+import org.junit.Test;
+import static org.junit.Assert.*;
 
 /**
- *
+ * Test host name and IP resolution and caching.
  */
-public class TestDNS extends TestCase {
+public class TestDNS {
 
   private static final Log LOG = LogFactory.getLog(TestDNS.class);
   private static final String DEFAULT = "default";
 
   /**
-   * Constructs a test case with the given name.
-   *
-   * @param name test name
-   */
-  public TestDNS(String name) {
-    super(name);
-  }
-
-  /**
    * Test that asking for the default hostname works
-   * @throws Exception if hostname lookups fail   */
+   * @throws Exception if hostname lookups fail
+   */
+  @Test
   public void testGetLocalHost() throws Exception {
     String hostname = DNS.getDefaultHost(DEFAULT);
     assertNotNull(hostname);
@@ -59,26 +52,27 @@ public class TestDNS extends TestCase {
    * hence that caching is being used
    * @throws Exception if hostname lookups fail
    */
+  @Test
   public void testGetLocalHostIsFast() throws Exception {
-    String hostname = DNS.getDefaultHost(DEFAULT);
-    assertNotNull(hostname);
-    long t1 = System.currentTimeMillis();
+    String hostname1 = DNS.getDefaultHost(DEFAULT);
+    assertNotNull(hostname1);
     String hostname2 = DNS.getDefaultHost(DEFAULT);
-    long t2 = System.currentTimeMillis();
+    long t1 = System.currentTimeMillis();
     String hostname3 = DNS.getDefaultHost(DEFAULT);
-    long t3 = System.currentTimeMillis();
+    long t2 = System.currentTimeMillis();
     assertEquals(hostname3, hostname2);
-    assertEquals(hostname2, hostname);
-    long interval2 = t3 - t2;
+    assertEquals(hostname2, hostname1);
+    long interval = t2 - t1;
     assertTrue(
-            "It is taking to long to determine the local host -caching is not working",
-            interval2 < 20000);
+        "Took too long to determine local host - caching is not working",
+        interval < 20000);
   }
 
   /**
    * Test that our local IP address is not null
    * @throws Exception if something went wrong
    */
+  @Test
   public void testLocalHostHasAnAddress() throws Exception {
     assertNotNull(getLocalIPAddr());
   }
@@ -90,34 +84,54 @@ public class TestDNS extends TestCase {
   }
 
   /**
-   * Test that passing a null pointer is as the interface
-   * fails with a NullPointerException
-   * @throws Exception if something went wrong
+   * Test null interface name
    */
+  @Test
   public void testNullInterface() throws Exception {
     try {
       String host = DNS.getDefaultHost(null);
       fail("Expected a NullPointerException, got " + host);
-    } catch (NullPointerException expected) {
-      //this is expected
+    } catch (NullPointerException npe) {
+      // Expected
+    }
+    try {
+      String ip = DNS.getDefaultIP(null);
+      fail("Expected a NullPointerException, got " + ip);
+    } catch (NullPointerException npe) {
+      // Expected
     }
   }
 
   /**
-   * Get the IP addresses of an unknown interface, expect to get something
-   * back
-   * @throws Exception if something went wrong
+   * Get the IP addresses of an unknown interface
    */
+  @Test
   public void testIPsOfUnknownInterface() throws Exception {
-    String[] ips = DNS.getIPs("name-of-an-unknown-interface");
-    assertNotNull(ips);
-    assertTrue(ips.length > 0);
+    try {
+      DNS.getIPs("name-of-an-unknown-interface");
+      fail("Got an IP for a bogus interface");
+    } catch (UnknownHostException e) {
+      assertEquals("No such interface name-of-an-unknown-interface",
+          e.getMessage());
+    }
+  }
+
+  /**
+   * Test the "default" IP addresses is the local IP addr
+   */
+  @Test
+  public void testGetIPWithDefault() throws Exception {
+    String[] ips = DNS.getIPs(DEFAULT);
+    assertEquals("Should only return 1 default IP", 1, ips.length);
+    assertEquals(getLocalIPAddr().getHostAddress(), ips[0].toString());
+    String ip = DNS.getDefaultIP(DEFAULT);
+    assertEquals(ip, ips[0].toString());
   }
 
   /**
    * TestCase: get our local address and reverse look it up
-   * @throws Exception if that fails
    */
+  @Test
   public void testRDNS() throws Exception {
     InetAddress localhost = getLocalIPAddr();
     try {
@@ -140,8 +154,8 @@ public class TestDNS extends TestCase {
    * Test that the name "localhost" resolves to something.
    *
    * If this fails, your machine's network is in a mess, go edit /etc/hosts
-   * @throws Exception for any problems
    */
+  @Test
   public void testLocalhostResolves() throws Exception {
     InetAddress localhost = InetAddress.getByName("localhost");
     assertNotNull("localhost is null", localhost);