HBASE-26416 Implement a new method for region replication instead of using replay...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / master / TestMetaAssignmentWithStopMaster.java
blob6ad4f0806055349fc3f20ba9bd0d8596131398d8
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.assertTrue;
21 import static org.junit.Assert.fail;
23 import org.apache.hadoop.hbase.HBaseClassTestRule;
24 import org.apache.hadoop.hbase.HBaseTestingUtil;
25 import org.apache.hadoop.hbase.ServerName;
26 import org.apache.hadoop.hbase.StartTestingClusterOption;
27 import org.apache.hadoop.hbase.TableName;
28 import org.apache.hadoop.hbase.client.Connection;
29 import org.apache.hadoop.hbase.client.ConnectionFactory;
30 import org.apache.hadoop.hbase.client.RegionLocator;
31 import org.apache.hadoop.hbase.testclassification.LargeTests;
32 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
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;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 @Category({ LargeTests.class })
42 public class TestMetaAssignmentWithStopMaster {
44 private static final Logger LOG =
45 LoggerFactory.getLogger(TestMetaAssignmentWithStopMaster.class);
47 @ClassRule
48 public static final HBaseClassTestRule CLASS_RULE =
49 HBaseClassTestRule.forClass(TestMetaAssignmentWithStopMaster.class);
51 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
53 private static final long WAIT_TIMEOUT = 120000;
55 @BeforeClass
56 public static void setUpBeforeClass() throws Exception {
57 StartTestingClusterOption option = StartTestingClusterOption.builder()
58 .numMasters(2).numRegionServers(3).numDataNodes(3).build();
59 UTIL.startMiniCluster(option);
62 @AfterClass
63 public static void tearDownAfterClass() throws Exception {
64 UTIL.shutdownMiniCluster();
67 @Test
68 public void testStopActiveMaster() throws Exception {
69 try (Connection conn = ConnectionFactory.createConnection(UTIL.getConfiguration());
70 RegionLocator locator = conn.getRegionLocator(TableName.META_TABLE_NAME)) {
71 ServerName oldMetaServer = locator.getAllRegionLocations().get(0).getServerName();
72 ServerName oldMaster = UTIL.getMiniHBaseCluster().getMaster().getServerName();
74 UTIL.getMiniHBaseCluster().getMaster().stop("Stop master for test");
75 long startTime = EnvironmentEdgeManager.currentTime();
76 while (UTIL.getMiniHBaseCluster().getMaster() == null ||
77 UTIL.getMiniHBaseCluster().getMaster().getServerName().equals(oldMaster)) {
78 LOG.info("Wait the standby master become active");
79 Thread.sleep(3000);
80 if (EnvironmentEdgeManager.currentTime() - startTime > WAIT_TIMEOUT) {
81 fail("Wait too long for standby master become active");
84 startTime = EnvironmentEdgeManager.currentTime();
85 while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) {
86 LOG.info("Wait the new active master to be initialized");
87 Thread.sleep(3000);
88 if (EnvironmentEdgeManager.currentTime() - startTime > WAIT_TIMEOUT) {
89 fail("Wait too long for the new active master to be initialized");
93 ServerName newMetaServer = locator.getAllRegionLocations().get(0).getServerName();
94 assertTrue("The new meta server " + newMetaServer + " should be same with" +
95 " the old meta server " + oldMetaServer, newMetaServer.equals(oldMetaServer));