@Override public void init(Context context) { delegate.init(context); } @Override
/** * Constructs a server listening on the named port and address. * @param server hosting instance of {@link Server}. We will do authentications if an * instance else pass null for no authentication check. * @param name Used keying this rpc servers' metrics and for naming the Listener thread. * @param services A list of services. * @param bindAddress Where to listen * @param conf * @param scheduler * @param reservoirEnabled Enable ByteBufferPool or not. */ public SimpleRpcServer(final Server server, final String name, final List<BlockingServiceAndInterface> services, final InetSocketAddress bindAddress, Configuration conf, RpcScheduler scheduler, boolean reservoirEnabled) throws IOException { super(server, name, services, bindAddress, conf, scheduler, reservoirEnabled); this.socketSendBufferSize = 0; this.readThreads = conf.getInt("hbase.ipc.server.read.threadpool.size", 10); this.purgeTimeout = conf.getLong("hbase.ipc.client.call.purge.timeout", 2 * HConstants.DEFAULT_HBASE_RPC_TIMEOUT); // Start the listener here and let it bind to the port listener = new Listener(name); this.port = listener.getAddress().getPort(); // Create the responder here responder = new SimpleRpcServerResponder(this); connectionManager = new ConnectionManager(); initReconfigurable(conf); this.scheduler.init(new RpcSchedulerContext(this)); }
@Test public void testBasic() throws IOException, InterruptedException { PriorityFunction qosFunction = mock(PriorityFunction.class); RpcScheduler scheduler = new SimpleRpcScheduler( conf, 10, 0, 0, qosFunction, 0); scheduler.init(CONTEXT); scheduler.start(); CallRunner task = createMockTask(); task.setStatus(new MonitoredRPCHandlerImpl()); scheduler.dispatch(task); verify(task, timeout(10000)).run(); scheduler.stop(); }
this.scheduler.init(new RpcSchedulerContext(this));
scheduler.init(CONTEXT); scheduler.start(); for (CallRunner task : tasks) {
/** * Tests that the rpc scheduler is called when requests arrive. */ @Test public void testRpcScheduler() throws IOException, ServiceException, InterruptedException { RpcScheduler scheduler = spy(new FifoRpcScheduler(CONF, 1)); RpcServer rpcServer = createRpcServer(null, "testRpcServer", Lists.newArrayList(new RpcServer.BlockingServiceAndInterface( SERVICE, null)), new InetSocketAddress("localhost", 0), CONF, scheduler); verify(scheduler).init((RpcScheduler.Context) anyObject()); try (AbstractRpcClient<?> client = createRpcClient(CONF)) { rpcServer.start(); verify(scheduler).start(); BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress()); EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build(); for (int i = 0; i < 10; i++) { stub.echo(null, param); } verify(scheduler, times(10)).dispatch((CallRunner) anyObject()); } finally { rpcServer.stop(); verify(scheduler).stop(); } }
@Test public void testCallQueueInfo() throws IOException, InterruptedException { ThreadPoolExecutor rpcExecutor; RpcScheduler scheduler = new FifoRpcScheduler( conf, 1); scheduler.init(CONTEXT); // Set number of handlers to a minimum value disableHandlers(scheduler); int totalCallMethods = 30; int unableToDispatch = 0; for (int i = totalCallMethods; i>0; i--) { CallRunner task = createMockTask(); task.setStatus(new MonitoredRPCHandlerImpl()); if(!scheduler.dispatch(task)) { unableToDispatch++; } Thread.sleep(10); } CallQueueInfo callQueueInfo = scheduler.getCallQueueInfo(); int executionCount = callExecutionCount.get(); int callQueueSize = 0; for (String callQueueName:callQueueInfo.getCallQueueNames()) { for (String calledMethod: callQueueInfo.getCalledMethodNames(callQueueName)) { callQueueSize += callQueueInfo.getCallMethodCount(callQueueName, calledMethod); } } assertEquals(totalCallMethods - unableToDispatch, callQueueSize + executionCount); scheduler.stop(); }
@Override public void init(Context context) { delegate.init(context); this.port = context.getListenerAddress().getPort(); }
@Test public void testCallQueueInfo() throws IOException, InterruptedException { PriorityFunction qosFunction = mock(PriorityFunction.class); RpcScheduler scheduler = new SimpleRpcScheduler( conf, 0, 0, 0, qosFunction, 0); scheduler.init(CONTEXT); // Set the handlers to zero. So that number of requests in call Queue can be tested scheduler = disableHandlers(scheduler); scheduler.start(); int totalCallMethods = 10; for (int i = totalCallMethods; i>0; i--) { CallRunner task = createMockTask(); task.setStatus(new MonitoredRPCHandlerImpl()); scheduler.dispatch(task); } CallQueueInfo callQueueInfo = scheduler.getCallQueueInfo(); for (String callQueueName:callQueueInfo.getCallQueueNames()) { for (String calledMethod: callQueueInfo.getCalledMethodNames(callQueueName)) { assertEquals(totalCallMethods, callQueueInfo.getCallMethodCount(callQueueName, calledMethod)); } } scheduler.stop(); }
/** * Test that we delegate to the passed {@link RpcScheduler} when the call priority is outside * the index range * @throws Exception */ @Test public void testDelegateWhenOutsideRange() throws Exception { PriorityFunction qosFunction = Mockito.mock(PriorityFunction.class); Abortable abortable = new AbortServer(); RpcScheduler mock = Mockito.mock(RpcScheduler.class); PhoenixRpcScheduler scheduler = new PhoenixRpcScheduler(conf, mock, 200, 250,qosFunction,abortable); dispatchCallWithPriority(scheduler, 100); dispatchCallWithPriority(scheduler, 251); // try again, this time we tweak the ranges we support scheduler = new PhoenixRpcScheduler(conf, mock, 101, 110,qosFunction,abortable); dispatchCallWithPriority(scheduler, 200); dispatchCallWithPriority(scheduler, 111); Mockito.verify(mock, Mockito.times(4)).init(Mockito.any(Context.class)); Mockito.verify(mock, Mockito.times(4)).dispatch(Mockito.any(CallRunner.class)); scheduler.stop(); }
@Test public void testIndexPriorityWritesToIndexHandler() throws Exception { RpcScheduler mock = Mockito.mock(RpcScheduler.class); PriorityFunction qosFunction = Mockito.mock(PriorityFunction.class); Abortable abortable = new AbortServer(); PhoenixRpcScheduler scheduler = new PhoenixRpcScheduler(conf, mock, 200, 250,qosFunction,abortable); BalancedQueueRpcExecutor executor = new BalancedQueueRpcExecutor("test-queue", 1, 1,qosFunction,conf,abortable); scheduler.setIndexExecutorForTesting(executor); dispatchCallWithPriority(scheduler, 200); List<BlockingQueue<CallRunner>> queues = executor.getQueues(); assertEquals(1, queues.size()); BlockingQueue<CallRunner> queue = queues.get(0); queue.poll(20, TimeUnit.SECONDS); // try again, this time we tweak the ranges we support scheduler = new PhoenixRpcScheduler(conf, mock, 101, 110,qosFunction,abortable); scheduler.setIndexExecutorForTesting(executor); dispatchCallWithPriority(scheduler, 101); queue.poll(20, TimeUnit.SECONDS); Mockito.verify(mock, Mockito.times(2)).init(Mockito.any(Context.class)); scheduler.stop(); executor.stop(); }
@Override public void init(Context context) { delegate.init(context); } @Override
@Override public void init(Context context) { delegate.init(context); this.port = context.getListenerAddress().getPort(); }
@Override public void init(Context context) { delegate.init(context); this.port = context.getListenerAddress().getPort(); }
this.scheduler.init(new RpcSchedulerContext(this));
@Test public void testBasic() throws IOException, InterruptedException { PriorityFunction qosFunction = mock(PriorityFunction.class); RpcScheduler scheduler = new SimpleRpcScheduler( conf, 10, 0, 0, qosFunction, 0); scheduler.init(CONTEXT); scheduler.start(); CallRunner task = createMockTask(); task.setStatus(new MonitoredRPCHandlerImpl()); scheduler.dispatch(task); verify(task, timeout(10000)).run(); scheduler.stop(); }
scheduler.init(CONTEXT); scheduler.start(); for (CallRunner task : tasks) {
/** * Tests that the rpc scheduler is called when requests arrive. */ @Test public void testRpcScheduler() throws IOException, ServiceException, InterruptedException { RpcScheduler scheduler = spy(new FifoRpcScheduler(CONF, 1)); RpcServer rpcServer = createRpcServer(null, "testRpcServer", Lists.newArrayList(new RpcServer.BlockingServiceAndInterface( SERVICE, null)), new InetSocketAddress("localhost", 0), CONF, scheduler); verify(scheduler).init((RpcScheduler.Context) anyObject()); try (AbstractRpcClient<?> client = createRpcClient(CONF)) { rpcServer.start(); verify(scheduler).start(); BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress()); EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build(); for (int i = 0; i < 10; i++) { stub.echo(null, param); } verify(scheduler, times(10)).dispatch((CallRunner) anyObject()); } finally { rpcServer.stop(); verify(scheduler).stop(); } }
@Test public void testCallQueueInfo() throws IOException, InterruptedException { ThreadPoolExecutor rpcExecutor; RpcScheduler scheduler = new FifoRpcScheduler( conf, 1); scheduler.init(CONTEXT); // Set number of handlers to a minimum value disableHandlers(scheduler); int totalCallMethods = 30; int unableToDispatch = 0; for (int i = totalCallMethods; i>0; i--) { CallRunner task = createMockTask(); task.setStatus(new MonitoredRPCHandlerImpl()); if(!scheduler.dispatch(task)) { unableToDispatch++; } Thread.sleep(10); } CallQueueInfo callQueueInfo = scheduler.getCallQueueInfo(); int executionCount = callExecutionCount.get(); int callQueueSize = 0; for (String callQueueName:callQueueInfo.getCallQueueNames()) { for (String calledMethod: callQueueInfo.getCalledMethodNames(callQueueName)) { callQueueSize += callQueueInfo.getCallMethodCount(callQueueName, calledMethod); } } assertEquals(totalCallMethods - unableToDispatch, callQueueSize + executionCount); scheduler.stop(); }
@Test public void testCallQueueInfo() throws IOException, InterruptedException { PriorityFunction qosFunction = mock(PriorityFunction.class); RpcScheduler scheduler = new SimpleRpcScheduler( conf, 0, 0, 0, qosFunction, 0); scheduler.init(CONTEXT); // Set the handlers to zero. So that number of requests in call Queue can be tested scheduler = disableHandlers(scheduler); scheduler.start(); int totalCallMethods = 10; for (int i = totalCallMethods; i>0; i--) { CallRunner task = createMockTask(); task.setStatus(new MonitoredRPCHandlerImpl()); scheduler.dispatch(task); } CallQueueInfo callQueueInfo = scheduler.getCallQueueInfo(); for (String callQueueName:callQueueInfo.getCallQueueNames()) { for (String calledMethod: callQueueInfo.getCalledMethodNames(callQueueName)) { assertEquals(totalCallMethods, callQueueInfo.getCallMethodCount(callQueueName, calledMethod)); } } scheduler.stop(); }