1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase;
20
21 import static org.junit.Assert.assertTrue;
22
23 import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread;
24 import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.experimental.categories.Category;
29
30
31
32
33 @Category(MediumTests.class)
34 public class TestClusterBootOrder {
35
36 private static final long SLEEP_INTERVAL = 1000;
37 private static final long SLEEP_TIME = 4000;
38
39 private HBaseTestingUtility testUtil;
40 private LocalHBaseCluster cluster;
41 private RegionServerThread rs;
42 private MasterThread master;
43
44 @Before
45 public void setUp() throws Exception {
46 testUtil = new HBaseTestingUtility();
47 testUtil.startMiniDFSCluster(1);
48 testUtil.startMiniZKCluster(1);
49 testUtil.createRootDir();
50 cluster = new LocalHBaseCluster(testUtil.getConfiguration(), 0, 0);
51 }
52
53 @After
54 public void tearDown() throws Exception {
55 cluster.shutdown();
56 cluster.join();
57 testUtil.shutdownMiniZKCluster();
58 testUtil.shutdownMiniDFSCluster();
59 }
60
61 private void startRegionServer() throws Exception {
62 rs = cluster.addRegionServer();
63 rs.start();
64
65 for (int i=0; i * SLEEP_INTERVAL < SLEEP_TIME ;i++) {
66
67 Thread.sleep(SLEEP_INTERVAL);
68 assertTrue(rs.isAlive());
69 }
70 }
71
72 private void startMaster() throws Exception {
73 master = cluster.addMaster();
74 master.start();
75
76 for (int i=0; i * SLEEP_INTERVAL < SLEEP_TIME ;i++) {
77 Thread.sleep(SLEEP_INTERVAL);
78 assertTrue(master.isAlive());
79 }
80 }
81
82 private void waitForClusterOnline() {
83 while (true) {
84 if (master.getMaster().isInitialized()) {
85 break;
86 }
87 try {
88 Thread.sleep(100);
89 } catch (InterruptedException ignored) {
90
91 }
92 }
93 rs.waitForServerOnline();
94 }
95
96
97
98
99
100 @Test
101 public void testBootRegionServerFirst() throws Exception {
102 startRegionServer();
103 startMaster();
104 waitForClusterOnline();
105 }
106
107
108
109
110
111 @Test
112 public void testBootMasterFirst() throws Exception {
113 startMaster();
114 startRegionServer();
115 waitForClusterOnline();
116 }
117
118 }