HBASE-26481 Consider rolling upgrading from old region replication framework (#3880)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestRpcConnectionRegistry.java
blob452d7fb892056a3d498b0b6a3c4b893c2121adba
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.hamcrest.CoreMatchers.hasItems;
21 import static org.hamcrest.MatcherAssert.assertThat;
22 import static org.junit.Assert.assertEquals;
24 import java.io.IOException;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.List;
28 import org.apache.hadoop.hbase.HBaseClassTestRule;
29 import org.apache.hadoop.hbase.HBaseTestingUtil;
30 import org.apache.hadoop.hbase.HRegionLocation;
31 import org.apache.hadoop.hbase.ServerName;
32 import org.apache.hadoop.hbase.TableName;
33 import org.apache.hadoop.hbase.master.HMaster;
34 import org.apache.hadoop.hbase.regionserver.BootstrapNodeManager;
35 import org.apache.hadoop.hbase.regionserver.RSRpcServices;
36 import org.apache.hadoop.hbase.testclassification.ClientTests;
37 import org.apache.hadoop.hbase.testclassification.MediumTests;
38 import org.junit.After;
39 import org.junit.AfterClass;
40 import org.junit.Before;
41 import org.junit.BeforeClass;
42 import org.junit.ClassRule;
43 import org.junit.Test;
44 import org.junit.experimental.categories.Category;
46 import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
48 @Category({ MediumTests.class, ClientTests.class })
49 public class TestRpcConnectionRegistry {
51 @ClassRule
52 public static final HBaseClassTestRule CLASS_RULE =
53 HBaseClassTestRule.forClass(TestRpcConnectionRegistry.class);
55 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
57 private RpcConnectionRegistry registry;
59 @BeforeClass
60 public static void setUpBeforeClass() throws Exception {
61 // allow refresh immediately so we will switch to use region servers soon.
62 UTIL.getConfiguration().setLong(RpcConnectionRegistry.INITIAL_REFRESH_DELAY_SECS, 1);
63 UTIL.getConfiguration().setLong(RpcConnectionRegistry.PERIODIC_REFRESH_INTERVAL_SECS, 1);
64 UTIL.getConfiguration().setLong(RpcConnectionRegistry.MIN_SECS_BETWEEN_REFRESHES, 0);
65 UTIL.getConfiguration().setLong(BootstrapNodeManager.REQUEST_MASTER_MIN_INTERVAL_SECS, 1);
66 UTIL.startMiniCluster(3);
67 HBaseTestingUtil.setReplicas(UTIL.getAdmin(), TableName.META_TABLE_NAME, 3);
70 @AfterClass
71 public static void tearDownAfterClass() throws Exception {
72 UTIL.shutdownMiniCluster();
75 @Before
76 public void setUp() throws IOException {
77 registry = new RpcConnectionRegistry(UTIL.getConfiguration());
80 @After
81 public void tearDown() throws IOException {
82 Closeables.close(registry, true);
85 private void setMaxNodeCount(int count) {
86 UTIL.getMiniHBaseCluster().getMasterThreads().stream()
87 .map(t -> t.getMaster().getConfiguration())
88 .forEach(conf -> conf.setInt(RSRpcServices.CLIENT_BOOTSTRAP_NODE_LIMIT, count));
89 UTIL.getMiniHBaseCluster().getRegionServerThreads().stream()
90 .map(t -> t.getRegionServer().getConfiguration())
91 .forEach(conf -> conf.setInt(RSRpcServices.CLIENT_BOOTSTRAP_NODE_LIMIT, count));
94 @Test
95 public void testRegistryRPCs() throws Exception {
96 HMaster activeMaster = UTIL.getHBaseCluster().getMaster();
97 // sleep 3 seconds, since our initial delay is 1 second, we should have refreshed the endpoints
98 Thread.sleep(3000);
99 assertThat(registry.getParsedServers(),
100 hasItems(activeMaster.getServerManager().getOnlineServersList().toArray(new ServerName[0])));
102 // Add wait on all replicas being assigned before proceeding w/ test. Failed on occasion
103 // because not all replicas had made it up before test started.
104 RegionReplicaTestHelper.waitUntilAllMetaReplicasAreReady(UTIL, registry);
106 assertEquals(registry.getClusterId().get(), activeMaster.getClusterId());
107 assertEquals(registry.getActiveMaster().get(), activeMaster.getServerName());
108 List<HRegionLocation> metaLocations =
109 Arrays.asList(registry.getMetaRegionLocations().get().getRegionLocations());
110 List<HRegionLocation> actualMetaLocations = activeMaster.getMetaLocations();
111 Collections.sort(metaLocations);
112 Collections.sort(actualMetaLocations);
113 assertEquals(actualMetaLocations, metaLocations);
115 // test that the node count config works
116 setMaxNodeCount(1);
117 UTIL.waitFor(10000, () -> registry.getParsedServers().size() == 1);