HDFS-13834. RBF: Connection creator thread should catch Throwable. Contributed 
by CR Hota.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/4d8cc85c
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/4d8cc85c
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/4d8cc85c

Branch: refs/heads/HDFS-13891
Commit: 4d8cc85c2c13aecdb517a07aac9da038a064ecf6
Parents: 6291f11
Author: Inigo Goiri <inigo...@apache.org>
Authored: Wed Nov 14 18:35:12 2018 +0530
Committer: Brahma Reddy Battula <bra...@apache.org>
Committed: Wed Nov 14 18:35:12 2018 +0530

----------------------------------------------------------------------
 .../federation/router/ConnectionManager.java    |  4 +-
 .../router/TestConnectionManager.java           | 43 ++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/4d8cc85c/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionManager.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionManager.java
 
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionManager.java
index 9fb83e4..fa2bf94 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionManager.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionManager.java
@@ -393,7 +393,7 @@ public class ConnectionManager {
   /**
    * Thread that creates connections asynchronously.
    */
-  private static class ConnectionCreator extends Thread {
+  static class ConnectionCreator extends Thread {
     /** If the creator is running. */
     private boolean running = true;
     /** Queue to push work to. */
@@ -426,6 +426,8 @@ public class ConnectionManager {
         } catch (InterruptedException e) {
           LOG.error("The connection creator was interrupted");
           this.running = false;
+        } catch (Throwable e) {
+          LOG.error("Fatal error caught by connection creator ", e);
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/4d8cc85c/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestConnectionManager.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestConnectionManager.java
 
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestConnectionManager.java
index 0e1eb40..765f6c8 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestConnectionManager.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestConnectionManager.java
@@ -22,12 +22,17 @@ import org.apache.hadoop.hdfs.protocol.ClientProtocol;
 import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol;
 import org.apache.hadoop.net.NetUtils;
 import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.test.GenericTestUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.Rule;
+import org.junit.rules.ExpectedException;
 
 import java.io.IOException;
 import java.util.Map;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -49,6 +54,7 @@ public class TestConnectionManager {
   private static final UserGroupInformation TEST_USER3 =
       UserGroupInformation.createUserForTesting("user3", TEST_GROUP);
   private static final String TEST_NN_ADDRESS = "nn1:8080";
+  private static final String UNRESOLVED_TEST_NN_ADDRESS = "unknownhost:8080";
 
   @Before
   public void setup() throws Exception {
@@ -59,6 +65,9 @@ public class TestConnectionManager {
     connManager.start();
   }
 
+  @Rule
+  public ExpectedException exceptionRule = ExpectedException.none();
+
   @After
   public void shutdown() {
     if (connManager != null) {
@@ -122,6 +131,40 @@ public class TestConnectionManager {
   }
 
   @Test
+  public void testConnectionCreatorWithException() throws Exception {
+    // Create a bad connection pool pointing to unresolvable namenode address.
+    ConnectionPool badPool = new ConnectionPool(
+            conf, UNRESOLVED_TEST_NN_ADDRESS, TEST_USER1, 0, 10,
+            ClientProtocol.class);
+    BlockingQueue<ConnectionPool> queue = new ArrayBlockingQueue<>(1);
+    queue.add(badPool);
+    ConnectionManager.ConnectionCreator connectionCreator =
+        new ConnectionManager.ConnectionCreator(queue);
+    connectionCreator.setDaemon(true);
+    connectionCreator.start();
+    // Wait to make sure async thread is scheduled and picks
+    GenericTestUtils.waitFor(()->queue.isEmpty(), 50, 5000);
+    // At this point connection creation task should be definitely picked up.
+    assertTrue(queue.isEmpty());
+    // At this point connection thread should still be alive.
+    assertTrue(connectionCreator.isAlive());
+    // Stop the thread as test is successful at this point
+    connectionCreator.interrupt();
+  }
+
+  @Test
+  public void testGetConnectionWithException() throws Exception {
+    String exceptionCause = "java.net.UnknownHostException: unknownhost";
+    exceptionRule.expect(IllegalArgumentException.class);
+    exceptionRule.expectMessage(exceptionCause);
+
+    // Create a bad connection pool pointing to unresolvable namenode address.
+    ConnectionPool badPool = new ConnectionPool(
+        conf, UNRESOLVED_TEST_NN_ADDRESS, TEST_USER1, 1, 10,
+        ClientProtocol.class);
+  }
+
+  @Test
   public void testGetConnection() throws Exception {
     Map<ConnectionPoolId, ConnectionPool> poolMap = connManager.getPools();
     final int totalConns = 10;


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to