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.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
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);
57 CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
58 master = HMaster.constructMaster(HMaster.class, conf, cp);
59 priority = master.getMasterRpcServices().getPriority();
60 }
61
62
63
64
65
66
67
68
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 }