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.QosTestHelper;
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
039 * over in pb doesn't break it.
040 */
041@Category({RegionServerTests.class, MediumTests.class})
042public class TestQosFunction extends QosTestHelper {
043
044  @ClassRule
045  public static final HBaseClassTestRule CLASS_RULE =
046      HBaseClassTestRule.forClass(TestQosFunction.class);
047
048  private Configuration conf;
049  private RSRpcServices rpcServices;
050  private AnnotationReadingPriorityFunction qosFunction;
051
052
053  @Before
054  public void setUp() {
055    conf = HBaseConfiguration.create();
056    rpcServices = Mockito.mock(RSRpcServices.class);
057    when(rpcServices.getConfiguration()).thenReturn(conf);
058    qosFunction = new AnnotationReadingPriorityFunction(rpcServices, RSRpcServices.class);
059  }
060
061  @Test
062  public void testPriority() {
063    // Set method name in pb style with the method name capitalized.
064    checkMethod(conf, "ReplicateWALEntry", HConstants.REPLICATION_QOS, qosFunction);
065    // Set method name in pb style with the method name capitalized.
066    checkMethod(conf, "OpenRegion", HConstants.ADMIN_QOS, qosFunction);
067    // Check multi works.
068    checkMethod(conf, "Multi", HConstants.NORMAL_QOS, qosFunction,
069        MultiRequest.getDefaultInstance());
070
071  }
072
073
074  @Test
075  public void testAnnotations() {
076    checkMethod(conf, "CloseRegion", HConstants.ADMIN_QOS, qosFunction);
077    checkMethod(conf, "CompactRegion", HConstants.ADMIN_QOS, qosFunction);
078    checkMethod(conf, "FlushRegion", HConstants.ADMIN_QOS, qosFunction);
079  }
080}