Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-25910 - Fix port assignment test #3308

Merged
merged 10 commits into from
May 28, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,7 @@ private void putUpWebUI() throws IOException {
// auto bind enabled, try to use another port
LOG.info("Failed binding http info server to port: " + port);
port++;
LOG.info("Retry starting http info server with port: " + port);
}
}
port = this.infoServer.getPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.BindException;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@org.junit.Ignore // See HBASE-24342. This test can't pass 100% of time as written so disabling
@Category(MediumTests.class)
public class TestClusterPortAssignment {
@ClassRule
Expand All @@ -41,7 +42,7 @@ public class TestClusterPortAssignment {
* Check that we can start an HBase cluster specifying a custom set of
* RPC and infoserver ports.
*/
@Test
@Test(timeout = 300000)
public void testClusterPortAssignment() throws Exception {
boolean retry = false;
vli02 marked this conversation as resolved.
Show resolved Hide resolved
do {
Expand All @@ -50,10 +51,13 @@ public void testClusterPortAssignment() throws Exception {
int rsPort = HBaseTestingUtility.randomFreePort();
int rsInfoPort = HBaseTestingUtility.randomFreePort();
TEST_UTIL.getConfiguration().setBoolean(LocalHBaseCluster.ASSIGN_RANDOM_PORTS, false);
TEST_UTIL.getConfiguration().setBoolean(HConstants.REGIONSERVER_INFO_PORT_AUTO, false);
TEST_UTIL.getConfiguration().setBoolean("fs.hdfs.impl.disable.cache", true);
vli02 marked this conversation as resolved.
Show resolved Hide resolved
TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_PORT, masterPort);
TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, masterInfoPort);
TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, rsPort);
TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, rsInfoPort);
LOG.info("Ports: {}, {}, {}, {}", masterPort, masterInfoPort, rsPort, rsInfoPort);
try {
MiniHBaseCluster cluster = TEST_UTIL.startMiniCluster();
assertTrue("Cluster failed to come up", cluster.waitForActiveAndReadyMaster(30000));
Expand All @@ -67,13 +71,14 @@ public void testClusterPortAssignment() throws Exception {
assertEquals("RS info port is incorrect", rsInfoPort,
cluster.getRegionServer(0).getInfoServer().getPort());
} catch (Exception e) {
if (e instanceof BindException || e.getCause() != null &&
(e.getCause() instanceof BindException || e.getCause().getCause() != null &&
e.getCause().getCause() instanceof BindException)) {
Throwable rootCause = ExceptionUtils.getRootCause(e);
if (rootCause instanceof BindException) {
LOG.info("Failed bind, need to retry", e);
retry = true;
} else {
throw e;
LOG.info("Failed to start mini cluster", e);
vli02 marked this conversation as resolved.
Show resolved Hide resolved
retry = false;
fail("Failed to start mini cluster with assigned ports.");
}
} finally {
TEST_UTIL.shutdownMiniCluster();
Expand Down