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