YARN-731. RPCUtil.unwrapAndThrowException should unwrap remote RuntimeExceptions. Contributed by Zhijie Shen.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1492000 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
25946da413
commit
6d4d87008c
|
@ -312,6 +312,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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -64,6 +64,12 @@ public class TestRPCUtil {
|
|||
verifyRemoteExceptionUnwrapping(exception, exception.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteRuntimeExceptionUnwrapping() {
|
||||
Class<? extends Throwable> 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<? extends Throwable> expectedLocalException,
|
||||
String realExceptionClassName) {
|
||||
|
|
Loading…
Reference in New Issue