org.apache.hadoop.hbase.HBaseTestingUtility.randomFreePort()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(97)

本文整理了Java中org.apache.hadoop.hbase.HBaseTestingUtility.randomFreePort()方法的一些代码示例,展示了HBaseTestingUtility.randomFreePort()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HBaseTestingUtility.randomFreePort()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.HBaseTestingUtility
类名称:HBaseTestingUtility
方法名:randomFreePort

HBaseTestingUtility.randomFreePort介绍

暂无

代码示例

代码示例来源:origin: apache/hbase

/**
 * Generates a list of random port numbers in the sorted order. A sorted
 * order makes sense if we ever want to refer to these servers by their index
 * in the returned array, e.g. server #0, #1, etc.
 */
private static List<Integer> sortedPorts(int n) {
 List<Integer> ports = new ArrayList<>(n);
 for (int i = 0; i < n; ++i) {
  ports.add(HBaseTestingUtility.randomFreePort());
 }
 Collections.sort(ports);
 return ports;
}

代码示例来源:origin: apache/hbase

/**
 * Creates and binds a regular ServerSocket.
 */
private void bindServerSocket(InetAddress inetAddr) throws IOException {
 while(true) {
  int port = HBaseTestingUtility.randomFreePort();
  InetSocketAddress addr = new InetSocketAddress(inetAddr, port);
  ServerSocket serverSocket = null;
  try {
   serverSocket = new ServerSocket();
   serverSocket.bind(addr);
   break;
  } catch (BindException ex) {
   //continue
   LOG.info("Failed on " + addr + ", inedAddr=" + inetAddr, ex);
  } finally {
   if (serverSocket != null) {
    serverSocket.close();
   }
  }
 }
}

代码示例来源:origin: apache/hbase

/**
 * Creates a NIO ServerSocketChannel, and gets the ServerSocket from
 * there. Then binds the obtained socket.
 * This fails on Windows with Oracle JDK1.6.0u33, if the passed InetAddress is a
 * IPv6 address. Works on Oracle JDK 1.7.
 */
private void bindNIOServerSocket(InetAddress inetAddr) throws IOException {
 while (true) {
  int port = HBaseTestingUtility.randomFreePort();
  InetSocketAddress addr = new InetSocketAddress(inetAddr, port);
  ServerSocketChannel channel = null;
  ServerSocket serverSocket = null;
  try {
   channel = ServerSocketChannel.open();
   serverSocket = channel.socket();
   serverSocket.bind(addr); // This does not work
   break;
  } catch (BindException ex) {
   //continue
  } finally {
   if (serverSocket != null) {
    serverSocket.close();
   }
   if (channel != null) {
    channel.close();
   }
  }
 }
}

代码示例来源:origin: apache/hbase

confMap.put(HConstants.MASTER_PORT, rpcPort);
int masterInfoPort = HBaseTestingUtility.randomFreePort();
reportWebUIPort("master", masterInfoPort);
confMap.put(HConstants.MASTER_INFO_PORT, masterInfoPort);
confMap.put(HConstants.REGIONSERVER_PORT, rpcPort);
int rsInfoPort = HBaseTestingUtility.randomFreePort();
reportWebUIPort("region server", rsInfoPort);
confMap.put(HConstants.REGIONSERVER_INFO_PORT, rsInfoPort);

代码示例来源:origin: apache/hbase

void runThriftServer(int customHeaderSize) throws Exception {
 List<String> args = new ArrayList<>(3);
 port = HBaseTestingUtility.randomFreePort();
 args.add("-" + PORT_OPTION);
 args.add(String.valueOf(port));
 args.add("-" + INFOPORT_OPTION);
 int infoPort = HBaseTestingUtility.randomFreePort();
 args.add(String.valueOf(infoPort));
 args.add("start");

代码示例来源:origin: apache/hbase

/**
 * Constructor. Modifies the passed configuration.
 * @param hbaseHome the top directory of the HBase source tree
 */
public ProcessBasedLocalHBaseCluster(Configuration conf,
  int numDataNodes, int numRegionServers) {
 this.conf = conf;
 this.hbaseHome = HBaseHomePath.getHomePath();
 this.numMasters = 1;
 this.numRegionServers = numRegionServers;
 this.workDir = hbaseHome + "/target/local_cluster";
 this.numDataNodes = numDataNodes;
 hbaseDaemonScript = hbaseHome + "/bin/hbase-daemon.sh";
 zkClientPort = HBaseTestingUtility.randomFreePort();
 this.rsPorts = sortedPorts(numRegionServers);
 this.masterPorts = sortedPorts(numMasters);
 conf.set(HConstants.ZOOKEEPER_QUORUM, HConstants.LOCALHOST);
 conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, zkClientPort);
}

代码示例来源:origin: apache/hbase

