HBASE-26567 Remove IndexType from ChunkCreator (#3947)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / TestClusterPortAssignment.java
blob38d1627ac5f2ed3eee25460699dbfd18cf777015
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 static org.junit.Assert.fail;
23 import java.net.BindException;
24 import org.apache.commons.lang3.exception.ExceptionUtils;
25 import org.apache.hadoop.hbase.testclassification.MediumTests;
26 import org.junit.ClassRule;
27 import org.junit.Test;
28 import org.junit.experimental.categories.Category;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 @Category(MediumTests.class)
33 public class TestClusterPortAssignment {
34 @ClassRule
35 public static final HBaseClassTestRule CLASS_RULE =
36 HBaseClassTestRule.forClass(TestClusterPortAssignment.class);
38 private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
39 private static final Logger LOG = LoggerFactory.getLogger(TestClusterPortAssignment.class);
41 /**
42 * Check that we can start an HBase cluster specifying a custom set of
43 * RPC and infoserver ports.
45 @Test(timeout = 300000)
46 public void testClusterPortAssignment() throws Exception {
47 boolean retry = false;
48 do {
49 int masterPort = HBaseTestingUtil.randomFreePort();
50 int masterInfoPort = HBaseTestingUtil.randomFreePort();
51 int rsPort = HBaseTestingUtil.randomFreePort();
52 int rsInfoPort = HBaseTestingUtil.randomFreePort();
53 TEST_UTIL.getConfiguration().setBoolean(LocalHBaseCluster.ASSIGN_RANDOM_PORTS, false);
54 TEST_UTIL.getConfiguration().setBoolean(HConstants.REGIONSERVER_INFO_PORT_AUTO, false);
55 TEST_UTIL.getConfiguration().setBoolean("fs.hdfs.impl.disable.cache", true);
56 TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_PORT, masterPort);
57 TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, masterInfoPort);
58 TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, rsPort);
59 TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, rsInfoPort);
60 LOG.info("Ports: {}, {}, {}, {}", masterPort, masterInfoPort, rsPort, rsInfoPort);
61 try {
62 SingleProcessHBaseCluster cluster = TEST_UTIL.startMiniCluster();
63 assertTrue("Cluster failed to come up", cluster.waitForActiveAndReadyMaster(30000));
64 retry = false;
65 assertEquals("Master RPC port is incorrect", masterPort,
66 cluster.getMaster().getRpcServer().getListenerAddress().getPort());
67 assertEquals("Master info port is incorrect", masterInfoPort,
68 cluster.getMaster().getInfoServer().getPort());
69 assertEquals("RS RPC port is incorrect", rsPort,
70 cluster.getRegionServer(0).getRpcServer().getListenerAddress().getPort());
71 assertEquals("RS info port is incorrect", rsInfoPort,
72 cluster.getRegionServer(0).getInfoServer().getPort());
73 } catch (Exception e) {
74 Throwable rootCause = ExceptionUtils.getRootCause(e);
75 if (rootCause instanceof BindException) {
76 LOG.info("Failed bind, need to retry", e);
77 retry = true;
78 } else {
79 LOG.error("Failed to start mini cluster", e);
80 retry = false;
81 fail("Failed to start mini cluster with assigned ports.");
83 } finally {
84 TEST_UTIL.shutdownMiniCluster();
86 } while (retry);