@Override public boolean dispatch(CallRunner task) throws IOException, InterruptedException { return delegate.dispatch(task); }
doAnswerTaskExecution(hugeCallTask, work, 100, 250); scheduler.dispatch(smallCallTask); scheduler.dispatch(smallCallTask); scheduler.dispatch(smallCallTask); scheduler.dispatch(hugeCallTask); scheduler.dispatch(smallCallTask); scheduler.dispatch(largeCallTask); scheduler.dispatch(smallCallTask); scheduler.dispatch(smallCallTask);
@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(); }
for (CallRunner task : tasks) { when(qosFunction.getPriority(any(), any(), any())).thenReturn(qos.get(task)); scheduler.dispatch(task);
if (!scheduler.dispatch(task)) { unableToDispatch++;
/** * 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(); }
this.addr, timeout, this.callCleanup); if (!this.rpcServer.scheduler.dispatch(new CallRunner(this.rpcServer, call))) { this.rpcServer.callQueueSizeInBytes.add(-1 * call.getSize()); this.rpcServer.metrics.exception(RpcServer.CALL_QUEUE_TOO_BIG_EXCEPTION);
@Override public boolean dispatch(CallRunner callTask) throws InterruptedException, IOException { ServerCall call = callTask.getCall(); int priority = call.getHeader().getPriority(); if (indexPriority == priority) { return indexCallExecutor.dispatch(callTask); } else if (metadataPriority == priority) { return metadataCallExecutor.dispatch(callTask); } else { return delegate.dispatch(callTask); } }
private void dispatchCallWithPriority(RpcScheduler scheduler, int priority) throws Exception { CallRunner task = Mockito.mock(CallRunner.class); RequestHeader header = RequestHeader.newBuilder().setPriority(priority).build(); RpcServer server = RpcServerFactory.createRpcServer(null, "test-rpcserver", Lists.newArrayList(new BlockingServiceAndInterface( SERVICE, null)), isa, conf, scheduler); ServerCall call = Mockito.mock(ServerCall.class); when(call.getHeader()).thenReturn(header); when(call.getRequestUser()).thenReturn(Optional.empty()); Mockito.when(task.getCall()).thenReturn(call); scheduler.dispatch(task); Mockito.verify(task).getCall(); Mockito.verifyNoMoreInteractions(task); server.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(); }
@Override public boolean dispatch(CallRunner task) throws IOException, InterruptedException { return delegate.dispatch(task); }
@Override public boolean dispatch(CallRunner callTask) throws InterruptedException, IOException { ServerCall call = callTask.getCall(); int priority = call.getHeader().getPriority(); if (indexPriority == priority) { return indexCallExecutor.dispatch(callTask); } else if (metadataPriority == priority) { return metadataCallExecutor.dispatch(callTask); } else { return delegate.dispatch(callTask); } }
@Override public boolean dispatch(CallRunner callTask) throws InterruptedException, IOException { ServerCall call = callTask.getCall(); int priority = call.getHeader().getPriority(); if (indexPriority == priority) { return indexCallExecutor.dispatch(callTask); } else if (metadataPriority == priority) { return metadataCallExecutor.dispatch(callTask); } else { return delegate.dispatch(callTask); } }
@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(); }
/** * 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(); }