hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomwh...@apache.org
Subject svn commit: r939018 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/ipc/Client.java src/test/core/org/apache/hadoop/ipc/TestIPC.java
Date Wed, 28 Apr 2010 17:34:55 GMT
Author: tomwhite
Date: Wed Apr 28 17:34:55 2010
New Revision: 939018

URL: http://svn.apache.org/viewvc?rev=939018&view=rev
Log:
HADOOP-6724. IPC doesn't properly handle IOEs thrown by socket factory. Contributed by Todd
Lipcon.

Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/ipc/Client.java
    hadoop/common/trunk/src/test/core/org/apache/hadoop/ipc/TestIPC.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=939018&r1=939017&r2=939018&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Wed Apr 28 17:34:55 2010
@@ -373,6 +373,9 @@ Trunk (unreleased changes)
     HADOOP-6719. Insert all missing methods in FilterFs.
     (Rodrigo Schmidt via dhruba)
 
+    HADOOP-6724. IPC doesn't properly handle IOEs thrown by socket factory.
+    (Todd Lipcon via tomwhite)
+
 Release 0.21.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/ipc/Client.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/ipc/Client.java?rev=939018&r1=939017&r2=939018&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/ipc/Client.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/ipc/Client.java Wed Apr 28 17:34:55 2010
@@ -494,10 +494,12 @@ public class Client {
     private void handleConnectionFailure(
         int curRetries, int maxRetries, IOException ioe) throws IOException {
       // close the current connection
-      try {
-        socket.close();
-      } catch (IOException e) {
-        LOG.warn("Not able to close a socket", e);
+      if (socket != null) {
+        try {
+          socket.close();
+        } catch (IOException e) {
+          LOG.warn("Not able to close a socket", e);
+        }
       }
       // set socket to null so that the next call to setupIOstreams
       // can start the process of connect all over again.

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/ipc/TestIPC.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/ipc/TestIPC.java?rev=939018&r1=939017&r2=939018&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/ipc/TestIPC.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/ipc/TestIPC.java Wed Apr 28 17:34:55
2010
@@ -29,8 +29,10 @@ import java.util.Random;
 import java.io.DataInput;
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import javax.net.SocketFactory;
 
 import junit.framework.TestCase;
+import static org.mockito.Mockito.*;
 
 import org.apache.hadoop.conf.Configuration;
 
@@ -267,6 +269,25 @@ public class TestIPC extends TestCase {
     }
   }
 
+  /**
+   * Test that, if the socket factory throws an IOE, it properly propagates
+   * to the client.
+   */
+  public void testSocketFactoryException() throws Exception {
+    SocketFactory mockFactory = mock(SocketFactory.class);
+    doThrow(new IOException("Injected fault")).when(mockFactory).createSocket();
+    Client client = new Client(LongWritable.class, conf, mockFactory);
+    
+    InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10);
+    try {
+      client.call(new LongWritable(RANDOM.nextLong()),
+              address, null, null);
+      fail("Expected an exception to have been thrown");
+    } catch (IOException e) {
+      assertTrue(e.getMessage().contains("Injected fault"));
+    }
+  }
+
 
   public static void main(String[] args) throws Exception {
 



Mime
View raw message