1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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);
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
67
68
69
70
71
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 }