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 over in pb 039 * 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 @Before 053 public void setUp() { 054 conf = HBaseConfiguration.create(); 055 rpcServices = Mockito.mock(RSRpcServices.class); 056 when(rpcServices.getConfiguration()).thenReturn(conf); 057 qosFunction = new AnnotationReadingPriorityFunction(rpcServices, RSRpcServices.class); 058 } 059 060 @Test 061 public void testPriority() { 062 // Set method name in pb style with the method name capitalized. 063 checkMethod(conf, "ReplicateWALEntry", HConstants.REPLICATION_QOS, qosFunction); 064 // Set method name in pb style with the method name capitalized. 065 checkMethod(conf, "OpenRegion", HConstants.ADMIN_QOS, qosFunction); 066 // Check multi works. 067 checkMethod(conf, "Multi", HConstants.NORMAL_QOS, qosFunction, 068 MultiRequest.getDefaultInstance()); 069 070 } 071 072 @Test 073 public void testAnnotations() { 074 checkMethod(conf, "CloseRegion", HConstants.ADMIN_QOS, qosFunction); 075 checkMethod(conf, "CompactRegion", HConstants.ADMIN_QOS, qosFunction); 076 checkMethod(conf, "FlushRegion", HConstants.ADMIN_QOS, qosFunction); 077 } 078}