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.replication; 019 020import java.io.IOException; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.fs.FileSystem; 023import org.apache.hadoop.hbase.ClusterId; 024import org.apache.hadoop.hbase.HBaseZKTestingUtil; 025import org.apache.hadoop.hbase.HConstants; 026import org.apache.hadoop.hbase.testclassification.MediumTests; 027import org.apache.hadoop.hbase.testclassification.ReplicationTests; 028import org.apache.hadoop.hbase.zookeeper.ZKClusterId; 029import org.apache.hadoop.hbase.zookeeper.ZKConfig; 030import org.apache.hadoop.hbase.zookeeper.ZKUtil; 031import org.apache.hadoop.hbase.zookeeper.ZKWatcher; 032import org.apache.hadoop.hbase.zookeeper.ZNodePaths; 033import org.apache.zookeeper.KeeperException; 034import org.junit.jupiter.api.AfterAll; 035import org.junit.jupiter.api.AfterEach; 036import org.junit.jupiter.api.BeforeAll; 037import org.junit.jupiter.api.BeforeEach; 038import org.junit.jupiter.api.Tag; 039 040@Tag(ReplicationTests.TAG) 041@Tag(MediumTests.TAG) 042public class TestReplicationStateZKImpl extends TestReplicationStateBasic { 043 044 private static Configuration conf; 045 private static HBaseZKTestingUtil utility; 046 private static ZKWatcher zkw; 047 private static String replicationZNode; 048 049 @BeforeAll 050 public static void setUpBeforeClass() throws Exception { 051 utility = new HBaseZKTestingUtil(); 052 utility.startMiniZKCluster(); 053 conf = utility.getConfiguration(); 054 conf.setBoolean(HConstants.REPLICATION_BULKLOAD_ENABLE_KEY, true); 055 zkw = utility.getZooKeeperWatcher(); 056 String replicationZNodeName = conf.get("zookeeper.znode.replication", "replication"); 057 replicationZNode = ZNodePaths.joinZNode(zkw.getZNodePaths().baseZNode, replicationZNodeName); 058 KEY_ONE = initPeerClusterState("/hbase1"); 059 KEY_TWO = initPeerClusterState("/hbase2"); 060 } 061 062 private static String initPeerClusterState(String baseZKNode) 063 throws IOException, KeeperException { 064 // Add a dummy region server and set up the cluster id 065 Configuration testConf = new Configuration(conf); 066 testConf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, baseZKNode); 067 ZKWatcher zkw1 = new ZKWatcher(testConf, "test1", null); 068 String fakeRs = 069 ZNodePaths.joinZNode(zkw1.getZNodePaths().rsZNode, "hostname1.example.org:1234"); 070 ZKUtil.createWithParents(zkw1, fakeRs); 071 ZKClusterId.setClusterId(zkw1, new ClusterId()); 072 return ZKConfig.getZooKeeperClusterKey(testConf); 073 } 074 075 @BeforeEach 076 public void setUp() throws IOException { 077 zkTimeoutCount = 0; 078 rp = 079 ReplicationFactory.getReplicationPeers(FileSystem.get(utility.getConfiguration()), zkw, conf); 080 OUR_KEY = ZKConfig.getZooKeeperClusterKey(conf); 081 } 082 083 @AfterEach 084 public void tearDown() throws KeeperException, IOException { 085 ZKUtil.deleteNodeRecursively(zkw, replicationZNode); 086 } 087 088 @AfterAll 089 public static void tearDownAfterClass() throws Exception { 090 utility.shutdownMiniZKCluster(); 091 } 092}