本文整理汇总了Java中org.apache.hadoop.hbase.HBaseTestingUtility.randomFreePort方法的典型用法代码示例。如果您正苦于以下问题:Java HBaseTestingUtility.randomFreePort方法的具体用法?Java HBaseTestingUtility.randomFreePort怎么用?Java HBaseTestingUtility.randomFreePort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hbase.HBaseTestingUtility
的用法示例。
在下文中一共展示了HBaseTestingUtility.randomFreePort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ProcessBasedLocalHBaseCluster
import org.apache.hadoop.hbase.HBaseTestingUtility; //导入方法依赖的package包/类
/**
* 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);
}
示例2: runThriftServer
import org.apache.hadoop.hbase.HBaseTestingUtility; //导入方法依赖的package包/类
private void runThriftServer(int customHeaderSize) throws Exception {
List<String> args = new ArrayList<String>();
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);
}
}
}
示例3: testRunThriftServer
import org.apache.hadoop.hbase.HBaseTestingUtility; //导入方法依赖的package包/类
@Test(timeout=600000)
public void testRunThriftServer() throws Exception {
List<String> args = new ArrayList<String>();
if (implType != null) {
String serverTypeOption = implType.toString();
assertTrue(serverTypeOption.startsWith("-"));
args.add(serverTypeOption);
}
port = HBaseTestingUtility.randomFreePort();
args.add("-" + ThriftServer.PORT_OPTION);
args.add(String.valueOf(port));
if (specifyFramed) {
args.add("-" + ThriftServer.FRAMED_OPTION);
}
if (specifyBindIP) {
args.add("-" + ThriftServer.BIND_OPTION);
args.add(InetAddress.getLocalHost().getHostName());
}
if (specifyCompact) {
args.add("-" + ThriftServer.COMPACT_OPTION);
}
args.add("start");
thriftServer = new ThriftServer(TEST_UTIL.getConfiguration());
startCmdLineThread(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.tserver == null); i++) {
Thread.sleep(100);
}
Class<? extends TServer> expectedClass = implType != null ?
implType.serverClass : TBoundedThreadPoolServer.class;
assertEquals(expectedClass,
thriftServer.serverRunner.tserver.getClass());
try {
talkToThriftServer();
} catch (Exception ex) {
clientSideException = ex;
} finally {
stopCmdLineThread();
}
if (clientSideException != null) {
LOG.error("Thrift client threw an exception. Parameters:" +
getParametersString(), clientSideException);
throw new Exception(clientSideException);
}
}
示例4: generateConfig
import org.apache.hadoop.hbase.HBaseTestingUtility; //导入方法依赖的package包/类
private final String generateConfig(ServerType serverType, int rpcPort,
String daemonDir) {
StringBuilder sb = new StringBuilder();
Map<String, Object> confMap = new TreeMap<String, Object>();
confMap.put(HConstants.CLUSTER_DISTRIBUTED, true);
if (serverType == ServerType.MASTER) {
confMap.put(HConstants.MASTER_PORT, rpcPort);
int masterInfoPort = HBaseTestingUtility.randomFreePort();
reportWebUIPort("master", masterInfoPort);
confMap.put(HConstants.MASTER_INFO_PORT, masterInfoPort);
} else if (serverType == ServerType.RS) {
confMap.put(HConstants.REGIONSERVER_PORT, rpcPort);
int rsInfoPort = HBaseTestingUtility.randomFreePort();
reportWebUIPort("region server", rsInfoPort);
confMap.put(HConstants.REGIONSERVER_INFO_PORT, rsInfoPort);
} else {
confMap.put(HConstants.ZOOKEEPER_DATA_DIR, daemonDir);
}
confMap.put(HConstants.ZOOKEEPER_CLIENT_PORT, zkClientPort);
confMap.put(HConstants.HREGION_MAX_FILESIZE, MAX_FILE_SIZE_OVERRIDE);
if (dfsCluster != null) {
String fsURL = "hdfs://" + HConstants.LOCALHOST + ":" + dfsCluster.getNameNodePort();
confMap.put("fs.defaultFS", fsURL);
confMap.put("hbase.rootdir", fsURL + "/hbase_test");
}
sb.append("<configuration>\n");
for (Map.Entry<String, Object> entry : confMap.entrySet()) {
sb.append(" <property>\n");
sb.append(" <name>" + entry.getKey() + "</name>\n");
sb.append(" <value>" + entry.getValue() + "</value>\n");
sb.append(" </property>\n");
}
sb.append("</configuration>\n");
return sb.toString();
}