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