001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver;
019
020import static org.junit.Assert.assertTrue;
021
022import org.apache.hadoop.conf.Configuration;
023import org.apache.hadoop.hbase.HBaseClassTestRule;
024import org.apache.hadoop.hbase.HBaseConfiguration;
025import org.apache.hadoop.hbase.ipc.FifoRpcScheduler;
026import org.apache.hadoop.hbase.ipc.RWQueueRpcExecutor;
027import org.apache.hadoop.hbase.ipc.RpcExecutor;
028import org.apache.hadoop.hbase.ipc.RpcScheduler;
029import org.apache.hadoop.hbase.ipc.SimpleRpcScheduler;
030import org.apache.hadoop.hbase.testclassification.SmallTests;
031import org.junit.Before;
032import org.junit.ClassRule;
033import org.junit.Rule;
034import org.junit.Test;
035import org.junit.experimental.categories.Category;
036import org.junit.rules.TestName;
037
038/**
039 * A silly test that does nothing but make sure an rpcscheduler factory makes what it says it is
040 * going to make.
041 */
042@Category(SmallTests.class)
043public class TestRpcSchedulerFactory {
044
045  @ClassRule
046  public static final HBaseClassTestRule CLASS_RULE =
047    HBaseClassTestRule.forClass(TestRpcSchedulerFactory.class);
048
049  @Rule
050  public TestName testName = new TestName();
051  private Configuration conf;
052
053  @Before
054  public void setUp() throws Exception {
055    this.conf = HBaseConfiguration.create();
056  }
057
058  @Test
059  public void testRWQ() {
060    // Set some configs just to see how it changes the scheduler. Can't assert the settings had
061    // an effect. Just eyeball the log.
062    this.conf.setDouble(RWQueueRpcExecutor.CALL_QUEUE_READ_SHARE_CONF_KEY, 0.5);
063    this.conf.setDouble(RpcExecutor.CALL_QUEUE_HANDLER_FACTOR_CONF_KEY, 0.5);
064    this.conf.setDouble(RWQueueRpcExecutor.CALL_QUEUE_SCAN_SHARE_CONF_KEY, 0.5);
065    RpcSchedulerFactory factory = new SimpleRpcSchedulerFactory();
066    RpcScheduler rpcScheduler = factory.create(this.conf, null, null);
067    assertTrue(rpcScheduler.getClass().equals(SimpleRpcScheduler.class));
068  }
069
070  @Test
071  public void testRWQWithoutReadShare() {
072    // Set some configs just to see how it changes the scheduler. Can't assert the settings had
073    // an effect. Just eyeball the log.
074    this.conf.setDouble(RWQueueRpcExecutor.CALL_QUEUE_READ_SHARE_CONF_KEY, 0);
075    this.conf.setDouble(RpcExecutor.CALL_QUEUE_HANDLER_FACTOR_CONF_KEY, 0.5);
076    this.conf.setDouble(RWQueueRpcExecutor.CALL_QUEUE_SCAN_SHARE_CONF_KEY, 0);
077    RpcSchedulerFactory factory = new SimpleRpcSchedulerFactory();
078    RpcScheduler rpcScheduler = factory.create(this.conf, null, null);
079    assertTrue(rpcScheduler.getClass().equals(SimpleRpcScheduler.class));
080  }
081
082  @Test
083  public void testFifo() {
084    RpcSchedulerFactory factory = new FifoRpcSchedulerFactory();
085    RpcScheduler rpcScheduler = factory.create(this.conf, null, null);
086    assertTrue(rpcScheduler.getClass().equals(FifoRpcScheduler.class));
087  }
088}