HBASE-15835 - Prevent HBaseTestingUtility#startMiniCluster from throwing _HMasterAddress already in use_ RuntimeException when another HBase thread is running

Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Daniel Vimont 2016-05-24 19:16:52 +09:00 committed by stack
parent a1f0c1cbb3
commit e6d613de70
16 changed files with 45 additions and 38 deletions

View File

@ -143,7 +143,10 @@ import org.apache.zookeeper.ZooKeeper.States;
* Not all methods work with the real cluster.
* Depends on log4j being on classpath and
* hbase-site.xml for logging and test-run configuration. It does not set
* logging levels nor make changes to configuration parameters.
* logging levels.
* In the configuration properties, default values for master-info-port and
* region-server-port are overridden such that a random port will be assigned (thus
* avoiding port contention if another local HBase instance is already running).
* <p>To preserve test data directories, pass the system property "hbase.testing.preserve.testdir"
* setting it to true.
*/
@ -310,6 +313,20 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
// a hbase checksum verification failure will cause unit tests to fail
ChecksumUtil.generateExceptionForChecksumFailureForTest(true);
// prevent contention for ports if other hbase thread(s) already running
if (conf != null) {
if (conf.getInt(HConstants.MASTER_INFO_PORT, HConstants.DEFAULT_MASTER_INFOPORT)
== HConstants.DEFAULT_MASTER_INFOPORT) {
conf.setInt(HConstants.MASTER_INFO_PORT, -1);
LOG.debug("Config property " + HConstants.MASTER_INFO_PORT + " changed to -1");
}
if (conf.getInt(HConstants.REGIONSERVER_PORT, HConstants.DEFAULT_REGIONSERVER_PORT)
== HConstants.DEFAULT_REGIONSERVER_PORT) {
conf.setInt(HConstants.REGIONSERVER_PORT, -1);
LOG.debug("Config property " + HConstants.REGIONSERVER_PORT + " changed to -1");
}
}
}
/**

View File

@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.Path;
@ -224,7 +225,7 @@ public class TestHBaseTestingUtility {
// kill another active zk server
currentActivePort = cluster2.killCurrentActiveZooKeeperServer();
assertTrue(currentActivePort >= defaultClientPort);
assertTrue(cluster2.getClientPort() == currentActivePort);
assertTrue(cluster2.getClientPort() == currentActivePort);
assertEquals(2, cluster2.getBackupZooKeeperServerNum());
assertEquals(3, cluster2.getZooKeeperServerNum());
@ -418,4 +419,28 @@ public class TestHBaseTestingUtility {
assertNotEquals(port1, port2);
Mockito.verify(random, Mockito.times(3)).nextInt(Mockito.any(Integer.class));
}
@Test
public void testOverridingOfDefaultPorts() {
// confirm that default port properties being overridden to "-1"
Configuration defaultConfig = HBaseConfiguration.create();
defaultConfig.setInt(HConstants.MASTER_INFO_PORT, HConstants.DEFAULT_MASTER_INFOPORT);
defaultConfig.setInt(HConstants.REGIONSERVER_PORT, HConstants.DEFAULT_REGIONSERVER_PORT);
HBaseTestingUtility htu = new HBaseTestingUtility(defaultConfig);
assertEquals(-1, htu.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0));
assertEquals(-1, htu.getConfiguration().getInt(HConstants.REGIONSERVER_PORT, 0));
// confirm that nonDefault (custom) port settings are NOT overridden
Configuration altConfig = HBaseConfiguration.create();
final int nonDefaultMasterInfoPort = 3333;
final int nonDefaultRegionServerPort = 4444;
altConfig.setInt(HConstants.MASTER_INFO_PORT, nonDefaultMasterInfoPort);
altConfig.setInt(HConstants.REGIONSERVER_PORT, nonDefaultRegionServerPort);
htu = new HBaseTestingUtility(altConfig);
assertEquals(nonDefaultMasterInfoPort,
htu.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0));
assertEquals(nonDefaultRegionServerPort
, htu.getConfiguration().getInt(HConstants.REGIONSERVER_PORT, 0));
}
}

View File

@ -94,9 +94,6 @@ public class TestSnapshotCloneIndependence {
conf.setInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, 15);
// enable snapshot support
conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true);
// disable the ui
conf.setInt("hbase.regionsever.info.port", -1);
conf.setInt("hbase.master.info.port", -1);
// change the flush size to a small amount, regulating number of store files
conf.setInt("hbase.hregion.memstore.flush.size", 25000);
// so make sure we get a compaction when doing a load, but keep around

View File

@ -49,9 +49,6 @@ public class TestDefaultMobStoreFlusher {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setInt("hbase.master.info.port", 0);
TEST_UTIL.getConfiguration().setBoolean("hbase.regionserver.info.port.auto", true);
TEST_UTIL.startMiniCluster(1);
}

View File

@ -53,9 +53,6 @@ public class TestExpiredMobFileCleaner {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setInt("hbase.master.info.port", 0);
TEST_UTIL.getConfiguration().setBoolean("hbase.regionserver.info.port.auto", true);
TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3);
}

View File

@ -55,9 +55,6 @@ public class TestMobDataBlockEncoding {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setInt("hbase.master.info.port", 0);
TEST_UTIL.getConfiguration().setBoolean("hbase.regionserver.info.port.auto", true);
TEST_UTIL.startMiniCluster(1);
}

View File

@ -113,8 +113,6 @@ public class TestMobCompactor {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setInt("hbase.master.info.port", 0);
TEST_UTIL.getConfiguration().setBoolean("hbase.regionserver.info.port.auto", true);
TEST_UTIL.getConfiguration()
.setLong(MobConstants.MOB_COMPACTION_MERGEABLE_THRESHOLD, 5000);
TEST_UTIL.getConfiguration().set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY,

View File

@ -78,8 +78,6 @@ public class TestPartitionedMobCompactor {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setInt("hbase.master.info.port", 0);
TEST_UTIL.getConfiguration().setBoolean("hbase.regionserver.info.port.auto", true);
TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3);
TEST_UTIL.startMiniCluster(1);
pool = createThreadPool();
@ -396,4 +394,4 @@ public class TestPartitionedMobCompactor {
conf.setInt(MobConstants.MOB_COMPACTION_BATCH_SIZE,
MobConstants.DEFAULT_MOB_COMPACTION_BATCH_SIZE);
}
}
}

View File

@ -47,8 +47,6 @@ public class TestMobSweepJob {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setInt("hbase.master.info.port", 0);
TEST_UTIL.getConfiguration().setBoolean("hbase.regionserver.info.port.auto", true);
TEST_UTIL.getConfiguration().set(CommonConfigurationKeys.IO_SERIALIZATIONS_KEY,
JavaSerialization.class.getName() + "," + WritableSerialization.class.getName());
TEST_UTIL.startMiniCluster();

View File

@ -54,8 +54,6 @@ public class TestMobSweepMapper {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setInt("hbase.master.info.port", 0);
TEST_UTIL.getConfiguration().setBoolean("hbase.regionserver.info.port.auto", true);
TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3);
TEST_UTIL.startMiniCluster(1);
}

View File

@ -77,9 +77,6 @@ public class TestMobSweepReducer {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setInt("hbase.master.info.port", 0);
TEST_UTIL.getConfiguration().setBoolean("hbase.regionserver.info.port.auto", true);
TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3);
TEST_UTIL.startMiniCluster(1);

View File

@ -50,8 +50,6 @@ public class TestDeleteMobTable {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setInt("hbase.master.info.port", 0);
TEST_UTIL.getConfiguration().setBoolean("hbase.regionserver.info.port.auto", true);
TEST_UTIL.startMiniCluster(1);
}

View File

@ -85,8 +85,6 @@ public class TestMobStoreCompaction {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
UTIL.getConfiguration().setInt("hbase.master.info.port", 0);
UTIL.getConfiguration().setBoolean("hbase.regionserver.info.port.auto", true);
UTIL.startMiniCluster(1);
}

View File

@ -78,8 +78,6 @@ public class TestMobStoreScanner {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setInt("hbase.master.info.port", 0);
TEST_UTIL.getConfiguration().setBoolean("hbase.regionserver.info.port.auto", true);
TEST_UTIL.getConfiguration().setInt("hbase.client.keyvalue.maxsize", 100 * 1024 * 1024);
// TODO: AsyncFSWAL can not handle large edits right now, remove this after we fix the issue.
TEST_UTIL.getConfiguration().set(WALFactory.WAL_PROVIDER, "filesystem");

View File

@ -44,10 +44,6 @@ public abstract class AbstractTestShell {
TEST_UTIL.getConfiguration().setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false);
TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3);
//NOTE: Below Settings are disabled for taskmonitor_test
TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, -1);
TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, 0);
TEST_UTIL.getConfiguration().setBoolean(HConstants.REGIONSERVER_INFO_PORT_AUTO, true);
// Security setup configuration
SecureTestUtil.enableSecurity(TEST_UTIL.getConfiguration());
VisibilityTestUtil.enableVisiblityLabels(TEST_UTIL.getConfiguration());

View File

@ -60,8 +60,6 @@ public class TestShellRSGroups {
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6);
TEST_UTIL.getConfiguration().setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false);
TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3);
TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, -1);
TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, -1);
// Security setup configuration
SecureTestUtil.enableSecurity(TEST_UTIL.getConfiguration());
VisibilityTestUtil.enableVisiblityLabels(TEST_UTIL.getConfiguration());