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();
}
}
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 });
}
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;
}
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();
}
}
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();
}
}
Aggregations