This is an automated email from the ASF dual-hosted git repository.
chesnay pushed a commit to branch release-1.14
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/release-1.14 by this push:
new a37f891 [FLINK-24329][pulsar][tests] Fix port conflict
a37f891 is described below
commit a37f8914136888576d9c4ab229daa10b9c0ea845
Author: xmarker <[email protected]>
AuthorDate: Wed Sep 22 15:13:22 2021 +0800
[FLINK-24329][pulsar][tests] Fix port conflict
---
.../testutils/runtime/mock/PortBindingUtils.java | 67 ----------------------
.../testutils/runtime/mock/PulsarMockRuntime.java | 7 +--
2 files changed, 3 insertions(+), 71 deletions(-)
diff --git
a/flink-connectors/flink-connector-pulsar/src/test/java/org/apache/flink/connector/pulsar/testutils/runtime/mock/PortBindingUtils.java
b/flink-connectors/flink-connector-pulsar/src/test/java/org/apache/flink/connector/pulsar/testutils/runtime/mock/PortBindingUtils.java
deleted file mode 100644
index 41035db..0000000
---
a/flink-connectors/flink-connector-pulsar/src/test/java/org/apache/flink/connector/pulsar/testutils/runtime/mock/PortBindingUtils.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.flink.connector.pulsar.testutils.runtime.mock;
-
-import javax.net.ServerSocketFactory;
-
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.util.concurrent.ThreadLocalRandom;
-
-/**
- * This class is used for finding a available socket port. Use for running
multiple instances of the
- * bookkeeper tests at once.
- */
-public final class PortBindingUtils {
-
- private static final int MIN_PORT = 1024;
- private static final int MAX_PORT = 65535;
-
- private PortBindingUtils() {
- // No public constructor
- }
-
- public static int findAvailablePort() {
- return findAvailablePort(MIN_PORT, MAX_PORT);
- }
-
- public static int findAvailablePort(int minPort, int maxPort) {
- int port;
- do {
- port = randomPort(minPort, maxPort);
- } while (!isPortAvailable(port));
-
- return port;
- }
-
- private static int randomPort(int minPort, int maxPort) {
- int delta = maxPort - minPort;
- return ThreadLocalRandom.current().nextInt(delta) + minPort;
- }
-
- public static boolean isPortAvailable(int port) {
- try (ServerSocket serverSocket =
- ServerSocketFactory.getDefault()
- .createServerSocket(port, 1,
InetAddress.getByName("localhost"))) {
- return true;
- } catch (Exception ex) {
- return false;
- }
- }
-}
diff --git
a/flink-connectors/flink-connector-pulsar/src/test/java/org/apache/flink/connector/pulsar/testutils/runtime/mock/PulsarMockRuntime.java
b/flink-connectors/flink-connector-pulsar/src/test/java/org/apache/flink/connector/pulsar/testutils/runtime/mock/PulsarMockRuntime.java
index 552ce42..b6f8aa4 100644
---
a/flink-connectors/flink-connector-pulsar/src/test/java/org/apache/flink/connector/pulsar/testutils/runtime/mock/PulsarMockRuntime.java
+++
b/flink-connectors/flink-connector-pulsar/src/test/java/org/apache/flink/connector/pulsar/testutils/runtime/mock/PulsarMockRuntime.java
@@ -35,7 +35,6 @@ import java.util.Optional;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static
org.apache.flink.connector.pulsar.common.utils.PulsarExceptionUtils.sneakyAdmin;
-import static
org.apache.flink.connector.pulsar.testutils.runtime.mock.PortBindingUtils.findAvailablePort;
import static org.apache.flink.util.Preconditions.checkNotNull;
/** Providing a mocked pulsar server. */
@@ -145,9 +144,9 @@ public class PulsarMockRuntime implements PulsarRuntime {
configuration.setBrokerDeleteInactiveTopicsEnabled(false);
configuration.setWebSocketServiceEnabled(false);
- // Binding Ports
- configuration.setBrokerServicePort(Optional.of(findAvailablePort()));
- configuration.setWebServicePort(Optional.of(findAvailablePort()));
+ // Use runtime dynamic ports
+ configuration.setBrokerServicePort(Optional.of(0));
+ configuration.setWebServicePort(Optional.of(0));
// Enable transaction with in memory.
configuration.setTransactionCoordinatorEnabled(true);