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.*; 024import org.apache.hadoop.hbase.HBaseClassTestRule; 025import org.apache.hadoop.hbase.testclassification.MediumTests; 026import org.apache.hadoop.hbase.testclassification.RegionServerTests; 027import org.junit.Before; 028import org.junit.ClassRule; 029import org.junit.Test; 030import org.junit.experimental.categories.Category; 031import org.mockito.Mockito; 032 033import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRequest; 034 035/** 036 * Basic test that qos function is sort of working; i.e. a change in method naming style 037 * over in pb doesn't break it. 038 */ 039@Category({RegionServerTests.class, MediumTests.class}) 040public class TestQosFunction extends QosTestHelper { 041 042 @ClassRule 043 public static final HBaseClassTestRule CLASS_RULE = 044 HBaseClassTestRule.forClass(TestQosFunction.class); 045 046 private Configuration conf; 047 private RSRpcServices rpcServices; 048 private AnnotationReadingPriorityFunction qosFunction; 049 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 AnnotationReadingPriorityFunction(rpcServices, RSRpcServices.class); 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 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}