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