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
;
33 * Tests the boot order indifference between regionserver and master
35 @Category({MiscTests
.class, MediumTests
.class})
36 public class TestClusterBootOrder
{
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
;
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);
60 public void tearDown() throws Exception
{
63 testUtil
.shutdownMiniZKCluster();
64 testUtil
.shutdownMiniDFSCluster();
67 private void startRegionServer() throws Exception
{
68 rs
= cluster
.addRegionServer();
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();
82 for (int i
=0; i
* SLEEP_INTERVAL
< SLEEP_TIME
;i
++) {
83 Thread
.sleep(SLEEP_INTERVAL
);
84 assertTrue(master
.isAlive());
88 private void waitForClusterOnline() {
90 if (master
.getMaster().isInitialized()) {
95 } catch (InterruptedException ignored
) {
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.
107 public void testBootRegionServerFirst() throws Exception
{
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.
118 public void testBootMasterFirst() throws Exception
{
121 waitForClusterOnline();