HBASE-22002 Remove the deprecated methods in Admin interface
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestZKAsyncRegistry.java
blob46890d0963fc701eb7ad4db420fa58066988df8e
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.apache.hadoop.hbase.HConstants.META_REPLICAS_NUM;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertNotSame;
26 import java.io.IOException;
27 import java.util.concurrent.ExecutionException;
28 import java.util.stream.IntStream;
29 import org.apache.commons.io.IOUtils;
30 import org.apache.hadoop.conf.Configuration;
31 import org.apache.hadoop.hbase.HBaseClassTestRule;
32 import org.apache.hadoop.hbase.HBaseTestingUtility;
33 import org.apache.hadoop.hbase.HConstants;
34 import org.apache.hadoop.hbase.HRegionLocation;
35 import org.apache.hadoop.hbase.RegionLocations;
36 import org.apache.hadoop.hbase.TableName;
37 import org.apache.hadoop.hbase.testclassification.ClientTests;
38 import org.apache.hadoop.hbase.testclassification.MediumTests;
39 import org.apache.hadoop.hbase.zookeeper.ReadOnlyZKClient;
40 import org.junit.AfterClass;
41 import org.junit.BeforeClass;
42 import org.junit.ClassRule;
43 import org.junit.Test;
44 import org.junit.experimental.categories.Category;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
48 @Category({ MediumTests.class, ClientTests.class })
49 public class TestZKAsyncRegistry {
51 @ClassRule
52 public static final HBaseClassTestRule CLASS_RULE =
53 HBaseClassTestRule.forClass(TestZKAsyncRegistry.class);
55 static final Logger LOG = LoggerFactory.getLogger(TestZKAsyncRegistry.class);
56 static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
58 private static ZKAsyncRegistry REGISTRY;
60 @BeforeClass
61 public static void setUp() throws Exception {
62 TEST_UTIL.getConfiguration().setInt(META_REPLICAS_NUM, 3);
63 TEST_UTIL.startMiniCluster(3);
64 REGISTRY = new ZKAsyncRegistry(TEST_UTIL.getConfiguration());
67 @AfterClass
68 public static void tearDown() throws Exception {
69 IOUtils.closeQuietly(REGISTRY);
70 TEST_UTIL.shutdownMiniCluster();
73 @Test
74 public void test() throws InterruptedException, ExecutionException, IOException {
75 LOG.info("STARTED TEST");
76 String clusterId = REGISTRY.getClusterId().get();
77 String expectedClusterId = TEST_UTIL.getHBaseCluster().getMaster().getClusterId();
78 assertEquals("Expected " + expectedClusterId + ", found=" + clusterId, expectedClusterId,
79 clusterId);
80 assertEquals(TEST_UTIL.getHBaseCluster().getClusterMetrics().getLiveServerMetrics().size(),
81 REGISTRY.getCurrentNrHRS().get().intValue());
82 assertEquals(TEST_UTIL.getHBaseCluster().getMaster().getServerName(),
83 REGISTRY.getMasterAddress().get());
84 assertEquals(-1, REGISTRY.getMasterInfoPort().get().intValue());
85 RegionReplicaTestHelper.waitUntilAllMetaReplicasHavingRegionLocation(REGISTRY, 3);
86 RegionLocations locs = REGISTRY.getMetaRegionLocation().get();
87 assertEquals(3, locs.getRegionLocations().length);
88 IntStream.range(0, 3).forEach(i -> {
89 HRegionLocation loc = locs.getRegionLocation(i);
90 assertNotNull("Replica " + i + " doesn't have location", loc);
91 assertEquals(TableName.META_TABLE_NAME, loc.getRegion().getTable());
92 assertEquals(i, loc.getRegion().getReplicaId());
93 });
96 @Test
97 public void testIndependentZKConnections() throws IOException {
98 try (ReadOnlyZKClient zk1 = REGISTRY.getZKClient()) {
99 Configuration otherConf = new Configuration(TEST_UTIL.getConfiguration());
100 otherConf.set(HConstants.ZOOKEEPER_QUORUM, "127.0.0.1");
101 try (ZKAsyncRegistry otherRegistry = new ZKAsyncRegistry(otherConf)) {
102 ReadOnlyZKClient zk2 = otherRegistry.getZKClient();
103 assertNotSame("Using a different configuration / quorum should result in different " +
104 "backing zk connection.", zk1, zk2);
105 assertNotEquals(
106 "Using a different configrution / quorum should be reflected in the zk connection.",
107 zk1.getConnectString(), zk2.getConnectString());
109 } finally {
110 LOG.info("DONE!");