HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / TestClusterBootOrder.java
blob2d16a90ef1fff87a0fc267653e75ab4515560998
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase;
20 import static org.junit.Assert.assertTrue;
22 import org.apache.hadoop.hbase.testclassification.MediumTests;
23 import org.apache.hadoop.hbase.testclassification.MiscTests;
24 import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread;
25 import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.ClassRule;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
32 /**
33 * Tests the boot order indifference between regionserver and master
35 @Category({MiscTests.class, MediumTests.class})
36 public class TestClusterBootOrder {
38 @ClassRule
39 public static final HBaseClassTestRule CLASS_RULE =
40 HBaseClassTestRule.forClass(TestClusterBootOrder.class);
42 private static final long SLEEP_INTERVAL = 1000;
43 private static final long SLEEP_TIME = 4000;
45 private HBaseTestingUtility testUtil;
46 private LocalHBaseCluster cluster;
47 private RegionServerThread rs;
48 private MasterThread master;
50 @Before
51 public void setUp() throws Exception {
52 testUtil = new HBaseTestingUtility();
53 testUtil.startMiniDFSCluster(1);
54 testUtil.startMiniZKCluster(1);
55 testUtil.createRootDir(); //manually setup hbase dir to point to minidfscluster
56 cluster = new LocalHBaseCluster(testUtil.getConfiguration(), 0, 0);
59 @After
60 public void tearDown() throws Exception {
61 cluster.shutdown();
62 cluster.join();
63 testUtil.shutdownMiniZKCluster();
64 testUtil.shutdownMiniDFSCluster();
67 private void startRegionServer() throws Exception {
68 rs = cluster.addRegionServer();
69 rs.start();
71 for (int i=0; i * SLEEP_INTERVAL < SLEEP_TIME ;i++) {
72 //we cannot block on wait for rs at this point , since master is not up.
73 Thread.sleep(SLEEP_INTERVAL);
74 assertTrue(rs.isAlive());
78 private void startMaster() throws Exception {
79 master = cluster.addMaster();
80 master.start();
82 for (int i=0; i * SLEEP_INTERVAL < SLEEP_TIME ;i++) {
83 Thread.sleep(SLEEP_INTERVAL);
84 assertTrue(master.isAlive());
88 private void waitForClusterOnline() {
89 while (true) {
90 if (master.getMaster().isInitialized()) {
91 break;
93 try {
94 Thread.sleep(100);
95 } catch (InterruptedException ignored) {
96 // Keep waiting
99 rs.waitForServerOnline();
103 * Tests launching the cluster by first starting regionserver, and then the master
104 * to ensure that it does not matter which is started first.
106 @Test
107 public void testBootRegionServerFirst() throws Exception {
108 startRegionServer();
109 startMaster();
110 waitForClusterOnline();
114 * Tests launching the cluster by first starting master, and then the regionserver
115 * to ensure that it does not matter which is started first.
117 @Test
118 public void testBootMasterFirst() throws Exception {
119 startMaster();
120 startRegionServer();
121 waitForClusterOnline();