1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.master;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25
26 import java.util.List;
27
28 import org.apache.hadoop.hbase.*;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.hadoop.conf.Configuration;
32 import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35
36 @Category(LargeTests.class)
37 public class TestMasterShutdown {
38 private static final Log LOG = LogFactory.getLog(TestMasterShutdown.class);
39
40
41
42
43
44
45
46
47 @Test (timeout=240000)
48 public void testMasterShutdown() throws Exception {
49
50 final int NUM_MASTERS = 3;
51 final int NUM_RS = 3;
52
53
54 Configuration conf = HBaseConfiguration.create();
55
56
57 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf);
58 TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
59 MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
60
61
62 List<MasterThread> masterThreads = cluster.getMasterThreads();
63
64
65 for (MasterThread mt : masterThreads) {
66 assertTrue(mt.isAlive());
67 }
68
69
70 HMaster active = null;
71 for (int i = 0; i < masterThreads.size(); i++) {
72 if (masterThreads.get(i).getMaster().isActiveMaster()) {
73 active = masterThreads.get(i).getMaster();
74 break;
75 }
76 }
77 assertNotNull(active);
78
79 ClusterStatus status = active.getClusterStatus();
80 assertEquals(2, status.getBackupMastersSize());
81 assertEquals(2, status.getBackupMasters().size());
82
83
84 active.shutdown();
85
86 for (int i = NUM_MASTERS - 1; i >= 0 ;--i) {
87 cluster.waitOnMaster(i);
88 }
89
90 assertEquals(0,masterThreads.size());
91
92 TEST_UTIL.shutdownMiniCluster();
93 }
94
95 @org.junit.Rule
96 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
97 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
98 }
99