Search in sources :

Example 1 with EchoResponseProto

use of org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoResponseProto in project hbase by apache.

the class TestProtoBufRpc method testProtoBufRpc.

@Test(expected = org.apache.hbase.thirdparty.com.google.protobuf.ServiceException.class)
public void testProtoBufRpc() throws Exception {
    RpcClient rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT);
    try {
        BlockingInterface stub = newBlockingStub(rpcClient, this.isa);
        // 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);
        assertEquals("hello", echoResponse.getMessage());
        stub.error(null, emptyRequest);
        fail("Expected exception is not thrown");
    } finally {
        rpcClient.close();
    }
}
Also used : BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) EchoRequestProto(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoRequestProto) EchoResponseProto(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoResponseProto) TestProtos(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos) Test(org.junit.Test)

Example 2 with EchoResponseProto

use of org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoResponseProto in project hbase by apache.

the class AbstractTestIPC method testAsyncEcho.

@Test
public void testAsyncEcho() throws IOException {
    Configuration conf = HBaseConfiguration.create();
    RpcServer rpcServer = createRpcServer(null, "testRpcServer", Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(SERVICE, null)), new InetSocketAddress("localhost", 0), CONF, new FifoRpcScheduler(CONF, 1));
    try (AbstractRpcClient<?> client = createRpcClient(conf)) {
        rpcServer.start();
        Interface stub = newStub(client, rpcServer.getListenerAddress());
        int num = 10;
        List<HBaseRpcController> pcrcList = new ArrayList<>();
        List<BlockingRpcCallback<EchoResponseProto>> callbackList = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            HBaseRpcController pcrc = new HBaseRpcControllerImpl();
            BlockingRpcCallback<EchoResponseProto> done = new BlockingRpcCallback<>();
            stub.echo(pcrc, EchoRequestProto.newBuilder().setMessage("hello-" + i).build(), done);
            pcrcList.add(pcrc);
            callbackList.add(done);
        }
        for (int i = 0; i < num; i++) {
            HBaseRpcController pcrc = pcrcList.get(i);
            assertFalse(pcrc.failed());
            assertNull(pcrc.cellScanner());
            assertEquals("hello-" + i, callbackList.get(i).get().getMessage());
        }
    } finally {
        rpcServer.stop();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) EchoResponseProto(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoResponseProto) BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) Interface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.Interface) BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) Test(org.junit.Test)

Aggregations

EchoResponseProto (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoResponseProto)2 BlockingInterface (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface)2 Test (org.junit.Test)2 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 BlockingServiceAndInterface (org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface)1 TestProtos (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos)1 EchoRequestProto (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoRequestProto)1 Interface (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.Interface)1