use of org.apache.hadoop.ipc.protobuf.TestProtos.EchoRequestProto in project hadoop by apache.
the class RPCCallBenchmark method createRpcClient.
/**
* Create a client proxy for the specified engine.
*/
private RpcServiceWrapper createRpcClient(MyOptions opts) throws IOException {
InetSocketAddress addr = NetUtils.createSocketAddr(opts.host, opts.getPort());
if (opts.rpcEngine == ProtobufRpcEngine.class) {
final TestRpcService proxy = RPC.getProxy(TestRpcService.class, 0, addr, conf);
return new RpcServiceWrapper() {
@Override
public String doEcho(String msg) throws Exception {
EchoRequestProto req = EchoRequestProto.newBuilder().setMessage(msg).build();
EchoResponseProto responseProto = proxy.echo(null, req);
return responseProto.getMessage();
}
};
} else {
throw new RuntimeException("unsupported engine: " + opts.rpcEngine);
}
}
use of org.apache.hadoop.ipc.protobuf.TestProtos.EchoRequestProto in project hadoop by apache.
the class TestProtoBufRpc method testProtoBufRpc.
// separated test out so that other tests can call it.
public static void testProtoBufRpc(TestRpcService client) throws Exception {
// Test ping method
client.ping(null, newEmptyRequest());
// Test echo method
EchoRequestProto echoRequest = EchoRequestProto.newBuilder().setMessage("hello").build();
EchoResponseProto echoResponse = client.echo(null, echoRequest);
Assert.assertEquals(echoResponse.getMessage(), "hello");
// Test error method - error should be thrown as RemoteException
try {
client.error(null, newEmptyRequest());
Assert.fail("Expected exception is not thrown");
} catch (ServiceException e) {
RemoteException re = (RemoteException) e.getCause();
RpcServerException rse = (RpcServerException) re.unwrapRemoteException(RpcServerException.class);
Assert.assertNotNull(rse);
Assert.assertTrue(re.getErrorCode().equals(RpcErrorCodeProto.ERROR_RPC_SERVER));
}
}
Aggregations