HBASE-26481 Consider rolling upgrading from old region replication framework (#3880)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestShutdownOfMetaReplicaHolder.java
blob11e5404ec5d8771c778f32031bf4bab018eb2593
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.client;
20 import org.apache.hadoop.hbase.HBaseClassTestRule;
21 import org.apache.hadoop.hbase.HConstants;
22 import org.apache.hadoop.hbase.HRegionLocation;
23 import org.apache.hadoop.hbase.ServerName;
24 import org.apache.hadoop.hbase.TableName;
25 import org.apache.hadoop.hbase.testclassification.MediumTests;
26 import org.apache.hadoop.hbase.testclassification.MiscTests;
27 import org.junit.BeforeClass;
28 import org.junit.ClassRule;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 @Category({ MiscTests.class, MediumTests.class })
35 public class TestShutdownOfMetaReplicaHolder extends MetaWithReplicasTestBase {
37 @ClassRule
38 public static final HBaseClassTestRule CLASS_RULE =
39 HBaseClassTestRule.forClass(TestShutdownOfMetaReplicaHolder.class);
41 private static final Logger LOG = LoggerFactory.getLogger(TestShutdownOfMetaReplicaHolder.class);
43 @BeforeClass
44 public static void setUp() throws Exception {
45 startCluster();
48 @Test
49 public void testShutdownOfReplicaHolder() throws Exception {
50 // checks that the when the server holding meta replica is shut down, the meta replica
51 // can be recovered
52 try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
53 RegionLocator locator = conn.getRegionLocator(TableName.META_TABLE_NAME)) {
54 HRegionLocation hrl = locator.getRegionLocations(HConstants.EMPTY_START_ROW, true).get(1);
55 ServerName oldServer = hrl.getServerName();
56 TEST_UTIL.getHBaseClusterInterface().killRegionServer(oldServer);
57 LOG.debug("Waiting for the replica {} to come up", hrl.getRegion());
58 TEST_UTIL.waitFor(30000, () -> {
59 HRegionLocation loc = locator.getRegionLocations(HConstants.EMPTY_START_ROW, true).get(1);
60 return loc != null && !loc.getServerName().equals(oldServer);
61 });
62 LOG.debug("Replica {} is online on {}, old server is {}", hrl.getRegion(),
63 locator.getRegionLocations(HConstants.EMPTY_START_ROW, true).get(1).getServerName(),
64 oldServer);