Search in sources :

Example 6 with Call

use of org.apache.hadoop.ipc.Server.Call in project hadoop by apache.

the class TestIPC method testCallIdAndRetry.

/**
   * Test if
   * (1) the rpc server uses the call id/retry provided by the rpc client, and
   * (2) the rpc client receives the same call id/retry from the rpc server.
   */
@Test(timeout = 60000)
public void testCallIdAndRetry() throws IOException {
    final CallInfo info = new CallInfo();
    // Override client to store the call info and check response
    final Client client = new Client(LongWritable.class, conf) {

        @Override
        Call createCall(RpcKind rpcKind, Writable rpcRequest) {
            final Call call = super.createCall(rpcKind, rpcRequest);
            info.id = call.id;
            info.retry = call.retry;
            return call;
        }

        @Override
        void checkResponse(RpcResponseHeaderProto header) throws IOException {
            super.checkResponse(header);
            Assert.assertEquals(info.id, header.getCallId());
            Assert.assertEquals(info.retry, header.getRetryCount());
        }
    };
    // Attach a listener that tracks every call received by the server.
    final TestServer server = new TestServer(1, false);
    server.callListener = new Runnable() {

        @Override
        public void run() {
            Assert.assertEquals(info.id, Server.getCallId());
            Assert.assertEquals(info.retry, Server.getCallRetryCount());
        }
    };
    try {
        InetSocketAddress addr = NetUtils.getConnectAddress(server);
        server.start();
        final SerialCaller caller = new SerialCaller(client, addr, 10);
        caller.run();
        assertFalse(caller.failed);
    } finally {
        client.stop();
        server.stop();
    }
}
Also used : Call(org.apache.hadoop.ipc.Server.Call) RpcResponseHeaderProto(org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcResponseHeaderProto) InetSocketAddress(java.net.InetSocketAddress) Writable(org.apache.hadoop.io.Writable) LongWritable(org.apache.hadoop.io.LongWritable) RpcKind(org.apache.hadoop.ipc.RPC.RpcKind) Test(org.junit.Test)

Aggregations

Call (org.apache.hadoop.ipc.Server.Call)6 Test (org.junit.Test)5 IOException (java.io.IOException)3 InetSocketAddress (java.net.InetSocketAddress)3 SocketTimeoutException (java.net.SocketTimeoutException)3 ExecutorService (java.util.concurrent.ExecutorService)3 LongWritable (org.apache.hadoop.io.LongWritable)3 Writable (org.apache.hadoop.io.Writable)3 ServiceException (com.google.protobuf.ServiceException)2 InterruptedIOException (java.io.InterruptedIOException)2 ConnectException (java.net.ConnectException)2 ArrayList (java.util.ArrayList)2 Callable (java.util.concurrent.Callable)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 TimeoutException (java.util.concurrent.TimeoutException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 HadoopIllegalArgumentException (org.apache.hadoop.HadoopIllegalArgumentException)2 Configuration (org.apache.hadoop.conf.Configuration)2 RpcKind (org.apache.hadoop.ipc.RPC.RpcKind)2