@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 RpcScheduler create(Configuration conf, PriorityFunction priorityFunction, Abortable abortable) { PhoenixRpcScheduler phoenixIndexRpcScheduler = (PhoenixRpcScheduler)super.create(conf, priorityFunction, abortable); phoenixIndexRpcScheduler.setIndexExecutorForTesting(indexRpcExecutor); phoenixIndexRpcScheduler.setMetadataExecutorForTesting(metadataRpcExecutor); return phoenixIndexRpcScheduler; }
/** * 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 RpcScheduler create(Configuration conf, PriorityFunction priorityFunction, Abortable abortable) { // create the delegate scheduler RpcScheduler delegate; try { // happens in <=0.98.4 where the scheduler factory is not visible delegate = new SimpleRpcSchedulerFactory().create(conf, priorityFunction, abortable); } catch (IllegalAccessError e) { LOG.fatal(VERSION_TOO_OLD_FOR_INDEX_RPC); throw e; } // get the index priority configs int indexPriority = getIndexPriority(conf); validatePriority(indexPriority); // get the metadata priority configs int metadataPriority = getMetadataPriority(conf); validatePriority(metadataPriority); // validate index and metadata priorities are not the same Preconditions.checkArgument(indexPriority != metadataPriority, "Index and Metadata priority must not be same "+ indexPriority); LOG.info("Using custom Phoenix Index RPC Handling with index rpc priority " + indexPriority + " and metadata rpc priority " + metadataPriority); PhoenixRpcScheduler scheduler = new PhoenixRpcScheduler(conf, delegate, indexPriority, metadataPriority, priorityFunction,abortable); return scheduler; }
@Override public RpcScheduler create(Configuration conf, PriorityFunction priorityFunction, Abortable abortable) { // create the delegate scheduler RpcScheduler delegate; try { // happens in <=0.98.4 where the scheduler factory is not visible delegate = new SimpleRpcSchedulerFactory().create(conf, priorityFunction, abortable); } catch (IllegalAccessError e) { LOG.fatal(VERSION_TOO_OLD_FOR_INDEX_RPC); throw e; } // get the index priority configs int indexPriority = getIndexPriority(conf); validatePriority(indexPriority); // get the metadata priority configs int metadataPriority = getMetadataPriority(conf); validatePriority(metadataPriority); // validate index and metadata priorities are not the same Preconditions.checkArgument(indexPriority != metadataPriority, "Index and Metadata priority must not be same "+ indexPriority); LOG.info("Using custom Phoenix Index RPC Handling with index rpc priority " + indexPriority + " and metadata rpc priority " + metadataPriority); PhoenixRpcScheduler scheduler = new PhoenixRpcScheduler(conf, delegate, indexPriority, metadataPriority, priorityFunction,abortable); return scheduler; }
@Override public RpcScheduler create(Configuration conf, PriorityFunction priorityFunction, Abortable abortable) { // create the delegate scheduler RpcScheduler delegate; try { // happens in <=0.98.4 where the scheduler factory is not visible delegate = new SimpleRpcSchedulerFactory().create(conf, priorityFunction, abortable); } catch (IllegalAccessError e) { LOG.fatal(VERSION_TOO_OLD_FOR_INDEX_RPC); throw e; } // get the index priority configs int indexPriority = getIndexPriority(conf); validatePriority(indexPriority); // get the metadata priority configs int metadataPriority = getMetadataPriority(conf); validatePriority(metadataPriority); // validate index and metadata priorities are not the same Preconditions.checkArgument(indexPriority != metadataPriority, "Index and Metadata priority must not be same "+ indexPriority); LOG.info("Using custom Phoenix Index RPC Handling with index rpc priority " + indexPriority + " and metadata rpc priority " + metadataPriority); PhoenixRpcScheduler scheduler = new PhoenixRpcScheduler(conf, delegate, indexPriority, metadataPriority, priorityFunction,abortable); return scheduler; }