public void startZooKeeper(final Properties properties, boolean format, String path, final boolean randomPort) {
String realPath = path + "/zk_test";
properties.setProperty("dataDir", realPath);
final ServerConfig serverConfig = new ServerConfig();
QuorumPeerConfig config = new QuorumPeerConfig() {
@Override
public InetSocketAddress getClientPortAddress() {
InetSocketAddress clientPortAddress = super.getClientPortAddress();
if (randomPort) {
return randomPort(clientPortAddress);
}
return clientPortAddress;
}
private InetSocketAddress randomPort(InetSocketAddress clientPortAddress) {
return new InetSocketAddress(clientPortAddress.getAddress(), 0);
}
};
try {
config.parseProperties(properties);
} catch (IOException e) {
LOG.error(e);
throw new RuntimeException(e);
} catch (ConfigException e) {
LOG.error(e);