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.assertTrue;
21 import static org.junit.Assert.fail;
22
23 import org.apache.hadoop.hbase.HBaseTestingUtility;
24 import org.apache.hadoop.hbase.HRegionInfo;
25 import org.apache.hadoop.hbase.ServerName;
26 import org.apache.hadoop.hbase.client.ClusterConnection;
27 import org.apache.hadoop.hbase.client.ConnectionFactory;
28 import org.apache.hadoop.hbase.testclassification.LargeTests;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.junit.experimental.categories.Category;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 @Category({ LargeTests.class })
36 public class TestMetaAssignmentWithStopMaster {
37
38 private static final Logger LOG =
39 LoggerFactory.getLogger(TestMetaAssignmentWithStopMaster.class);
40
41 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
42
43 private static final long WAIT_TIMEOUT = 120000;
44
45 @BeforeClass
46 public static void setUp() throws Exception {
47 UTIL.startMiniCluster(2,3);
48 }
49
50 @Test
51 public void testStopActiveMaster() throws Exception {
52 ClusterConnection conn =
53 (ClusterConnection) ConnectionFactory.createConnection(UTIL.getConfiguration());
54 ServerName oldMetaServer = conn.locateRegion(HRegionInfo.FIRST_META_REGIONINFO
55 .getRegionName()).getServerName();
56 ServerName oldMaster = UTIL.getMiniHBaseCluster().getMaster().getServerName();
57
58 UTIL.getMiniHBaseCluster().getMaster().stop("Stop master for test");
59 long startTime = System.currentTimeMillis();
60 while (UTIL.getMiniHBaseCluster().getMaster() == null || UTIL.getMiniHBaseCluster().getMaster()
61 .getServerName().equals(oldMaster)) {
62 LOG.info("Wait the standby master become active");
63 Thread.sleep(3000);
64 if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) {
65 fail("Wait too long for standby master become active");
66 }
67 }
68 startTime = System.currentTimeMillis();
69 while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) {
70 LOG.info("Wait the new active master to be initialized");
71 Thread.sleep(3000);
72 if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) {
73 fail("Wait too long for the new active master to be initialized");
74 }
75 }
76
77 ServerName newMetaServer = conn.locateRegion(HRegionInfo.FIRST_META_REGIONINFO
78 .getRegionName()).getServerName();
79 assertTrue("The new meta server " + newMetaServer + " should be same with" +
80 " the old meta server " + oldMetaServer, newMetaServer.equals(oldMetaServer));
81 }
82 }