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.master; 019 020import static org.mockito.Mockito.when; 021 022import java.io.IOException; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hbase.HBaseClassTestRule; 025import org.apache.hadoop.hbase.HBaseConfiguration; 026import org.apache.hadoop.hbase.HConstants; 027import org.apache.hadoop.hbase.HRegionInfo; 028import org.apache.hadoop.hbase.QosTestHelper; 029import org.apache.hadoop.hbase.ServerName; 030import org.apache.hadoop.hbase.TableName; 031import org.apache.hadoop.hbase.regionserver.AnnotationReadingPriorityFunction; 032import org.apache.hadoop.hbase.regionserver.RSRpcServices; 033import org.apache.hadoop.hbase.testclassification.MasterTests; 034import org.apache.hadoop.hbase.testclassification.SmallTests; 035import org.apache.hadoop.hbase.util.Bytes; 036import org.junit.Before; 037import org.junit.ClassRule; 038import org.junit.Test; 039import org.junit.experimental.categories.Category; 040import org.mockito.Mockito; 041 042import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; 043import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos; 044import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos; 045 046@Category({ MasterTests.class, SmallTests.class }) 047public class TestMasterQosFunction extends QosTestHelper { 048 049 @ClassRule 050 public static final HBaseClassTestRule CLASS_RULE = 051 HBaseClassTestRule.forClass(TestMasterQosFunction.class); 052 053 private Configuration conf; 054 private RSRpcServices rpcServices; 055 private AnnotationReadingPriorityFunction qosFunction; 056 057 @Before 058 public void setUp() { 059 conf = HBaseConfiguration.create(); 060 rpcServices = Mockito.mock(MasterRpcServices.class); 061 when(rpcServices.getConfiguration()).thenReturn(conf); 062 qosFunction = new MasterAnnotationReadingPriorityFunction(rpcServices, MasterRpcServices.class); 063 } 064 065 @Test 066 public void testRegionInTransition() throws IOException { 067 // Check ReportRegionInTransition 068 HBaseProtos.RegionInfo meta_ri = HRegionInfo.convert(HRegionInfo.FIRST_META_REGIONINFO); 069 HBaseProtos.RegionInfo normal_ri = 070 HRegionInfo.convert(new HRegionInfo(TableName.valueOf("test:table"), Bytes.toBytes("a"), 071 Bytes.toBytes("b"), false)); 072 073 RegionServerStatusProtos.RegionStateTransition metaTransition = 074 RegionServerStatusProtos.RegionStateTransition.newBuilder().addRegionInfo(meta_ri) 075 .setTransitionCode(RegionServerStatusProtos.RegionStateTransition.TransitionCode.CLOSED) 076 .build(); 077 078 RegionServerStatusProtos.RegionStateTransition normalTransition = 079 RegionServerStatusProtos.RegionStateTransition.newBuilder().addRegionInfo(normal_ri) 080 .setTransitionCode(RegionServerStatusProtos.RegionStateTransition.TransitionCode.CLOSED) 081 .build(); 082 083 RegionServerStatusProtos.ReportRegionStateTransitionRequest metaTransitionRequest = 084 RegionServerStatusProtos.ReportRegionStateTransitionRequest.newBuilder() 085 .setServer(ProtobufUtil.toServerName(ServerName.valueOf("locahost:60020", 100))) 086 .addTransition(normalTransition).addTransition(metaTransition).build(); 087 088 RegionServerStatusProtos.ReportRegionStateTransitionRequest normalTransitionRequest = 089 RegionServerStatusProtos.ReportRegionStateTransitionRequest.newBuilder() 090 .setServer(ProtobufUtil.toServerName(ServerName.valueOf("locahost:60020", 100))) 091 .addTransition(normalTransition).build(); 092 093 final String reportFuncName = "ReportRegionStateTransition"; 094 checkMethod(conf, reportFuncName, HConstants.META_QOS, qosFunction, metaTransitionRequest); 095 checkMethod(conf, reportFuncName, HConstants.HIGH_QOS, qosFunction, normalTransitionRequest); 096 } 097 098 @Test 099 public void testAnnotations() { 100 checkMethod(conf, "GetLastFlushedSequenceId", HConstants.ADMIN_QOS, qosFunction); 101 checkMethod(conf, "CompactRegion", HConstants.ADMIN_QOS, qosFunction); 102 checkMethod(conf, "GetLastFlushedSequenceId", HConstants.ADMIN_QOS, qosFunction); 103 checkMethod(conf, "GetRegionInfo", HConstants.ADMIN_QOS, qosFunction); 104 } 105}