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.jupiter.api.Assertions.assertTrue;
021
022import org.apache.hadoop.conf.Configuration;
023import org.apache.hadoop.hbase.HBaseConfiguration;
024import org.apache.hadoop.hbase.ipc.FifoRpcScheduler;
025import org.apache.hadoop.hbase.ipc.RWQueueRpcExecutor;
026import org.apache.hadoop.hbase.ipc.RpcExecutor;
027import org.apache.hadoop.hbase.ipc.RpcScheduler;
028import org.apache.hadoop.hbase.ipc.SimpleRpcScheduler;
029import org.apache.hadoop.hbase.testclassification.SmallTests;
030import org.junit.jupiter.api.BeforeEach;
031import org.junit.jupiter.api.Tag;
032import org.junit.jupiter.api.Test;
033
034/**
035 * A silly test that does nothing but make sure an rpcscheduler factory makes what it says it is
036 * going to make.
037 */
038@Tag(SmallTests.TAG)
039public class TestRpcSchedulerFactory {
040
041  private Configuration conf;
042
043  @BeforeEach
044  public void setUp() throws Exception {
045    this.conf = HBaseConfiguration.create();
046  }
047
048  @Test
049  public void testRWQ() {
050    // Set some configs just to see how it changes the scheduler. Can't assert the settings had
051    // an effect. Just eyeball the log.
052    this.conf.setDouble(RWQueueRpcExecutor.CALL_QUEUE_READ_SHARE_CONF_KEY, 0.5);
053    this.conf.setDouble(RpcExecutor.CALL_QUEUE_HANDLER_FACTOR_CONF_KEY, 0.5);
054    this.conf.setDouble(RWQueueRpcExecutor.CALL_QUEUE_SCAN_SHARE_CONF_KEY, 0.5);
055    RpcSchedulerFactory factory = new SimpleRpcSchedulerFactory();
056    RpcScheduler rpcScheduler = factory.create(this.conf, null, null);
057    assertTrue(rpcScheduler.getClass().equals(SimpleRpcScheduler.class));
058  }
059
060  @Test
061  public void testRWQWithoutReadShare() {
062    // Set some configs just to see how it changes the scheduler. Can't assert the settings had
063    // an effect. Just eyeball the log.
064    this.conf.setDouble(RWQueueRpcExecutor.CALL_QUEUE_READ_SHARE_CONF_KEY, 0);
065    this.conf.setDouble(RpcExecutor.CALL_QUEUE_HANDLER_FACTOR_CONF_KEY, 0.5);
066    this.conf.setDouble(RWQueueRpcExecutor.CALL_QUEUE_SCAN_SHARE_CONF_KEY, 0);
067    RpcSchedulerFactory factory = new SimpleRpcSchedulerFactory();
068    RpcScheduler rpcScheduler = factory.create(this.conf, null, null);
069    assertTrue(rpcScheduler.getClass().equals(SimpleRpcScheduler.class));
070  }
071
072  @Test
073  public void testFifo() {
074    RpcSchedulerFactory factory = new FifoRpcSchedulerFactory();
075    RpcScheduler rpcScheduler = factory.create(this.conf, null, null);
076    assertTrue(rpcScheduler.getClass().equals(FifoRpcScheduler.class));
077  }
078}