@Test public void testCoprocessorError() throws Exception { Configuration configuration = new Configuration(util.getConfiguration()); // Make it not retry forever configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); Table table = new HTable(configuration, TEST_TABLE); try { CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol); service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance()); fail("Should have thrown an exception"); } catch (ServiceException e) { } finally { table.close(); } }
@Test public void testCoprocessorError() throws Exception { Configuration configuration = new Configuration(util.getConfiguration()); // Make it not retry forever configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); HTable table = new HTable(configuration, TEST_TABLE); try { CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol); service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance()); fail("Should have thrown an exception"); } catch (ServiceException e) { } finally { table.close(); } }
@Test public void testCoprocessorError() throws Exception { Configuration configuration = new Configuration(util.getConfiguration()); // Make it not retry forever configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); Table table = util.getConnection().getTable(TEST_TABLE); try { CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol); service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance()); fail("Should have thrown an exception"); } catch (ServiceException e) { } finally { table.close(); } }
@Override public TestProtos.EchoResponseProto echo(RpcController controller, TestProtos.EchoRequestProto request) throws ServiceException { if (controller instanceof PayloadCarryingRpcController) { PayloadCarryingRpcController pcrc = (PayloadCarryingRpcController) controller; // If cells, scan them to check we are able to iterate what we were given and since // this is // an echo, just put them back on the controller creating a new block. Tests our // block // building. CellScanner cellScanner = pcrc.cellScanner(); List<Cell> list = null; if (cellScanner != null) { list = new ArrayList<Cell>(); try { while (cellScanner.advance()) { list.add(cellScanner.current()); } } catch (IOException e) { throw new ServiceException(e); } } cellScanner = CellUtil.createCellScanner(list); ((PayloadCarryingRpcController) controller).setCellScanner(cellScanner); } return TestProtos.EchoResponseProto.newBuilder() .setMessage(request.getMessage()).build(); }
@Override public void run() { String result; try { result = stub.echo(null, TestProtos.EchoRequestProto.newBuilder().setMessage(String.valueOf( ThreadLocalRandom.current().nextInt())).build()).getMessage(); } catch (ServiceException e) { throw new RuntimeException(e); } if (results != null) { synchronized (results) { results.add(result); } } }
@Test public void testMasterCoprocessorService() throws Throwable { Admin admin = util.getHBaseAdmin(); final TestProtos.EchoRequestProto request = TestProtos.EchoRequestProto.newBuilder().setMessage("hello").build(); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(admin.coprocessorService()); assertEquals("hello", service.echo(null, request).getMessage()); }
@Test public void testMasterCoprocessorError() throws Throwable { Admin admin = util.getHBaseAdmin(); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(admin.coprocessorService()); try { service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance()); fail("Should have thrown an exception"); } 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 testMasterCoprocessorService() throws Throwable { HBaseAdmin admin = util.getHBaseAdmin(); final TestProtos.EchoRequestProto request = TestProtos.EchoRequestProto.newBuilder().setMessage("hello").build(); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(admin.coprocessorService()); assertEquals("hello", service.echo(null, request).getMessage()); }
@Test public void testMasterCoprocessorError() throws Throwable { HBaseAdmin admin = util.getHBaseAdmin(); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(admin.coprocessorService()); try { service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance()); fail("Should have thrown an exception"); } catch (ServiceException e) { } }
@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(); } }
@Test public void testMasterCoprocessorService() throws Throwable { Admin admin = util.getAdmin(); final TestProtos.EchoRequestProto request = TestProtos.EchoRequestProto.newBuilder().setMessage("hello").build(); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(admin.coprocessorService()); assertEquals("hello", service.echo(null, request).getMessage()); }
@Test public void testMasterCoprocessorError() throws Throwable { Admin admin = util.getAdmin(); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(admin.coprocessorService()); try { service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance()); fail("Should have thrown an exception"); } catch (ServiceException e) { } }
@Test public void testMasterCoprocessorService() throws Exception { TestProtos.EchoRequestProto request = TestProtos.EchoRequestProto.newBuilder().setMessage("hello").build(); TestProtos.EchoResponseProto response = admin .<TestRpcServiceProtos.TestProtobufRpcProto.Stub, TestProtos.EchoResponseProto> coprocessorService( TestRpcServiceProtos.TestProtobufRpcProto::newStub, (s, c, done) -> s.echo(c, request, done)).get(); assertEquals("hello", response.getMessage()); }
@Test public void testMasterCoprocessorError() throws Exception { TestProtos.EmptyRequestProto emptyRequest = TestProtos.EmptyRequestProto.getDefaultInstance(); try { admin .<TestRpcServiceProtos.TestProtobufRpcProto.Stub, TestProtos.EmptyResponseProto> coprocessorService( TestRpcServiceProtos.TestProtobufRpcProto::newStub, (s, c, done) -> s.error(c, emptyRequest, done)).get(); fail("Should have thrown an exception"); } catch (Exception e) { } }
@Test public void testMasterCoprocessorService() throws Throwable { HBaseAdmin admin = util.getHBaseAdmin(); final TestProtos.EchoRequestProto request = TestProtos.EchoRequestProto.newBuilder().setMessage("hello").build(); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(admin.coprocessorService()); assertEquals("hello", service.echo(null, request).getMessage()); admin.close(); }
@Override public TestProtos.EmptyResponseProto ping(RpcController controller, TestProtos.EmptyRequestProto request) throws ServiceException { return null; }
@Override public TestProtos.EmptyResponseProto error(RpcController controller, TestProtos.EmptyRequestProto request) throws ServiceException { return null; }
@Override public void ping(RpcController controller, TestProtos.EmptyRequestProto request, RpcCallback<TestProtos.EmptyResponseProto> done) { done.run(TestProtos.EmptyResponseProto.getDefaultInstance()); }
@Override public void echo(RpcController controller, TestProtos.EchoRequestProto request, RpcCallback<TestProtos.EchoResponseProto> done) { String message = request.getMessage(); done.run(TestProtos.EchoResponseProto.newBuilder().setMessage(message).build()); }
@Override public void error(RpcController controller, TestProtos.EmptyRequestProto request, RpcCallback<TestProtos.EmptyResponseProto> done) { ResponseConverter.setControllerException(controller, new IOException("Test exception")); done.run(null); }