Search in sources :

Example 1 with FifoRpcScheduler

use of org.apache.hadoop.hbase.ipc.FifoRpcScheduler in project hbase by apache.

the class TestSecureIPC method callRpcService.

/**
 * Sets up a RPC Server and a Client. Does a RPC checks the result. If an exception is thrown from
 * the stub, this function will throw root cause of that exception.
 */
private void callRpcService(User clientUser) throws Exception {
    SecurityInfo securityInfoMock = Mockito.mock(SecurityInfo.class);
    Mockito.when(securityInfoMock.getServerPrincipal()).thenReturn(HBaseKerberosUtils.KRB_PRINCIPAL);
    SecurityInfo.addInfo("TestProtobufRpcProto", securityInfoMock);
    InetSocketAddress isa = new InetSocketAddress(HOST, 0);
    RpcServerInterface rpcServer = RpcServerFactory.createRpcServer(null, "AbstractTestSecureIPC", Lists.newArrayList(new RpcServer.BlockingServiceAndInterface((BlockingService) SERVICE, null)), isa, serverConf, new FifoRpcScheduler(serverConf, 1));
    rpcServer.start();
    try (RpcClient rpcClient = RpcClientFactory.createClient(clientConf, HConstants.DEFAULT_CLUSTER_ID.toString())) {
        BlockingInterface stub = newBlockingStub(rpcClient, rpcServer.getListenerAddress(), clientUser);
        TestThread th1 = new TestThread(stub);
        final Throwable[] exception = new Throwable[1];
        Collections.synchronizedList(new ArrayList<Throwable>());
        Thread.UncaughtExceptionHandler exceptionHandler = new Thread.UncaughtExceptionHandler() {

            @Override
            public void uncaughtException(Thread th, Throwable ex) {
                exception[0] = ex;
            }
        };
        th1.setUncaughtExceptionHandler(exceptionHandler);
        th1.start();
        th1.join();
        if (exception[0] != null) {
            // throw root cause.
            while (exception[0].getCause() != null) {
                exception[0] = exception[0].getCause();
            }
            throw (Exception) exception[0];
        }
    } finally {
        rpcServer.stop();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) FifoRpcScheduler(org.apache.hadoop.hbase.ipc.FifoRpcScheduler) SaslException(javax.security.sasl.SaslException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) RpcServerInterface(org.apache.hadoop.hbase.ipc.RpcServerInterface) BlockingRpcClient(org.apache.hadoop.hbase.ipc.BlockingRpcClient) RpcClient(org.apache.hadoop.hbase.ipc.RpcClient) NettyRpcClient(org.apache.hadoop.hbase.ipc.NettyRpcClient)

Aggregations

IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 SaslException (javax.security.sasl.SaslException)1 BlockingRpcClient (org.apache.hadoop.hbase.ipc.BlockingRpcClient)1 FifoRpcScheduler (org.apache.hadoop.hbase.ipc.FifoRpcScheduler)1 NettyRpcClient (org.apache.hadoop.hbase.ipc.NettyRpcClient)1 RpcClient (org.apache.hadoop.hbase.ipc.RpcClient)1 RpcServerInterface (org.apache.hadoop.hbase.ipc.RpcServerInterface)1 BlockingInterface (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface)1 ExpectedException (org.junit.rules.ExpectedException)1