HBASE-23723 Ensure MOB compaction works in optimized mode after snapshot clone (...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / TestClusterPortAssignment.java
bloba5d4467d4ab8c6c60187e9ef2525426fc15452d1
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;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 import java.net.BindException;
23 import org.apache.hadoop.hbase.testclassification.MediumTests;
24 import org.junit.ClassRule;
25 import org.junit.Test;
26 import org.junit.experimental.categories.Category;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 @Category(MediumTests.class)
31 public class TestClusterPortAssignment {
32 @ClassRule
33 public static final HBaseClassTestRule CLASS_RULE =
34 HBaseClassTestRule.forClass(TestClusterPortAssignment.class);
36 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
37 private static final Logger LOG = LoggerFactory.getLogger(TestClusterPortAssignment.class);
39 /**
40 * Check that we can start an HBase cluster specifying a custom set of
41 * RPC and infoserver ports.
43 @Test
44 public void testClusterPortAssignment() throws Exception {
45 boolean retry = false;
46 do {
47 int masterPort = HBaseTestingUtility.randomFreePort();
48 int masterInfoPort = HBaseTestingUtility.randomFreePort();
49 int rsPort = HBaseTestingUtility.randomFreePort();
50 int rsInfoPort = HBaseTestingUtility.randomFreePort();
51 TEST_UTIL.getConfiguration().setBoolean(LocalHBaseCluster.ASSIGN_RANDOM_PORTS, false);
52 TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_PORT, masterPort);
53 TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, masterInfoPort);
54 TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, rsPort);
55 TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, rsInfoPort);
56 try {
57 MiniHBaseCluster cluster = TEST_UTIL.startMiniCluster();
58 assertTrue("Cluster failed to come up", cluster.waitForActiveAndReadyMaster(30000));
59 retry = false;
60 assertEquals("Master RPC port is incorrect", masterPort,
61 cluster.getMaster().getRpcServer().getListenerAddress().getPort());
62 assertEquals("Master info port is incorrect", masterInfoPort,
63 cluster.getMaster().getInfoServer().getPort());
64 assertEquals("RS RPC port is incorrect", rsPort,
65 cluster.getRegionServer(0).getRpcServer().getListenerAddress().getPort());
66 assertEquals("RS info port is incorrect", rsInfoPort,
67 cluster.getRegionServer(0).getInfoServer().getPort());
68 } catch (Exception e) {
69 if (e instanceof BindException || e.getCause() != null &&
70 (e.getCause() instanceof BindException || e.getCause().getCause() != null &&
71 e.getCause().getCause() instanceof BindException)) {
72 LOG.info("Failed bind, need to retry", e);
73 retry = true;
74 } else {
75 throw e;
77 } finally {
78 TEST_UTIL.shutdownMiniCluster();
80 } while (retry);