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 2010/10/26 19:28:55 UTC

svn commit: r1027662 - in /hadoop/common/branches/branch-0.20: CHANGES.txt src/core/org/apache/hadoop/ipc/Client.java src/test/org/apache/hadoop/ipc/TestIPC.java

Author: eli
Date: Tue Oct 26 17:28:55 2010
New Revision: 1027662

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

Modified:
    hadoop/common/branches/branch-0.20/CHANGES.txt
    hadoop/common/branches/branch-0.20/src/core/org/apache/hadoop/ipc/Client.java
    hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/ipc/TestIPC.java

Modified: hadoop/common/branches/branch-0.20/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/CHANGES.txt?rev=1027662&r1=1027661&r2=1027662&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.20/CHANGES.txt Tue Oct 26 17:28:55 2010
@@ -59,6 +59,9 @@ Release 0.20.3 - Unreleased
     HDFS-1404. TestNodeCount logic incorrect in branch-0.20.
     (Todd Lipcon via Eli Collins)
 
+    HADOOP-6724. IPC doesn't properly handle IOEs thrown by socket factory.
+    (Todd Lipcon via Eli Collins)
+
   IMPROVEMENTS
 
     MAPREDUCE-1407. Update javadoc in mapreduce.{Mapper,Reducer} to match

Modified: hadoop/common/branches/branch-0.20/src/core/org/apache/hadoop/ipc/Client.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/src/core/org/apache/hadoop/ipc/Client.java?rev=1027662&r1=1027661&r2=1027662&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20/src/core/org/apache/hadoop/ipc/Client.java (original)
+++ hadoop/common/branches/branch-0.20/src/core/org/apache/hadoop/ipc/Client.java Tue Oct 26 17:28:55 2010
@@ -347,10 +347,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/branches/branch-0.20/src/test/org/apache/hadoop/ipc/TestIPC.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/ipc/TestIPC.java?rev=1027662&r1=1027661&r2=1027662&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/ipc/TestIPC.java (original)
+++ hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/ipc/TestIPC.java Tue Oct 26 17:28: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;
 
@@ -268,6 +270,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 {
 
     //new TestIPC("test").testSerial(5, false, 2, 10, 1000);