HBASE-25032 Do not assign regions to region server which has not called regionServerR...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / master / TestMasterQosFunction.java
blob9f46ca2c46fdeba765e3278b5b5fb79d06bce50b
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.master;
20 import static org.mockito.Mockito.when;
22 import java.io.IOException;
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.hadoop.hbase.HBaseClassTestRule;
25 import org.apache.hadoop.hbase.HBaseConfiguration;
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.QosTestHelper;
28 import org.apache.hadoop.hbase.ServerName;
29 import org.apache.hadoop.hbase.TableName;
30 import org.apache.hadoop.hbase.client.RegionInfoBuilder;
31 import org.apache.hadoop.hbase.regionserver.AnnotationReadingPriorityFunction;
32 import org.apache.hadoop.hbase.regionserver.RSRpcServices;
33 import org.apache.hadoop.hbase.testclassification.MasterTests;
34 import org.apache.hadoop.hbase.testclassification.SmallTests;
35 import org.apache.hadoop.hbase.util.Bytes;
36 import org.junit.Before;
37 import org.junit.ClassRule;
38 import org.junit.Test;
39 import org.junit.experimental.categories.Category;
40 import org.mockito.Mockito;
42 import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
43 import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
44 import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos;
46 @Category({MasterTests.class, SmallTests.class})
47 public class TestMasterQosFunction extends QosTestHelper {
49 @ClassRule
50 public static final HBaseClassTestRule CLASS_RULE =
51 HBaseClassTestRule.forClass(TestMasterQosFunction.class);
53 private Configuration conf;
54 private RSRpcServices rpcServices;
55 private AnnotationReadingPriorityFunction qosFunction;
58 @Before
59 public void setUp() {
60 conf = HBaseConfiguration.create();
61 rpcServices = Mockito.mock(MasterRpcServices.class);
62 when(rpcServices.getConfiguration()).thenReturn(conf);
63 qosFunction = new MasterAnnotationReadingPriorityFunction(rpcServices, MasterRpcServices.class);
66 @Test
67 public void testRegionInTransition() throws IOException {
68 // Check ReportRegionInTransition
69 HBaseProtos.RegionInfo meta_ri =
70 ProtobufUtil.toRegionInfo(RegionInfoBuilder.FIRST_META_REGIONINFO);
71 HBaseProtos.RegionInfo normal_ri =
72 ProtobufUtil.toRegionInfo(RegionInfoBuilder.newBuilder(TableName.valueOf("test:table"))
73 .setStartKey(Bytes.toBytes("a")).setEndKey(Bytes.toBytes("b")).build());
76 RegionServerStatusProtos.RegionStateTransition metaTransition = RegionServerStatusProtos
77 .RegionStateTransition.newBuilder()
78 .addRegionInfo(meta_ri)
79 .setTransitionCode(RegionServerStatusProtos.RegionStateTransition.TransitionCode.CLOSED)
80 .build();
82 RegionServerStatusProtos.RegionStateTransition normalTransition = RegionServerStatusProtos
83 .RegionStateTransition.newBuilder()
84 .addRegionInfo(normal_ri)
85 .setTransitionCode(RegionServerStatusProtos.RegionStateTransition.TransitionCode.CLOSED)
86 .build();
88 RegionServerStatusProtos.ReportRegionStateTransitionRequest metaTransitionRequest =
89 RegionServerStatusProtos.ReportRegionStateTransitionRequest.newBuilder()
90 .setServer(ProtobufUtil.toServerName(ServerName.valueOf("locahost:60020", 100)))
91 .addTransition(normalTransition)
92 .addTransition(metaTransition).build();
94 RegionServerStatusProtos.ReportRegionStateTransitionRequest normalTransitionRequest =
95 RegionServerStatusProtos.ReportRegionStateTransitionRequest.newBuilder()
96 .setServer(ProtobufUtil.toServerName(ServerName.valueOf("locahost:60020", 100)))
97 .addTransition(normalTransition).build();
99 final String reportFuncName = "ReportRegionStateTransition";
100 checkMethod(conf, reportFuncName, 300, qosFunction,
101 metaTransitionRequest);
102 checkMethod(conf, reportFuncName, HConstants.HIGH_QOS, qosFunction, normalTransitionRequest);
105 @Test
106 public void testAnnotations() {
107 checkMethod(conf, "GetLastFlushedSequenceId", HConstants.ADMIN_QOS, qosFunction);
108 checkMethod(conf, "CompactRegion", HConstants.ADMIN_QOS, qosFunction);
109 checkMethod(conf, "GetLastFlushedSequenceId", HConstants.ADMIN_QOS, qosFunction);
110 checkMethod(conf, "GetRegionInfo", HConstants.ADMIN_QOS, qosFunction);