HADOOP-9343. Allow additional exceptions through the RPC layer. (sseth)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1452918 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Siddharth Seth 2013-03-05 17:56:17 +00:00
parent cc15fff263
commit 52703c2d0d
5 changed files with 34 additions and 3 deletions

View File

@ -363,6 +363,8 @@ Release 2.0.4-beta - UNRELEASED
HADOOP-9334. Upgrade netty version. (Nicolas Liochon via suresh) HADOOP-9334. Upgrade netty version. (Nicolas Liochon via suresh)
HADOOP-9343. Allow additional exceptions through the RPC layer. (sseth)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -24,6 +24,7 @@
import java.io.DataOutput; import java.io.DataOutput;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.BindException; import java.net.BindException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -1788,6 +1789,9 @@ public Writable run() throws Exception {
); );
} }
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof UndeclaredThrowableException) {
e = e.getCause();
}
String logMsg = getName() + ", call " + call + ": error: " + e; String logMsg = getName() + ", call " + call + ": error: " + e;
if (e instanceof RuntimeException || e instanceof Error) { if (e instanceof RuntimeException || e instanceof Error) {
// These exception types indicate something is probably wrong // These exception types indicate something is probably wrong

View File

@ -1501,7 +1501,7 @@ public <T> T doAs(PrivilegedExceptionAction<T> action
} else if (cause instanceof InterruptedException) { } else if (cause instanceof InterruptedException) {
throw (InterruptedException) cause; throw (InterruptedException) cause;
} else { } else {
throw new UndeclaredThrowableException(pae,"Unknown exception in doAs"); throw new UndeclaredThrowableException(cause);
} }
} }
} }

View File

@ -22,6 +22,7 @@
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URISyntaxException;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.protobuf.TestProtos.EchoRequestProto; import org.apache.hadoop.ipc.protobuf.TestProtos.EchoRequestProto;
@ -83,6 +84,13 @@ public EmptyResponseProto error(RpcController unused,
EmptyRequestProto request) throws ServiceException { EmptyRequestProto request) throws ServiceException {
throw new ServiceException("error", new RpcServerException("error")); throw new ServiceException("error", new RpcServerException("error"));
} }
@Override
public EmptyResponseProto error2(RpcController unused,
EmptyRequestProto request) throws ServiceException {
throw new ServiceException("error", new URISyntaxException("",
"testException"));
}
} }
public static class PBServer2Impl implements TestRpcService2 { public static class PBServer2Impl implements TestRpcService2 {
@ -149,7 +157,7 @@ private static TestRpcService2 getClient2() throws IOException {
conf); conf);
} }
@Test @Test (timeout=5000)
public void testProtoBufRpc() throws Exception { public void testProtoBufRpc() throws Exception {
TestRpcService client = getClient(); TestRpcService client = getClient();
testProtoBufRpc(client); testProtoBufRpc(client);
@ -178,7 +186,7 @@ public static void testProtoBufRpc(TestRpcService client) throws Exception {
} }
} }
@Test @Test (timeout=5000)
public void testProtoBufRpc2() throws Exception { public void testProtoBufRpc2() throws Exception {
TestRpcService2 client = getClient2(); TestRpcService2 client = getClient2();
@ -201,4 +209,20 @@ public void testProtoBufRpc2() throws Exception {
getMetrics(server.getRpcDetailedMetrics().name()); getMetrics(server.getRpcDetailedMetrics().name());
assertCounterGt("Echo2NumOps", 0L, rpcDetailedMetrics); assertCounterGt("Echo2NumOps", 0L, rpcDetailedMetrics);
} }
@Test (timeout=5000)
public void testProtoBufRandomException() throws Exception {
TestRpcService client = getClient();
EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build();
try {
client.error2(null, emptyRequest);
} catch (ServiceException se) {
Assert.assertTrue(se.getCause() instanceof RemoteException);
RemoteException re = (RemoteException) se.getCause();
Assert.assertTrue(re.getClassName().equals(
URISyntaxException.class.getName()));
Assert.assertTrue(re.getMessage().contains("testException"));
}
}
} }

View File

@ -31,6 +31,7 @@ service TestProtobufRpcProto {
rpc ping(EmptyRequestProto) returns (EmptyResponseProto); rpc ping(EmptyRequestProto) returns (EmptyResponseProto);
rpc echo(EchoRequestProto) returns (EchoResponseProto); rpc echo(EchoRequestProto) returns (EchoResponseProto);
rpc error(EmptyRequestProto) returns (EmptyResponseProto); rpc error(EmptyRequestProto) returns (EmptyResponseProto);
rpc error2(EmptyRequestProto) returns (EmptyResponseProto);
} }
service TestProtobufRpc2Proto { service TestProtobufRpc2Proto {