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 java.util.HashMap;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.fs.Path;
26 import org.apache.hadoop.hbase.CompatibilityFactory;
27 import org.apache.hadoop.hbase.HBaseTestingUtility;
28 import org.apache.hadoop.hbase.HConstants;
29 import org.apache.hadoop.hbase.HColumnDescriptor;
30 import org.apache.hadoop.hbase.HTableDescriptor;
31 import org.apache.hadoop.hbase.MiniHBaseCluster;
32 import org.apache.hadoop.hbase.TableName;
33 import org.apache.hadoop.hbase.client.Put;
34 import org.apache.hadoop.hbase.client.Table;
35 import org.apache.hadoop.hbase.test.MetricsAssertHelper;
36 import org.apache.hadoop.hbase.testclassification.MediumTests;
37 import org.apache.hadoop.hbase.util.Bytes;
38 import org.junit.AfterClass;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41 import org.junit.experimental.categories.Category;
42
43 @Category(MediumTests.class)
44 public class TestAssignmentManagerMetrics {
45
46 private static final Log LOG = LogFactory.getLog(TestAssignmentManagerMetrics.class);
47 private static final MetricsAssertHelper metricsHelper = CompatibilityFactory
48 .getInstance(MetricsAssertHelper.class);
49
50 private static MiniHBaseCluster cluster;
51 private static HMaster master;
52 private static HBaseTestingUtility TEST_UTIL;
53 private static Configuration conf;
54 private static final int msgInterval = 1000;
55
56 @BeforeClass
57 public static void startCluster() throws Exception {
58 LOG.info("Starting cluster");
59 TEST_UTIL = new HBaseTestingUtility();
60 conf = TEST_UTIL.getConfiguration();
61
62
63 conf.setBoolean("hbase.table.sanity.checks", false);
64
65
66 conf.setInt(HConstants.METRICS_RIT_STUCK_WARNING_THRESHOLD, 20);
67
68
69 conf.setInt("hbase.regionserver.msginterval", msgInterval);
70
71
72 conf.set("hbase.balancer.tablesOnMaster", "none");
73
74 TEST_UTIL.startMiniCluster(1);
75 cluster = TEST_UTIL.getHBaseCluster();
76 master = cluster.getMaster();
77 }
78
79 @AfterClass
80 public static void after() throws Exception {
81 if (TEST_UTIL != null) {
82 TEST_UTIL.shutdownMiniCluster();
83 }
84 }
85
86 @Test
87 public void testRITAssignmentManagerMetrics() throws Exception {
88
89 final TableName TABLENAME = TableName.valueOf("testRITMetrics");
90 final byte[] FAMILY = Bytes.toBytes("family");
91
92 Table table = null;
93 try {
94 table = TEST_UTIL.createTable(TABLENAME, FAMILY);
95
96 final byte[] row = Bytes.toBytes("row");
97 final byte[] qualifier = Bytes.toBytes("qualifier");
98 final byte[] value = Bytes.toBytes("value");
99
100 Put put = new Put(row);
101 put.addColumn(FAMILY, qualifier, value);
102 table.put(put);
103
104
105 Thread.sleep(msgInterval * 3);
106
107
108 MetricsAssignmentManagerSource amSource =
109 master.getAssignmentManager().getAssignmentManagerMetrics().getMetricsProcSource();
110
111 metricsHelper.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_NAME, 0, amSource);
112 metricsHelper.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_OVER_THRESHOLD_NAME, 0,
113 amSource);
114
115
116 HTableDescriptor htd = new HTableDescriptor(TABLENAME);
117 HColumnDescriptor hcd = new HColumnDescriptor(FAMILY);
118
119 htd.addFamily(hcd);
120
121 HashMap<String,String> kvs = new HashMap<>();
122 kvs.put("arg1", "1");
123 kvs.put("arg2", "2");
124 htd.addCoprocessor("com.foo.FooRegionObserver", new Path("hdfs:///foo.jar"), 1001, kvs);
125
126 TEST_UTIL.getHBaseAdmin().modifyTable(TABLENAME, htd);
127
128
129 Thread.sleep(msgInterval * 3);
130 metricsHelper.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_NAME, 1, amSource);
131 metricsHelper.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_OVER_THRESHOLD_NAME, 1,
132 amSource);
133
134 } finally {
135 if (table != null) {
136 table.close();
137 }
138 }
139 }
140 }