001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.client;
019
020import org.apache.hadoop.hbase.HConstants;
021import org.apache.hadoop.hbase.HRegionLocation;
022import org.apache.hadoop.hbase.ServerName;
023import org.apache.hadoop.hbase.TableName;
024import org.apache.hadoop.hbase.testclassification.MediumTests;
025import org.apache.hadoop.hbase.testclassification.MiscTests;
026import org.junit.jupiter.api.BeforeAll;
027import org.junit.jupiter.api.Tag;
028import org.junit.jupiter.api.Test;
029import org.slf4j.Logger;
030import org.slf4j.LoggerFactory;
031
032@Tag(MiscTests.TAG)
033@Tag(MediumTests.TAG)
034public class TestShutdownOfMetaReplicaHolder extends MetaWithReplicasTestBase {
035
036  private static final Logger LOG = LoggerFactory.getLogger(TestShutdownOfMetaReplicaHolder.class);
037
038  @BeforeAll
039  public static void setUp() throws Exception {
040    startCluster();
041  }
042
043  @Test
044  public void testShutdownOfReplicaHolder() throws Exception {
045    // checks that the when the server holding meta replica is shut down, the meta replica
046    // can be recovered
047    try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
048      RegionLocator locator = conn.getRegionLocator(TableName.META_TABLE_NAME)) {
049      HRegionLocation hrl = locator.getRegionLocations(HConstants.EMPTY_START_ROW, true).get(1);
050      ServerName oldServer = hrl.getServerName();
051      TEST_UTIL.getHBaseClusterInterface().killRegionServer(oldServer);
052      LOG.debug("Waiting for the replica {} to come up", hrl.getRegion());
053      TEST_UTIL.waitFor(30000, () -> {
054        HRegionLocation loc = locator.getRegionLocations(HConstants.EMPTY_START_ROW, true).get(1);
055        return loc != null && !loc.getServerName().equals(oldServer);
056      });
057      LOG.debug("Replica {} is online on {}, old server is {}", hrl.getRegion(),
058        locator.getRegionLocations(HConstants.EMPTY_START_ROW, true).get(1).getServerName(),
059        oldServer);
060    }
061  }
062}