View Javadoc

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
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
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.
17   */
18  package org.apache.hadoop.hbase.master;
19  
20  import static org.junit.Assert.assertEquals;
21  
22  import java.util.Set;
23  
24  import org.apache.hadoop.conf.Configuration;
25  import org.apache.hadoop.hbase.CoordinatedStateManager;
26  import org.apache.hadoop.hbase.CoordinatedStateManagerFactory;
27  import org.apache.hadoop.hbase.HBaseConfiguration;
28  import org.apache.hadoop.hbase.HConstants;
29  import org.apache.hadoop.hbase.ipc.PriorityFunction;
30  import org.apache.hadoop.hbase.protobuf.generated.RPCProtos.RequestHeader;
31  import org.apache.hadoop.hbase.testclassification.MediumTests;
32  import org.junit.Before;
33  import org.junit.Test;
34  import org.junit.experimental.categories.Category;
35  
36  import com.google.common.collect.Sets;
37  
38  /**
39   * Tests to verify correct priority on Master RPC methods.
40   */
41  @Category({MediumTests.class})
42  public class TestMasterPriorityRpc {
43    private HMaster master = null;
44    private PriorityFunction priority = null;
45  
46    private final Set<String> ADMIN_METHODS = Sets.newHashSet("GetLastFlushedSequenceId",
47        "RegionServerReport", "RegionServerStartup", "ReportRSFatalError",
48        "ReportRegionStateTransition");
49  
50    private final Set<String> NORMAL_METHODS = Sets.newHashSet("CreateTable", "DeleteTable",
51        "ModifyColumn", "OfflineRegion", "Shutdown");
52  
53    @Before
54    public void setup() {
55      Configuration conf = HBaseConfiguration.create();
56      conf.setBoolean("hbase.testing.nocluster", true); // No need to do ZK
57      CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
58      master = HMaster.constructMaster(HMaster.class, conf, cp);
59      priority = master.getMasterRpcServices().getPriority();
60    }
61  
62    /**
63     * Asserts that the provided method has the given priority.
64     *
65     * @param methodName
66     *          The name of the RPC method.
67     * @param expectedPriority
68     *          The expected priority.
69     */
70    private void assertPriority(String methodName, int expectedPriority) {
71      assertEquals(methodName + " had unexpected priority", expectedPriority,
72          priority.getPriority(RequestHeader.newBuilder().setMethodName(methodName).build(), null));
73    }
74  
75    @Test
76    public void testNullMessage() {
77      assertPriority("doesnotexist", HConstants.NORMAL_QOS);
78    }
79  
80    @Test
81    public void testAdminPriorityMethods() {
82      for (String methodName : ADMIN_METHODS) {
83        assertPriority(methodName, HConstants.ADMIN_QOS);
84      }
85    }
86  
87    @Test
88    public void testSomeNormalMethods() {
89      for (String methodName : NORMAL_METHODS) {
90        assertPriority(methodName, HConstants.NORMAL_QOS);
91      }
92    }
93  }