HBASE-26481 Consider rolling upgrading from old region replication framework (#3880)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestMetaWithReplicasBasic.java
blob8ffbe6bb47fdac0bfb0a83e92021aa9d151c6964
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.assertEquals;
21 import static org.junit.Assert.assertThrows;
22 import static org.junit.Assert.assertTrue;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseClassTestRule;
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.TableName;
28 import org.apache.hadoop.hbase.TableNotFoundException;
29 import org.apache.hadoop.hbase.testclassification.MediumTests;
30 import org.apache.hadoop.hbase.testclassification.MiscTests;
31 import org.apache.hadoop.hbase.util.Bytes;
32 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
33 import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
34 import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
35 import org.junit.BeforeClass;
36 import org.junit.ClassRule;
37 import org.junit.Test;
38 import org.junit.experimental.categories.Category;
40 import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
42 @Category({ MiscTests.class, MediumTests.class })
43 public class TestMetaWithReplicasBasic extends MetaWithReplicasTestBase {
45 @ClassRule
46 public static final HBaseClassTestRule CLASS_RULE =
47 HBaseClassTestRule.forClass(TestMetaWithReplicasBasic.class);
49 @BeforeClass
50 public static void setUp() throws Exception {
51 startCluster();
54 @Test
55 public void testMetaHTDReplicaCount() throws Exception {
56 assertEquals(3,
57 TEST_UTIL.getAdmin().getDescriptor(TableName.META_TABLE_NAME).getRegionReplication());
60 @Test
61 public void testZookeeperNodesForReplicas() throws Exception {
62 // Checks all the znodes exist when meta's replicas are enabled
63 ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
64 Configuration conf = TEST_UTIL.getConfiguration();
65 String baseZNode =
66 conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
67 String primaryMetaZnode =
68 ZNodePaths.joinZNode(baseZNode, conf.get("zookeeper.znode.metaserver", "meta-region-server"));
69 // check that the data in the znode is parseable (this would also mean the znode exists)
70 byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
71 ProtobufUtil.toServerName(data);
72 for (int i = 1; i < 3; i++) {
73 String secZnode = ZNodePaths.joinZNode(baseZNode,
74 conf.get("zookeeper.znode.metaserver", "meta-region-server") + "-" + i);
75 String str = zkw.getZNodePaths().getZNodeForReplica(i);
76 assertTrue(str.equals(secZnode));
77 // check that the data in the znode is parseable (this would also mean the znode exists)
78 data = ZKUtil.getData(zkw, secZnode);
79 ProtobufUtil.toServerName(data);
83 @Test
84 public void testAccessingUnknownTables() throws Exception {
85 Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
86 conf.setBoolean(HConstants.USE_META_REPLICAS, true);
87 Table table = TEST_UTIL.getConnection().getTable(name.getTableName());
88 Get get = new Get(Bytes.toBytes("foo"));
89 assertThrows(TableNotFoundException.class, () -> table.get(get));