Search in sources :

Example 1 with EchoResponseProto

use of org.apache.hadoop.ipc.protobuf.TestProtos.EchoResponseProto 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);
    }
}
Also used : EchoRequestProto(org.apache.hadoop.ipc.protobuf.TestProtos.EchoRequestProto) InetSocketAddress(java.net.InetSocketAddress) EchoResponseProto(org.apache.hadoop.ipc.protobuf.TestProtos.EchoResponseProto)

Example 2 with EchoResponseProto

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

the class TestProtoBufRpc method testProtoBufRpc2.

@Test(timeout = 5000)
public void testProtoBufRpc2() throws Exception {
    TestRpcService2 client = getClient2();
    // Test ping method
    client.ping2(null, newEmptyRequest());
    // Test echo method
    EchoResponseProto echoResponse = client.echo2(null, newEchoRequest("hello"));
    Assert.assertEquals(echoResponse.getMessage(), "hello");
    // Ensure RPC metrics are updated
    MetricsRecordBuilder rpcMetrics = getMetrics(server.getRpcMetrics().name());
    assertCounterGt("RpcQueueTimeNumOps", 0L, rpcMetrics);
    assertCounterGt("RpcProcessingTimeNumOps", 0L, rpcMetrics);
    MetricsRecordBuilder rpcDetailedMetrics = getMetrics(server.getRpcDetailedMetrics().name());
    assertCounterGt("Echo2NumOps", 0L, rpcDetailedMetrics);
}
Also used : EchoResponseProto(org.apache.hadoop.ipc.protobuf.TestProtos.EchoResponseProto) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Example 3 with EchoResponseProto

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

the class TestProtoBufRpc method testExtraLongRpc.

@Test(timeout = 6000)
public void testExtraLongRpc() throws Exception {
    TestRpcService2 client = getClient2();
    final String shortString = StringUtils.repeat("X", 4);
    // short message goes through
    EchoResponseProto echoResponse = client.echo2(null, newEchoRequest(shortString));
    Assert.assertEquals(shortString, echoResponse.getMessage());
    final String longString = StringUtils.repeat("X", 4096);
    try {
        client.echo2(null, newEchoRequest(longString));
        Assert.fail("expected extra-long RPC to fail");
    } catch (ServiceException se) {
    // expected
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) EchoResponseProto(org.apache.hadoop.ipc.protobuf.TestProtos.EchoResponseProto) Test(org.junit.Test)

Example 4 with EchoResponseProto

use of org.apache.hadoop.ipc.protobuf.TestProtos.EchoResponseProto 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));
    }
}
Also used : EchoRequestProto(org.apache.hadoop.ipc.protobuf.TestProtos.EchoRequestProto) ServiceException(com.google.protobuf.ServiceException) EchoResponseProto(org.apache.hadoop.ipc.protobuf.TestProtos.EchoResponseProto)

Aggregations

EchoResponseProto (org.apache.hadoop.ipc.protobuf.TestProtos.EchoResponseProto)4 ServiceException (com.google.protobuf.ServiceException)2 EchoRequestProto (org.apache.hadoop.ipc.protobuf.TestProtos.EchoRequestProto)2 Test (org.junit.Test)2 InetSocketAddress (java.net.InetSocketAddress)1 MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)1