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.*;
21
22 import java.util.AbstractMap.SimpleImmutableEntry;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.hbase.HBaseTestingUtility;
27 import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot;
28 import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus;
29 import org.apache.hadoop.hbase.quotas.SpaceViolationPolicy;
30 import org.apache.hadoop.hbase.testclassification.MediumTests;
31 import org.apache.hadoop.hbase.util.Threads;
32 import org.junit.AfterClass;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
36
37 @Category(MediumTests.class)
38 public class TestMasterMetricsWrapper {
39 private static final Log LOG = LogFactory.getLog(TestMasterMetricsWrapper.class);
40
41 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
42
43 @BeforeClass
44 public static void setup() throws Exception {
45 TEST_UTIL.startMiniCluster(1, 4);
46 }
47
48 @AfterClass
49 public static void teardown() throws Exception {
50 TEST_UTIL.shutdownMiniCluster();
51 }
52
53 @Test (timeout = 30000)
54 public void testInfo() {
55 HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
56 MetricsMasterWrapperImpl info = new MetricsMasterWrapperImpl(master);
57 assertEquals(master.getAverageLoad(), info.getAverageLoad(), 0);
58 assertEquals(master.getClusterId(), info.getClusterId());
59 assertEquals(master.getMasterActiveTime(), info.getActiveTime());
60 assertEquals(master.getMasterStartTime(), info.getStartTime());
61 assertEquals(master.getMasterCoprocessors().length, info.getCoprocessors().length);
62 assertEquals(master.getServerManager().getOnlineServersList().size(), info.getNumRegionServers());
63 assertEquals(4, info.getNumRegionServers());
64
65 String zkServers = info.getZookeeperQuorum();
66 assertEquals(zkServers.split(",").length, TEST_UTIL.getZkCluster().getZooKeeperServerNum());
67
68 final int index = 3;
69 LOG.info("Stopping " + TEST_UTIL.getMiniHBaseCluster().getRegionServer(index));
70 TEST_UTIL.getMiniHBaseCluster().stopRegionServer(index, false);
71 TEST_UTIL.getMiniHBaseCluster().waitOnRegionServer(index);
72
73
74 while (TEST_UTIL.getHBaseCluster().getMaster().getServerManager().getOnlineServers().size() !=
75 3) {
76 Threads.sleep(10);
77 }
78 assertEquals(3, info.getNumRegionServers());
79 assertEquals(1, info.getNumDeadRegionServers());
80 assertEquals(1, info.getNumWALFiles());
81 }
82
83 @Test
84 public void testQuotaSnapshotConversion() {
85 MetricsMasterWrapperImpl info = new MetricsMasterWrapperImpl(
86 TEST_UTIL.getHBaseCluster().getMaster());
87 assertEquals(new SimpleImmutableEntry<Long,Long>(1024L, 2048L),
88 info.convertSnapshot(new SpaceQuotaSnapshot(
89 SpaceQuotaStatus.notInViolation(), 1024L, 2048L)));
90 assertEquals(new SimpleImmutableEntry<Long,Long>(4096L, 2048L),
91 info.convertSnapshot(new SpaceQuotaSnapshot(
92 new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 4096L, 2048L)));
93 }
94 }