Java Code Examples for org.apache.hadoop.hbase.HBaseTestingUtility#available()

The following examples show how to use org.apache.hadoop.hbase.HBaseTestingUtility#available() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBalancerStatusTagInJMXMetrics.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Setup the environment for the test.
 */
@BeforeClass
public static void setupBeforeClass() throws Exception {
  conf = UTIL.getConfiguration();
  Random rand = new Random();
  for (int i = 0; i < 10; i++) {
    do {
      int sign = i % 2 == 0 ? 1 : -1;
      connectorPort += sign * rand.nextInt(100);
    } while (!HBaseTestingUtility.available(connectorPort));
    try {
      conf.setInt("regionserver.rmi.registry.port", connectorPort);
      cluster = UTIL.startMiniCluster();
      LOG.info("Waiting for active/ready master");
      cluster.waitForActiveAndReadyMaster();
      master = cluster.getMaster();
      break;
    } catch (Exception e) {
      LOG.debug("Encountered exception when starting mini cluster. Trying port " + connectorPort,
        e);
      try {
        // this is to avoid "IllegalStateException: A mini-cluster is already running"
        UTIL.shutdownMiniCluster();
      } catch (Exception ex) {
        LOG.debug("Encountered exception shutting down cluster", ex);
      }
    }
  }
}
 
Example 2
Source File: TestMetaTableMetrics.java    From hbase with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  // Set system coprocessor so it can be applied to meta regions
  UTIL.getConfiguration().set("hbase.coprocessor.region.classes",
    MetaTableMetrics.class.getName());
  conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY, JMXListener.class.getName());
  Random rand = new Random();
  for (int i = 0; i < 10; i++) {
    do {
      int sign = i % 2 == 0 ? 1 : -1;
      connectorPort += sign * rand.nextInt(100);
    } while (!HBaseTestingUtility.available(connectorPort));
    try {
      conf.setInt("regionserver.rmi.registry.port", connectorPort);
      UTIL.startMiniCluster(1);
      break;
    } catch (Exception e) {
      LOG.debug("Encountered exception when starting cluster. Trying port {}", connectorPort, e);
      try {
        // this is to avoid "IllegalStateException: A mini-cluster is already running"
        UTIL.shutdownMiniCluster();
      } catch (Exception ex) {
        LOG.debug("Encountered exception shutting down cluster", ex);
      }
    }
  }
}