Search in sources :

Example 6 with BlockingInterface

use of org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface 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() {

            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)

Example 7 with BlockingInterface

use of org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface 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 8 with BlockingInterface

use of org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface in project hbase by apache.

the class AbstractTestIPC method testRpcServerForNotNullRemoteAddressInCallObject.

/**
   * Tests that the RpcServer creates & dispatches CallRunner object to scheduler with non-null
   * remoteAddress set to its Call Object
   * @throws ServiceException
   */
@Test
public void testRpcServerForNotNullRemoteAddressInCallObject() throws IOException, ServiceException {
    RpcServer rpcServer = RpcServerFactory.createRpcServer(null, "testRpcServer", Lists.newArrayList(new BlockingServiceAndInterface(SERVICE, null)), new InetSocketAddress("localhost", 0), CONF, new FifoRpcScheduler(CONF, 1));
    InetSocketAddress localAddr = new InetSocketAddress("localhost", 0);
    try (AbstractRpcClient<?> client = createRpcClient(CONF)) {
        rpcServer.start();
        BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress());
        assertEquals(localAddr.getAddress().getHostAddress(), stub.addr(null, EmptyRequestProto.getDefaultInstance()).getAddr());
    } finally {
        rpcServer.stop();
    }
}
Also used : BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 9 with BlockingInterface

use of org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface in project hbase by apache.

the class AbstractTestIPC method testRemoteError.

@Test
public void testRemoteError() throws IOException, ServiceException {
    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());
        stub.error(null, EmptyRequestProto.getDefaultInstance());
    } catch (ServiceException e) {
        LOG.info("Caught expected exception: " + e);
        IOException ioe = ProtobufUtil.handleRemoteException(e);
        assertTrue(ioe instanceof DoNotRetryIOException);
        assertTrue(ioe.getMessage().contains("server error!"));
    } finally {
        rpcServer.stop();
    }
}
Also used : BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) InetSocketAddress(java.net.InetSocketAddress) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with BlockingInterface

use of org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface in project hbase by apache.

the class AbstractTestIPC method testTimeout.

@Test
public void testTimeout() throws IOException {
    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());
        HBaseRpcController pcrc = new HBaseRpcControllerImpl();
        int ms = 1000;
        int timeout = 100;
        for (int i = 0; i < 10; i++) {
            pcrc.reset();
            pcrc.setCallTimeout(timeout);
            long startTime = System.nanoTime();
            try {
                stub.pause(pcrc, PauseRequestProto.newBuilder().setMs(ms).build());
            } catch (ServiceException e) {
                long waitTime = (System.nanoTime() - startTime) / 1000000;
                // expected
                LOG.info("Caught expected exception: " + e);
                IOException ioe = ProtobufUtil.handleRemoteException(e);
                assertTrue(ioe.getCause() instanceof CallTimeoutException);
                // confirm that we got exception before the actual pause.
                assertTrue(waitTime < ms);
            }
        }
    } finally {
        rpcServer.stop();
    }
}
Also used : BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) InetSocketAddress(java.net.InetSocketAddress) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) Test(org.junit.Test)

Aggregations

BlockingInterface (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface)12 Test (org.junit.Test)11 InetSocketAddress (java.net.InetSocketAddress)10 BlockingServiceAndInterface (org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface)9 Configuration (org.apache.hadoop.conf.Configuration)5 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)5 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)5 IOException (java.io.IOException)4 EchoRequestProto (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoRequestProto)4 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)3 ArrayList (java.util.ArrayList)1 SaslException (javax.security.sasl.SaslException)1 Abortable (org.apache.hadoop.hbase.Abortable)1 Cell (org.apache.hadoop.hbase.Cell)1 CellScanner (org.apache.hadoop.hbase.CellScanner)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