From ed2576ac0d0639f780dd5d4af4f2f0fe6bd6ec39 Mon Sep 17 00:00:00 2001 From: Siddharth Seth Date: Tue, 11 Jun 2013 22:35:22 +0000 Subject: [PATCH] merge TEZ-731 from trunk. RPCUtil.unwrapAndThrowException should unwrap remote RuntimeExceptions. Contributed by Zhijie Shen. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1492001 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 3 +++ .../org/apache/hadoop/yarn/ipc/RPCUtil.java | 6 +++++ .../apache/hadoop/yarn/ipc/TestRPCUtil.java | 23 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index c470c5d8658..5ab3753069f 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -292,6 +292,9 @@ Release 2.1.0-beta - UNRELEASED YARN-737. Throw some specific exceptions directly instead of wrapping them in YarnException. (Jian He via sseth) + YARN-731. RPCUtil.unwrapAndThrowException should unwrap remote + RuntimeExceptions. (Zhijie Shen via sseth) + OPTIMIZATIONS YARN-512. Log aggregation root directory check is more expensive than it diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/ipc/RPCUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/ipc/RPCUtil.java index 35d2acbc516..a2fefedee2b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/ipc/RPCUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/ipc/RPCUtil.java @@ -101,6 +101,9 @@ public class RPCUtil { } else if (IOException.class.isAssignableFrom(realClass)) { throw instantiateException(realClass.asSubclass(IOException.class), re); + } else if (RuntimeException.class.isAssignableFrom(realClass)) { + throw instantiateException( + realClass.asSubclass(RuntimeException.class), re); } else { throw re; } @@ -110,6 +113,9 @@ public class RPCUtil { } else if (cause instanceof IOException) { // RPC Client exception. throw (IOException) cause; + } else if (cause instanceof RuntimeException) { + // RPC RuntimeException + throw (RuntimeException) cause; } else { // Should not be generated. throw new IOException(se); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/ipc/TestRPCUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/ipc/TestRPCUtil.java index 3131c7b5cdf..36ca968814a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/ipc/TestRPCUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/ipc/TestRPCUtil.java @@ -64,6 +64,12 @@ public class TestRPCUtil { verifyRemoteExceptionUnwrapping(exception, exception.getName()); } + @Test + public void testRemoteRuntimeExceptionUnwrapping() { + Class exception = NullPointerException.class; + verifyRemoteExceptionUnwrapping(exception, exception.getName()); + } + @Test public void testUnexpectedRemoteExceptionUnwrapping() { // Non IOException, YarnException thrown by the remote side. @@ -110,6 +116,23 @@ public class TestRPCUtil { Assert.assertTrue(t.getMessage().contains(message)); } + @Test + public void testRPCRuntimeExceptionUnwrapping() { + String message = "RPCRuntimeExceptionUnwrapping"; + RuntimeException re = new NullPointerException(message); + ServiceException se = new ServiceException(re); + + Throwable t = null; + try { + RPCUtil.unwrapAndThrowException(se); + } catch (Throwable thrown) { + t = thrown; + } + + Assert.assertTrue(NullPointerException.class.isInstance(t)); + Assert.assertTrue(t.getMessage().contains(message)); + } + private void verifyRemoteExceptionUnwrapping( Class expectedLocalException, String realExceptionClassName) {