public static void testProtoBufRpc(TestRpcService client) throws Exception { // Test ping method EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build(); client.ping(null, emptyRequest); // 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, emptyRequest); Assert.fail("Expected exception is not thrown"); } catch (ServiceException e) { } }
@Test public void testProtoBufRpc() throws Exception { RpcClient rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT); try { BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel( ServerName.valueOf(this.isa.getHostName(), this.isa.getPort(), System.currentTimeMillis()), User.getCurrent(), 0); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface stub = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(channel); // Test ping method TestProtos.EmptyRequestProto emptyRequest = TestProtos.EmptyRequestProto.newBuilder().build(); stub.ping(null, emptyRequest); // Test echo method EchoRequestProto echoRequest = EchoRequestProto.newBuilder().setMessage("hello").build(); EchoResponseProto echoResponse = stub.echo(null, echoRequest); Assert.assertEquals(echoResponse.getMessage(), "hello"); // Test error method - error should be thrown as RemoteException try { stub.error(null, emptyRequest); Assert.fail("Expected exception is not thrown"); } catch (ServiceException e) { } } finally { rpcClient.close(); } }
@Test public void testProtoBufRpc() throws Exception { RpcClient rpcClient = new RpcClient(conf, HConstants.CLUSTER_ID_DEFAULT); try { BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel( ServerName.valueOf(this.isa.getHostName(), this.isa.getPort(), System.currentTimeMillis()), User.getCurrent(), 0); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface stub = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(channel); // Test ping method TestProtos.EmptyRequestProto emptyRequest = TestProtos.EmptyRequestProto.newBuilder().build(); stub.ping(null, emptyRequest); // Test echo method EchoRequestProto echoRequest = EchoRequestProto.newBuilder().setMessage("hello").build(); EchoResponseProto echoResponse = stub.echo(null, echoRequest); Assert.assertEquals(echoResponse.getMessage(), "hello"); // Test error method - error should be thrown as RemoteException try { stub.error(null, emptyRequest); Assert.fail("Expected exception is not thrown"); } catch (ServiceException e) { } } finally { rpcClient.stop(); } }
@Override public EmptyResponseProto ping(RpcController controller, EmptyRequestProto request) throws ServiceException { return null; }
@Override public EmptyResponseProto error(RpcController controller, EmptyRequestProto request) throws ServiceException { return null; }
@Override public EmptyResponseProto ping(RpcController unused, EmptyRequestProto request) throws ServiceException { return EmptyResponseProto.newBuilder().build(); }
@Override public EmptyResponseProto error(RpcController unused, EmptyRequestProto request) throws ServiceException { throw new ServiceException("error", new IOException("error")); }
@Override public EmptyResponseProto ping(RpcController controller, EmptyRequestProto request) throws ServiceException { // TODO Auto-generated method stub return null; }
@Override public EmptyResponseProto error(RpcController controller, EmptyRequestProto request) throws ServiceException { // TODO Auto-generated method stub return null; }
@Override public void ping(RpcController controller, TestProtos.EmptyRequestProto request, RpcCallback<TestProtos.EmptyResponseProto> done) { done.run(TestProtos.EmptyResponseProto.getDefaultInstance()); }
@Override public void error(RpcController controller, TestProtos.EmptyRequestProto request, RpcCallback<TestProtos.EmptyResponseProto> done) { CoprocessorRpcUtils.setControllerException(controller, new IOException("Test exception")); done.run(null); }
@Override public void addr(RpcController controller, EmptyRequestProto request, RpcCallback<AddrResponseProto> done) { done.run(AddrResponseProto.newBuilder() .setAddr(RpcServer.getRemoteAddress().get().getHostAddress()).build()); }