File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
hadoop-common-project/hadoop-common/src
main/java/org/apache/hadoop/net
test/java/org/apache/hadoop/net Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 3737import java .net .UnknownHostException ;
3838import java .net .ConnectException ;
3939import java .nio .channels .SocketChannel ;
40+ import java .nio .channels .UnresolvedAddressException ;
4041import java .util .Map .Entry ;
4142import java .util .regex .Pattern ;
4243import java .util .*;
@@ -534,6 +535,8 @@ public static void connect(Socket socket,
534535 }
535536 } catch (SocketTimeoutException ste ) {
536537 throw new ConnectTimeoutException (ste .getMessage ());
538+ } catch (UnresolvedAddressException uae ) {
539+ throw new UnknownHostException (uae .getMessage ());
537540 }
538541
539542 // There is a very rare case allowed by the TCP specification, such that
Original file line number Diff line number Diff line change @@ -95,7 +95,25 @@ public void testAvoidLoopbackTcpSockets() throws Throwable {
9595 assertInException (se , "Invalid argument" );
9696 }
9797 }
98-
98+
99+ @ Test
100+ public void testInvalidAddress () throws Throwable {
101+ Configuration conf = new Configuration ();
102+
103+ Socket socket = NetUtils .getDefaultSocketFactory (conf )
104+ .createSocket ();
105+ socket .bind (new InetSocketAddress ("127.0.0.1" , 0 ));
106+ try {
107+ NetUtils .connect (socket ,
108+ new InetSocketAddress ("invalid-test-host" ,
109+ 0 ), 20000 );
110+ socket .close ();
111+ fail ("Should not have connected" );
112+ } catch (UnknownHostException uhe ) {
113+ LOG .info ("Got exception: " , uhe );
114+ }
115+ }
116+
99117 @ Test
100118 public void testSocketReadTimeoutWithChannel () throws Exception {
101119 doSocketReadTimeoutTest (true );
You can’t perform that action at this time.
0 commit comments