HBASE-26481 Consider rolling upgrading from old region replication framework (#3880)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestMetaReplicasAddressChange.java
blobfe105848c865738e1767330c9b39b1e6628c7761
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 static org.junit.Assert.assertNotEquals;
21 import static org.junit.Assert.assertTrue;
23 import java.util.Collection;
24 import java.util.EnumSet;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.ClusterMetrics.Option;
27 import org.apache.hadoop.hbase.HBaseClassTestRule;
28 import org.apache.hadoop.hbase.HConstants;
29 import org.apache.hadoop.hbase.ServerName;
30 import org.apache.hadoop.hbase.TableName;
31 import org.apache.hadoop.hbase.testclassification.MediumTests;
32 import org.apache.hadoop.hbase.testclassification.MiscTests;
33 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
34 import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
35 import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
36 import org.junit.BeforeClass;
37 import org.junit.ClassRule;
38 import org.junit.Test;
39 import org.junit.experimental.categories.Category;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
43 import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
45 @Category({ MiscTests.class, MediumTests.class })
46 public class TestMetaReplicasAddressChange extends MetaWithReplicasTestBase {
48 @ClassRule
49 public static final HBaseClassTestRule CLASS_RULE =
50 HBaseClassTestRule.forClass(TestMetaReplicasAddressChange.class);
52 private static final Logger LOG = LoggerFactory.getLogger(TestMetaReplicasAddressChange.class);
54 @BeforeClass
55 public static void setUp() throws Exception {
56 startCluster();
59 @Test
60 public void testMetaAddressChange() throws Exception {
61 // checks that even when the meta's location changes, the various
62 // caches update themselves. Uses the master operations to test
63 // this
64 Configuration conf = TEST_UTIL.getConfiguration();
65 ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
66 String baseZNode =
67 conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
68 String primaryMetaZnode =
69 ZNodePaths.joinZNode(baseZNode, conf.get("zookeeper.znode.metaserver", "meta-region-server"));
70 // check that the data in the znode is parseable (this would also mean the znode exists)
71 byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
72 ServerName currentServer = ProtobufUtil.toServerName(data);
73 Collection<ServerName> liveServers = TEST_UTIL.getAdmin()
74 .getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet();
75 ServerName moveToServer =
76 liveServers.stream().filter(s -> !currentServer.equals(s)).findAny().get();
77 final TableName tableName = name.getTableName();
78 TEST_UTIL.createTable(tableName, "f");
79 assertTrue(TEST_UTIL.getAdmin().tableExists(tableName));
80 TEST_UTIL.getAdmin().move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(),
81 moveToServer);
82 assertNotEquals(currentServer, moveToServer);
83 LOG.debug("CurrentServer={}, moveToServer={}", currentServer, moveToServer);
84 TEST_UTIL.waitFor(60000, () -> {
85 byte[] bytes = ZKUtil.getData(zkw, primaryMetaZnode);
86 ServerName actualServer = ProtobufUtil.toServerName(bytes);
87 return moveToServer.equals(actualServer);
88 });
89 TEST_UTIL.getAdmin().disableTable(tableName);
90 assertTrue(TEST_UTIL.getAdmin().isTableDisabled(tableName));