Search in sources :

Example 1 with EchoRequestProto

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

the class AbstractTestIPC method testRpcMaxRequestSize.

/** Tests that the rpc scheduler is called when requests arrive. */
@Test
public void testRpcMaxRequestSize() throws IOException, ServiceException {
    Configuration conf = new Configuration(CONF);
    conf.setInt(RpcServer.MAX_REQUEST_SIZE, 1000);
    RpcServer rpcServer = RpcServerFactory.createRpcServer(null, "testRpcServer", Lists.newArrayList(new BlockingServiceAndInterface(SERVICE, null)), new InetSocketAddress("localhost", 0), conf, new FifoRpcScheduler(conf, 1));
    try (AbstractRpcClient<?> client = createRpcClient(conf)) {
        rpcServer.start();
        BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress());
        StringBuilder message = new StringBuilder(1200);
        for (int i = 0; i < 200; i++) {
            message.append("hello.");
        }
        // set total RPC size bigger than 100 bytes
        EchoRequestProto param = EchoRequestProto.newBuilder().setMessage(message.toString()).build();
        stub.echo(new HBaseRpcControllerImpl(CellUtil.createCellScanner(ImmutableList.<Cell>of(CELL))), param);
        fail("RPC should have failed because it exceeds max request size");
    } catch (ServiceException e) {
        LOG.info("Caught expected exception: " + e);
        assertTrue(e.toString(), StringUtils.stringifyException(e).contains("RequestTooBigException"));
    } finally {
        rpcServer.stop();
    }
}
Also used : BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) EchoRequestProto(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoRequestProto) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 2 with EchoRequestProto

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

the class TestProtoBufRpc method testProtoBufRpc.

@Test(expected = org.apache.hadoop.hbase.shaded.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(echoResponse.getMessage(), "hello");
        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 3 with EchoRequestProto

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

the class AbstractTestIPC method testConnectionCloseWithOutstandingRPCs.

/** Tests that the connection closing is handled by the client with outstanding RPC calls */
@Test
public void testConnectionCloseWithOutstandingRPCs() throws InterruptedException, IOException {
    Configuration conf = new Configuration(CONF);
    RpcServer rpcServer = new TestFailingRpcServer(conf);
    try (AbstractRpcClient<?> client = createRpcClient(conf)) {
        rpcServer.start();
        BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress());
        EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
        stub.echo(null, param);
        fail("RPC should have failed because connection closed");
    } catch (ServiceException e) {
        LOG.info("Caught expected exception: " + e.toString());
    } finally {
        rpcServer.stop();
    }
}
Also used : BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) EchoRequestProto(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoRequestProto) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) Test(org.junit.Test)

Example 4 with EchoRequestProto

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

the class AbstractTestIPC method testRpcScheduler.

/**
   * Tests that the rpc scheduler is called when requests arrive.
   */
@Test
public void testRpcScheduler() throws IOException, ServiceException, InterruptedException {
    RpcScheduler scheduler = spy(new FifoRpcScheduler(CONF, 1));
    RpcServer rpcServer = RpcServerFactory.createRpcServer(null, "testRpcServer", Lists.newArrayList(new BlockingServiceAndInterface(SERVICE, null)), new InetSocketAddress("localhost", 0), CONF, scheduler);
    verify(scheduler).init((RpcScheduler.Context) anyObject());
    try (AbstractRpcClient<?> client = createRpcClient(CONF)) {
        rpcServer.start();
        verify(scheduler).start();
        BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress());
        EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
        for (int i = 0; i < 10; i++) {
            stub.echo(null, param);
        }
        verify(scheduler, times(10)).dispatch((CallRunner) anyObject());
    } finally {
        rpcServer.stop();
        verify(scheduler).stop();
    }
}
Also used : BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) EchoRequestProto(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoRequestProto) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Aggregations

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