private static SimpleKdcServer buildMiniKdc() throws Exception {
 SimpleKdcServer kdc = new SimpleKdcServer();
 final File target = new File(System.getProperty("user.dir"), "target");
 File kdcDir = new File(target, TestThriftSpnegoHttpServer.class.getSimpleName());
 if (kdcDir.exists()) {
  FileUtils.deleteDirectory(kdcDir);
 }
 kdcDir.mkdirs();
 kdc.setWorkDir(kdcDir);
 kdc.setKdcHost(HConstants.LOCALHOST);
 int kdcPort = HBaseTestingUtility.randomFreePort();
 kdc.setAllowTcp(true);
 kdc.setAllowUdp(false);
 kdc.setKdcTcpPort(kdcPort);
 LOG.info("Starting KDC server at " + HConstants.LOCALHOST + ":" + kdcPort);
 kdc.init();
 return kdc;
}

代码示例来源:origin: apache/hbase

args.add(serverTypeOption);
port = HBaseTestingUtility.randomFreePort();
args.add("-" + PORT_OPTION);
args.add(String.valueOf(port));
args.add("-" + INFOPORT_OPTION);
int infoPort = HBaseTestingUtility.randomFreePort();
args.add(String.valueOf(infoPort));

代码示例来源:origin: apache/hbase

@BeforeClass
public static void setUp() throws Exception {
 // Do not start info server
 TEST_UTIL.getConfiguration().setInt(THRIFT_INFO_SERVER_PORT , -1);
 TEST_UTIL.startMiniCluster();
 thriftPort = HBaseTestingUtility.randomFreePort();
 httpPort = HBaseTestingUtility.randomFreePort();
 // Start a thrift server
 thriftServer = startThriftServer(thriftPort, false);
 // Start a HTTP thrift server
 thriftHttpServer = startThriftServer(httpPort, true);
 thriftConnection = createConnection(thriftPort, false);
 thriftHttpConnection = createConnection(httpPort, true);
 thriftAdmin = thriftConnection.getAdmin();
 LOG.info("TS_1=" + TS_1);
 LOG.info("TS_2=" + TS_1);
}

代码示例来源:origin: apache/hbase

boolean retry = false;
do {
 int masterPort =  HBaseTestingUtility.randomFreePort();
 int masterInfoPort =  HBaseTestingUtility.randomFreePort();
 int rsPort =  HBaseTestingUtility.randomFreePort();
 int rsInfoPort =  HBaseTestingUtility.randomFreePort();
 TEST_UTIL.getConfiguration().setBoolean(LocalHBaseCluster.ASSIGN_RANDOM_PORTS, false);
 TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_PORT, masterPort);

代码示例来源:origin: apache/hbase

cluster.getConfiguration().setInt(HConstants.MASTER_PORT, HBaseTestingUtility.randomFreePort());
cluster.getConfiguration().setInt(HConstants.MASTER_PORT, HBaseTestingUtility.randomFreePort());
cluster.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART,
 tablesOnMaster? 3: 2);

代码示例来源:origin: apache/hbase

String address = HConstants.LOCALHOST_IP + ":" + HBaseTestingUtility.randomFreePort();

代码示例来源:origin: org.apache.hbase/hbase-server

/**
 * Generates a list of random port numbers in the sorted order. A sorted
 * order makes sense if we ever want to refer to these servers by their index
 * in the returned array, e.g. server #0, #1, etc.
 */
private static List<Integer> sortedPorts(int n) {
 List<Integer> ports = new ArrayList<>(n);
 for (int i = 0; i < n; ++i) {
  ports.add(HBaseTestingUtility.randomFreePort());
 }
 Collections.sort(ports);
 return ports;
}

代码示例来源:origin: org.apache.hbase/hbase-server

/**
 * Creates and binds a regular ServerSocket.
 */
private void bindServerSocket(InetAddress inetAddr) throws IOException {
 while(true) {
  int port = HBaseTestingUtility.randomFreePort();
  InetSocketAddress addr = new InetSocketAddress(inetAddr, port);
  ServerSocket serverSocket = null;
  try {
   serverSocket = new ServerSocket();
   serverSocket.bind(addr);
   break;
  } catch (BindException ex) {
   //continue
   LOG.info("Failed on " + addr + ", inedAddr=" + inetAddr, ex);
  } finally {
   if (serverSocket != null) {
    serverSocket.close();
   }
  }
 }
}

代码示例来源:origin: org.apache.hbase/hbase-server

/**
 * Creates a NIO ServerSocketChannel, and gets the ServerSocket from
 * there. Then binds the obtained socket.
 * This fails on Windows with Oracle JDK1.6.0u33, if the passed InetAddress is a
 * IPv6 address. Works on Oracle JDK 1.7.
 */
