Search in sources :

Example 6 with BlockingServiceAndInterface

use of org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface in project hbase by apache.

the class AbstractTestIPC method testNoCodec.

/**
   * Ensure we do not HAVE TO HAVE a codec.
   */
@Test
public void testNoCodec() throws IOException, ServiceException {
    Configuration conf = HBaseConfiguration.create();
    RpcServer rpcServer = RpcServerFactory.createRpcServer(null, "testRpcServer", Lists.newArrayList(new BlockingServiceAndInterface(SERVICE, null)), new InetSocketAddress("localhost", 0), CONF, new FifoRpcScheduler(CONF, 1));
    try (AbstractRpcClient<?> client = createRpcClientNoCodec(conf)) {
        rpcServer.start();
        BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress());
        HBaseRpcController pcrc = new HBaseRpcControllerImpl();
        String message = "hello";
        assertEquals(message, stub.echo(pcrc, EchoRequestProto.newBuilder().setMessage(message).build()).getMessage());
        assertNull(pcrc.cellScanner());
    } 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) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 7 with BlockingServiceAndInterface

use of org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface in project hbase by apache.

the class RpcServerFactory method createRpcServer.

public static RpcServer createRpcServer(final Server server, final String name, final List<BlockingServiceAndInterface> services, final InetSocketAddress bindAddress, Configuration conf, RpcScheduler scheduler) throws IOException {
    String rpcServerClass = conf.get(CUSTOM_RPC_SERVER_IMPL_CONF_KEY, SimpleRpcServer.class.getName());
    StringBuffer servicesList = new StringBuffer();
    for (BlockingServiceAndInterface s : services) {
        ServiceDescriptor sd = s.getBlockingService().getDescriptorForType();
        // Can be null for certain tests like TestTokenAuthentication
        if (sd == null)
            continue;
        if (servicesList.length() > 0)
            servicesList.append(", ");
        servicesList.append(sd.getFullName());
    }
    LOG.info("Creating " + rpcServerClass + " hosting " + servicesList);
    return ReflectionUtils.instantiateWithCustomCtor(rpcServerClass, new Class[] { Server.class, String.class, List.class, InetSocketAddress.class, Configuration.class, RpcScheduler.class }, new Object[] { server, name, services, bindAddress, conf, scheduler });
}
Also used : BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) ServiceDescriptor(org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.ServiceDescriptor)

Example 8 with BlockingServiceAndInterface

use of org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface in project hbase by apache.

the class RSRpcServices method getServices.

/**
   * @return list of blocking services and their security info classes that this server supports
   */
protected List<BlockingServiceAndInterface> getServices() {
    List<BlockingServiceAndInterface> bssi = new ArrayList<>(2);
    bssi.add(new BlockingServiceAndInterface(ClientService.newReflectiveBlockingService(this), ClientService.BlockingInterface.class));
    bssi.add(new BlockingServiceAndInterface(AdminService.newReflectiveBlockingService(this), AdminService.BlockingInterface.class));
    return bssi;
}
Also used : BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) ArrayList(java.util.ArrayList)

Example 9 with BlockingServiceAndInterface

use of org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface 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 10 with BlockingServiceAndInterface

use of org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface in project hbase by apache.

the class AbstractTestIPC method testAsyncTimeout.

@Test
public void testAsyncTimeout() 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();
        Interface stub = newStub(client, rpcServer.getListenerAddress());
        List<HBaseRpcController> pcrcList = new ArrayList<>();
        List<BlockingRpcCallback<EmptyResponseProto>> callbackList = new ArrayList<>();
        int ms = 1000;
        int timeout = 100;
        long startTime = System.nanoTime();
        for (int i = 0; i < 10; i++) {
            HBaseRpcController pcrc = new HBaseRpcControllerImpl();
            pcrc.setCallTimeout(timeout);
            BlockingRpcCallback<EmptyResponseProto> callback = new BlockingRpcCallback<>();
            stub.pause(pcrc, PauseRequestProto.newBuilder().setMs(ms).build(), callback);
            pcrcList.add(pcrc);
            callbackList.add(callback);
        }
        for (BlockingRpcCallback<?> callback : callbackList) {
            assertNull(callback.get());
        }
        long waitTime = (System.nanoTime() - startTime) / 1000000;
        for (HBaseRpcController pcrc : pcrcList) {
            assertTrue(pcrc.failed());
            LOG.info("Caught expected exception: " + pcrc.getFailed());
            IOException ioe = ProtobufUtil.handleRemoteException(pcrc.getFailed());
            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) ArrayList(java.util.ArrayList) EmptyResponseProto(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EmptyResponseProto) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) Interface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.Interface) BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) Test(org.junit.Test)

Aggregations

BlockingServiceAndInterface (org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface)15 InetSocketAddress (java.net.InetSocketAddress)12 BlockingInterface (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface)12 Test (org.junit.Test)12 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Configuration (org.apache.hadoop.conf.Configuration)5 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)5 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)5 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)4 Interface (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.Interface)3 EchoRequestProto (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoRequestProto)2 EmptyResponseProto (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EmptyResponseProto)2 Abortable (org.apache.hadoop.hbase.Abortable)1 Cell (org.apache.hadoop.hbase.Cell)1 CellScanner (org.apache.hadoop.hbase.CellScanner)1 ServiceDescriptor (org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.ServiceDescriptor)1 EchoResponseProto (org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos.EchoResponseProto)1 GzipCodec (org.apache.hadoop.io.compress.GzipCodec)1 Ignore (org.junit.Ignore)1