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.mockito.Mockito.when;
021
022import org.apache.hadoop.conf.Configuration;
023import org.apache.hadoop.hbase.HBaseClassTestRule;
024import org.apache.hadoop.hbase.HBaseConfiguration;
025import org.apache.hadoop.hbase.HConstants;
026import org.apache.hadoop.hbase.ipc.QosTestBase;
027import org.apache.hadoop.hbase.testclassification.MediumTests;
028import org.apache.hadoop.hbase.testclassification.RegionServerTests;
029import org.junit.Before;
030import org.junit.ClassRule;
031import org.junit.Test;
032import org.junit.experimental.categories.Category;
033import org.mockito.Mockito;
034
035import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRequest;
036
037/**
038 * Basic test that qos function is sort of working; i.e. a change in method naming style over in pb
039 * doesn't break it.
040 */
041@Category({ RegionServerTests.class, MediumTests.class })
042public class TestRSQosFunction extends QosTestBase {
043  @ClassRule
044  public static final HBaseClassTestRule CLASS_RULE =
045    HBaseClassTestRule.forClass(TestRSQosFunction.class);
046
047  private Configuration conf;
048  private RSRpcServices rpcServices;
049  private RSAnnotationReadingPriorityFunction qosFunction;
050
051  @Before
052  public void setUp() {
053    conf = HBaseConfiguration.create();
054    rpcServices = Mockito.mock(RSRpcServices.class);
055    when(rpcServices.getConfiguration()).thenReturn(conf);
056    qosFunction = new RSAnnotationReadingPriorityFunction(rpcServices);
057  }
058
059  @Test
060  public void testPriority() {
061    // Set method name in pb style with the method name capitalized.
062    checkMethod(conf, "ReplicateWALEntry", HConstants.REPLICATION_QOS, qosFunction);
063    // Set method name in pb style with the method name capitalized.
064    checkMethod(conf, "OpenRegion", HConstants.ADMIN_QOS, qosFunction);
065    // Check multi works.
066    checkMethod(conf, "Multi", HConstants.NORMAL_QOS, qosFunction,
067      MultiRequest.getDefaultInstance());
068  }
069
070  @Test
071  public void testAnnotations() {
072    checkMethod(conf, "CloseRegion", HConstants.ADMIN_QOS, qosFunction);
073    checkMethod(conf, "CompactRegion", HConstants.ADMIN_QOS, qosFunction);
074    checkMethod(conf, "FlushRegion", HConstants.ADMIN_QOS, qosFunction);
075    checkMethod(conf, "UpdateConfiguration", HConstants.ADMIN_QOS, qosFunction);
076    checkMethod(conf, "CompactionSwitch", HConstants.ADMIN_QOS, qosFunction);
077    checkMethod(conf, "RollWALWriter", HConstants.ADMIN_QOS, qosFunction);
078  }
079}