[MINOR] Fix hardcoding of ports in TestHoodieJmxMetrics (#1606)
This commit is contained in:
@@ -19,8 +19,8 @@
|
||||
package org.apache.hudi.common.minicluster;
|
||||
|
||||
import org.apache.hudi.common.model.HoodieTestUtils;
|
||||
import org.apache.hudi.common.testutils.NetworkTestUtils;
|
||||
import org.apache.hudi.common.util.FileIOUtils;
|
||||
import org.apache.hudi.exception.HoodieIOException;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
@@ -31,7 +31,6 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -61,14 +60,6 @@ public class HdfsTestService {
|
||||
return hadoopConf;
|
||||
}
|
||||
|
||||
private static int nextFreePort() {
|
||||
try (ServerSocket socket = new ServerSocket(0)) {
|
||||
return socket.getLocalPort();
|
||||
} catch (IOException e) {
|
||||
throw new HoodieIOException("Unable to find next free port", e);
|
||||
}
|
||||
}
|
||||
|
||||
public MiniDFSCluster start(boolean format) throws IOException {
|
||||
Objects.requireNonNull(workDir, "The work dir must be set before starting cluster.");
|
||||
hadoopConf = HoodieTestUtils.getDefaultHadoopConf();
|
||||
@@ -81,10 +72,10 @@ public class HdfsTestService {
|
||||
FileIOUtils.deleteDirectory(file);
|
||||
}
|
||||
|
||||
int namenodeRpcPort = nextFreePort();
|
||||
int datanodePort = nextFreePort();
|
||||
int datanodeIpcPort = nextFreePort();
|
||||
int datanodeHttpPort = nextFreePort();
|
||||
int namenodeRpcPort = NetworkTestUtils.nextFreePort();
|
||||
int datanodePort = NetworkTestUtils.nextFreePort();
|
||||
int datanodeIpcPort = NetworkTestUtils.nextFreePort();
|
||||
int datanodeHttpPort = NetworkTestUtils.nextFreePort();
|
||||
|
||||
// Configure and start the HDFS cluster
|
||||
// boolean format = shouldFormatDFSCluster(localDFSLocation, clean);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hudi.common.testutils;
|
||||
|
||||
import org.apache.hudi.exception.HoodieIOException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
|
||||
public class NetworkTestUtils {
|
||||
|
||||
public static int nextFreePort() {
|
||||
try (ServerSocket socket = new ServerSocket(0)) {
|
||||
return socket.getLocalPort();
|
||||
} catch (IOException e) {
|
||||
throw new HoodieIOException("Unable to find next free port", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user