View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.regionserver;
19  
20  import static org.junit.Assert.assertTrue;
21  
22  import org.apache.hadoop.conf.Configuration;
23  import org.apache.hadoop.hbase.CategoryBasedTimeout;
24  import org.apache.hadoop.hbase.HBaseConfiguration;
25  import org.apache.hadoop.hbase.ipc.FifoRpcScheduler;
26  import org.apache.hadoop.hbase.ipc.RWQueueRpcExecutor;
27  import org.apache.hadoop.hbase.ipc.RpcExecutor;
28  import org.apache.hadoop.hbase.ipc.RpcScheduler;
29  import org.apache.hadoop.hbase.ipc.SimpleRpcScheduler;
30  import org.apache.hadoop.hbase.testclassification.SmallTests;
31  import org.junit.Before;
32  import org.junit.ClassRule;
33  import org.junit.Rule;
34  import org.junit.Test;
35  import org.junit.experimental.categories.Category;
36  import org.junit.rules.TestName;
37  import org.junit.rules.TestRule;
38  
39  /**
40   * A silly test that does nothing but make sure an rpcscheduler factory makes what it says
41   * it is going to make.
42   */
43  @Category(SmallTests.class)
44  public class TestRpcSchedulerFactory {
45    @Rule public TestName testName = new TestName();
46    @ClassRule public static TestRule timeout =
47        CategoryBasedTimeout.forClass(TestRpcSchedulerFactory.class);
48    private Configuration conf;
49  
50    @Before
51    public void setUp() throws Exception {
52      this.conf = HBaseConfiguration.create();
53    }
54  
55    @Test
56    public void testRWQ() {
57      // Set some configs just to see how it changes the scheduler. Can't assert the settings had
58      // an effect. Just eyeball the log.
59      this.conf.setDouble(RWQueueRpcExecutor.CALL_QUEUE_READ_SHARE_CONF_KEY, 0.5);
60      this.conf.setDouble(RpcExecutor.CALL_QUEUE_HANDLER_FACTOR_CONF_KEY, 0.5);
61      this.conf.setDouble(RWQueueRpcExecutor.CALL_QUEUE_SCAN_SHARE_CONF_KEY, 0.5);
62      RpcSchedulerFactory factory = new SimpleRpcSchedulerFactory();
63      RpcScheduler rpcScheduler = factory.create(this.conf, null, null);
64      assertTrue(rpcScheduler.getClass().equals(SimpleRpcScheduler.class));
65    }
66  
67    @Test
68    public void testFifo() {
69      RpcSchedulerFactory factory = new FifoRpcSchedulerFactory();
70      RpcScheduler rpcScheduler = factory.create(this.conf, null, null);
71      assertTrue(rpcScheduler.getClass().equals(FifoRpcScheduler.class));
72    }
73  }