private void bindNIOServerSocket(InetAddress inetAddr) throws IOException {
 while (true) {
  int port = HBaseTestingUtility.randomFreePort();
  InetSocketAddress addr = new InetSocketAddress(inetAddr, port);
  ServerSocketChannel channel = null;
  ServerSocket serverSocket = null;
  try {
   channel = ServerSocketChannel.open();
   serverSocket = channel.socket();
   serverSocket.bind(addr); // This does not work
   break;
  } catch (BindException ex) {
   //continue
  } finally {
   if (serverSocket != null) {
    serverSocket.close();
   }
   if (channel != null) {
    channel.close();
   }
  }
 }
}

代码示例来源:origin: org.apache.hbase/hbase-server

/**
 * Constructor. Modifies the passed configuration.
 * @param hbaseHome the top directory of the HBase source tree
 */
public ProcessBasedLocalHBaseCluster(Configuration conf,
  int numDataNodes, int numRegionServers) {
 this.conf = conf;
 this.hbaseHome = HBaseHomePath.getHomePath();
 this.numMasters = 1;
 this.numRegionServers = numRegionServers;
 this.workDir = hbaseHome + "/target/local_cluster";
 this.numDataNodes = numDataNodes;
 hbaseDaemonScript = hbaseHome + "/bin/hbase-daemon.sh";
 zkClientPort = HBaseTestingUtility.randomFreePort();
 this.rsPorts = sortedPorts(numRegionServers);
 this.masterPorts = sortedPorts(numMasters);
 conf.set(HConstants.ZOOKEEPER_QUORUM, HConstants.LOCALHOST);
 conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, zkClientPort);
}

代码示例来源:origin: org.apache.hbase/hbase-thrift

void runThriftServer(int customHeaderSize) throws Exception {
 List<String> args = new ArrayList<>(3);
 port = HBaseTestingUtility.randomFreePort();
 args.add("-" + ThriftServer.PORT_OPTION);
 args.add(String.valueOf(port));
 args.add("-" + ThriftServer.INFOPORT_OPTION);
 int infoPort = HBaseTestingUtility.randomFreePort();
 args.add(String.valueOf(infoPort));
 args.add("start");

代码示例来源:origin: org.apache.hbase/hbase-thrift

private static SimpleKdcServer buildMiniKdc() throws Exception {
 SimpleKdcServer kdc = new SimpleKdcServer();
 final File target = new File(System.getProperty("user.dir"), "target");
 File kdcDir = new File(target, TestThriftSpnegoHttpServer.class.getSimpleName());
 if (kdcDir.exists()) {
  FileUtils.deleteDirectory(kdcDir);
 }
 kdcDir.mkdirs();
 kdc.setWorkDir(kdcDir);
 kdc.setKdcHost(HConstants.LOCALHOST);
 int kdcPort = HBaseTestingUtility.randomFreePort();
 kdc.setAllowTcp(true);
 kdc.setAllowUdp(false);
 kdc.setKdcTcpPort(kdcPort);
 LOG.info("Starting KDC server at " + HConstants.LOCALHOST + ":" + kdcPort);
 kdc.init();
 return kdc;
}

代码示例来源:origin: com.aliyun.hbase/alihbase-thrift

private void runThriftServer(int customHeaderSize) throws Exception {
 List<String> args = new ArrayList<>(3);
 port = HBaseTestingUtility.randomFreePort();
 args.add("-" + ThriftServer.PORT_OPTION);
 args.add(String.valueOf(port));
 args.add("start");
 thriftServer = new ThriftServer(TEST_UTIL.getConfiguration());
 startHttpServerThread(args.toArray(new String[args.size()]));
 // wait up to 10s for the server to start
 for (int i = 0; i < 100
   && ( thriftServer.serverRunner == null ||  thriftServer.serverRunner.httpServer ==
   null); i++) {
  Thread.sleep(100);
 }
 try {
  talkToThriftServer(customHeaderSize);
 } catch (Exception ex) {
  clientSideException = ex;
 } finally {
  stopHttpServerThread();
 }
 if (clientSideException != null) {
  LOG.error("Thrift client threw an exception " + clientSideException);
  if (clientSideException instanceof  TTransportException) {
   throw clientSideException;
  } else {
   throw new Exception(clientSideException);
  }
 }
}

代码示例来源:origin: org.apache.hbase/hbase-server

boolean retry = false;
do {
 int masterPort =  HBaseTestingUtility.randomFreePort();
 int masterInfoPort =  HBaseTestingUtility.randomFreePort();
 int rsPort =  HBaseTestingUtility.randomFreePort();
 int rsInfoPort =  HBaseTestingUtility.randomFreePort();
 TEST_UTIL.getConfiguration().setBoolean(LocalHBaseCluster.ASSIGN_RANDOM_PORTS, false);
 TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_PORT, masterPort);

相关文章

HBaseTestingUtility类方法