HBASE-23949 refactor loadBalancer implements for rsgroup balance by table to achieve...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / master / TestShutdownBackupMaster.java
bloba42a4046d54f52fc28799df2de76040c422f0b4d
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.master;
20 import static org.junit.Assert.assertNotNull;
22 import java.io.IOException;
23 import java.util.concurrent.CountDownLatch;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseClassTestRule;
26 import org.apache.hadoop.hbase.HBaseTestingUtility;
27 import org.apache.hadoop.hbase.HConstants;
28 import org.apache.hadoop.hbase.MiniHBaseCluster;
29 import org.apache.hadoop.hbase.StartMiniClusterOption;
30 import org.apache.hadoop.hbase.testclassification.MasterTests;
31 import org.apache.hadoop.hbase.testclassification.MediumTests;
32 import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread;
33 import org.junit.AfterClass;
34 import org.junit.BeforeClass;
35 import org.junit.ClassRule;
36 import org.junit.Test;
37 import org.junit.experimental.categories.Category;
39 /**
40 * Test to confirm that we will not hang when stop a backup master which is trying to become the
41 * active master. See HBASE-19838
43 @Category({ MasterTests.class, MediumTests.class })
44 public class TestShutdownBackupMaster {
46 @ClassRule
47 public static final HBaseClassTestRule CLASS_RULE =
48 HBaseClassTestRule.forClass(TestShutdownBackupMaster.class);
50 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
52 private static volatile CountDownLatch ARRIVE;
54 private static volatile CountDownLatch CONTINUE;
56 public static final class MockHMaster extends HMaster {
58 public MockHMaster(Configuration conf) throws IOException {
59 super(conf);
62 @Override
63 protected void initClusterSchemaService() throws IOException, InterruptedException {
64 if (ARRIVE != null) {
65 ARRIVE.countDown();
66 CONTINUE.await();
68 super.initClusterSchemaService();
72 @BeforeClass
73 public static void setUpBeforeClass() throws Exception {
74 UTIL.getConfiguration().setClass(HConstants.MASTER_IMPL, MockHMaster.class, HMaster.class);
75 StartMiniClusterOption option = StartMiniClusterOption.builder()
76 .numMasters(2).numRegionServers(2).numDataNodes(2).build();
77 UTIL.startMiniCluster(option);
78 UTIL.waitUntilAllSystemRegionsAssigned();
81 @AfterClass
82 public static void tearDownAfterClass() throws Exception {
83 // make sure that we can stop the cluster cleanly
84 UTIL.shutdownMiniCluster();
87 @Test
88 public void testShutdownWhileBecomingActive() throws InterruptedException {
89 MiniHBaseCluster cluster = UTIL.getHBaseCluster();
90 HMaster activeMaster = null;
91 HMaster backupMaster = null;
92 for (MasterThread t : cluster.getMasterThreads()) {
93 if (t.getMaster().isActiveMaster()) {
94 activeMaster = t.getMaster();
95 } else {
96 backupMaster = t.getMaster();
99 assertNotNull(activeMaster);
100 assertNotNull(backupMaster);
101 ARRIVE = new CountDownLatch(1);
102 CONTINUE = new CountDownLatch(1);
103 activeMaster.abort("Aborting active master for test");
104 // wait until we arrive the initClusterSchemaService
105 ARRIVE.await();
106 // killall RSes
107 cluster.getRegionServerThreads().stream().map(t -> t.getRegionServer())
108 .forEachOrdered(rs -> rs.abort("Aborting RS for test"));
109 CONTINUE.countDown();