1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.regionserver;
19
20 import java.io.IOException;
21
22 import org.apache.hadoop.hbase.CompatibilityFactory;
23 import org.apache.hadoop.hbase.HBaseConfiguration;
24 import org.apache.hadoop.hbase.test.MetricsAssertHelper;
25 import org.apache.hadoop.hbase.testclassification.SmallTests;
26 import org.junit.Before;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31 @Category({SmallTests.class})
32 public class TestMetricsTableAggregate {
33
34 public static MetricsAssertHelper HELPER =
35 CompatibilityFactory.getInstance(MetricsAssertHelper.class);
36
37 private String tableName = "testTableMetrics";
38 private String pre = "Namespace_default_table_" + tableName + "_metric_";
39
40 private MetricsTableWrapperStub tableWrapper;
41 private MetricsTable mt;
42 private MetricsRegionServerWrapper rsWrapper;
43 private MetricsRegionServer rsm;
44 private MetricsTableAggregateSource agg;
45
46 @BeforeClass
47 public static void classSetUp() {
48 HELPER.init();
49 }
50
51 @Before
52 public void setUp() {
53 tableWrapper = new MetricsTableWrapperStub(tableName);
54 mt = new MetricsTable(tableWrapper);
55 rsWrapper = new MetricsRegionServerWrapperStub();
56 rsm = new MetricsRegionServer(HBaseConfiguration.create(), rsWrapper, mt);
57 agg = mt.getTableSourceAgg();
58 }
59
60 @Test
61 public void testRequestMetrics() throws IOException {
62 HELPER.assertCounter(pre + "readRequestCount", 10, agg);
63 HELPER.assertCounter(pre + "writeRequestCount", 20, agg);
64 HELPER.assertCounter(pre + "totalRequestCount", 30, agg);
65 }
66
67 @Test
68 public void testRegionAndStoreMetrics() throws IOException {
69 HELPER.assertGauge(pre + "memstoreSize", 1000, agg);
70 HELPER.assertGauge(pre + "storeFileSize", 2000, agg);
71 HELPER.assertGauge(pre + "tableSize", 3000, agg);
72
73 HELPER.assertGauge(pre + "regionCount", 11, agg);
74 HELPER.assertGauge(pre + "storeCount", 22, agg);
75 HELPER.assertGauge(pre + "storeFileCount", 33, agg);
76 HELPER.assertGauge(pre + "maxStoreFileAge", 44, agg);
77 HELPER.assertGauge(pre + "minStoreFileAge", 55, agg);
78 HELPER.assertGauge(pre + "avgStoreFileAge", 66, agg);
79 HELPER.assertGauge(pre + "numReferenceFiles", 77, agg);
80 HELPER.assertGauge(pre + "averageRegionSize", 88, agg);
81 }
82
83 @Test
84 public void testFlush() {
85 rsm.updateFlush(tableName, 1, 2, 3);
86 HELPER.assertCounter(pre + "flushTime_num_ops", 1, agg);
87 HELPER.assertCounter(pre + "flushMemstoreSize_num_ops", 1, agg);
88 HELPER.assertCounter(pre + "flushOutputSize_num_ops", 1, agg);
89 HELPER.assertCounter(pre + "flushedMemstoreBytes", 2, agg);
90 HELPER.assertCounter(pre + "flushedOutputBytes", 3, agg);
91
92 rsm.updateFlush(tableName, 10, 20, 30);
93 HELPER.assertCounter(pre + "flushTime_num_ops", 2, agg);
94 HELPER.assertCounter(pre + "flushMemstoreSize_num_ops", 2, agg);
95 HELPER.assertCounter(pre + "flushOutputSize_num_ops", 2, agg);
96 HELPER.assertCounter(pre + "flushedMemstoreBytes", 22, agg);
97 HELPER.assertCounter(pre + "flushedOutputBytes", 33, agg);
98 }
99
100 @Test
101 public void testCompaction() {
102 rsm.updateCompaction(tableName, false, 1, 2, 3, 4, 5);
103 HELPER.assertCounter(pre + "compactionTime_num_ops", 1, agg);
104 HELPER.assertCounter(pre + "compactionInputFileCount_num_ops", 1, agg);
105 HELPER.assertCounter(pre + "compactionInputSize_num_ops", 1, agg);
106 HELPER.assertCounter(pre + "compactionOutputFileCount_num_ops", 1, agg);
107 HELPER.assertCounter(pre + "compactedInputBytes", 4, agg);
108 HELPER.assertCounter(pre + "compactedoutputBytes", 5, agg);
109
110 rsm.updateCompaction(tableName, false, 10, 20, 30, 40, 50);
111 HELPER.assertCounter(pre + "compactionTime_num_ops", 2, agg);
112 HELPER.assertCounter(pre + "compactionInputFileCount_num_ops", 2, agg);
113 HELPER.assertCounter(pre + "compactionInputSize_num_ops", 2, agg);
114 HELPER.assertCounter(pre + "compactionOutputFileCount_num_ops", 2, agg);
115 HELPER.assertCounter(pre + "compactedInputBytes", 44, agg);
116 HELPER.assertCounter(pre + "compactedoutputBytes", 55, agg);
117
118
119 rsm.updateCompaction(tableName, true, 100, 200, 300, 400, 500);
120
121 HELPER.assertCounter(pre + "compactionTime_num_ops", 3, agg);
122 HELPER.assertCounter(pre + "compactionInputFileCount_num_ops", 3, agg);
123 HELPER.assertCounter(pre + "compactionInputSize_num_ops", 3, agg);
124 HELPER.assertCounter(pre + "compactionOutputFileCount_num_ops", 3, agg);
125 HELPER.assertCounter(pre + "compactedInputBytes", 444, agg);
126 HELPER.assertCounter(pre + "compactedoutputBytes", 555, agg);
127
128 HELPER.assertCounter(pre + "majorCompactionTime_num_ops", 1, agg);
129 HELPER.assertCounter(pre + "majorCompactionInputFileCount_num_ops", 1, agg);
130 HELPER.assertCounter(pre + "majorCompactionInputSize_num_ops", 1, agg);
131 HELPER.assertCounter(pre + "majorCompactionOutputFileCount_num_ops", 1, agg);
132 HELPER.assertCounter(pre + "majorCompactedInputBytes", 400, agg);
133 HELPER.assertCounter(pre + "majorCompactedoutputBytes", 500, agg);
134 }
135 }