@Test
  public void testOverridingOfDefaultPorts() throws Exception {

    // confirm that default port properties being overridden to random
    Configuration defaultConfig = HBaseConfiguration.create();
    defaultConfig.setInt(HConstants.MASTER_INFO_PORT, HConstants.DEFAULT_MASTER_INFOPORT);
    defaultConfig.setInt(HConstants.REGIONSERVER_INFO_PORT,
      HConstants.DEFAULT_REGIONSERVER_INFOPORT);
    HBaseTestingUtil htu = new HBaseTestingUtil(defaultConfig);
    try {
      SingleProcessHBaseCluster defaultCluster = htu.startMiniCluster();
      final String masterHostPort =
        defaultCluster.getMaster().getServerName().getAddress().toString();
      assertNotEquals(HConstants.DEFAULT_MASTER_INFOPORT,
        defaultCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0));
      assertNotEquals(HConstants.DEFAULT_REGIONSERVER_INFOPORT,
        defaultCluster.getConfiguration().getInt(HConstants.REGIONSERVER_INFO_PORT, 0));
      assertEquals(masterHostPort,
        defaultCluster.getConfiguration().get(HConstants.MASTER_ADDRS_KEY));
    } finally {
      htu.shutdownMiniCluster();
    }

    // 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_INFO_PORT, nonDefaultRegionServerPort);
    htu = new HBaseTestingUtil(altConfig);
    try {
      SingleProcessHBaseCluster customCluster = htu.startMiniCluster();
      final String masterHostPort =
        customCluster.getMaster().getServerName().getAddress().toString();
      assertEquals(nonDefaultMasterInfoPort,
        customCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0));
      assertEquals(nonDefaultRegionServerPort,
        customCluster.getConfiguration().getInt(HConstants.REGIONSERVER_INFO_PORT, 0));
      assertEquals(masterHostPort,
        customCluster.getConfiguration().get(HConstants.MASTER_ADDRS_KEY));
    } finally {
      htu.shutdownMiniCluster();
    }
  }
Test that we can start and stop multiple time a cluster with the same HBaseTestingUtility.
hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtil.java