-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KAFKA-18275: Restarting broker in testing should use the same port #18381
base: trunk
Are you sure you want to change the base?
Changes from all commits
3bce960
f7bb644
687af35
6849805
3f9ad3d
df01bb6
5fe5225
a7c3b70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -43,7 +43,6 @@ | |||||||||||||
import org.apache.kafka.connect.util.SinkUtils; | ||||||||||||||
import org.apache.kafka.connect.util.clusters.EmbeddedConnectCluster; | ||||||||||||||
import org.apache.kafka.connect.util.clusters.WorkerHandle; | ||||||||||||||
import org.apache.kafka.network.SocketServerConfigs; | ||||||||||||||
import org.apache.kafka.test.TestUtils; | ||||||||||||||
|
||||||||||||||
import org.junit.jupiter.api.AfterEach; | ||||||||||||||
|
@@ -57,8 +56,6 @@ | |||||||||||||
|
||||||||||||||
import java.io.File; | ||||||||||||||
import java.io.FileOutputStream; | ||||||||||||||
import java.io.IOException; | ||||||||||||||
import java.net.ServerSocket; | ||||||||||||||
import java.nio.file.Path; | ||||||||||||||
import java.util.Collection; | ||||||||||||||
import java.util.Collections; | ||||||||||||||
|
@@ -247,8 +244,6 @@ public void testBrokerCoordinator() throws Exception { | |||||||||||||
ConnectorHandle connectorHandle = RuntimeHandles.get().connectorHandle(CONNECTOR_NAME); | ||||||||||||||
workerProps.put(DistributedConfig.SCHEDULED_REBALANCE_MAX_DELAY_MS_CONFIG, String.valueOf(5000)); | ||||||||||||||
|
||||||||||||||
useFixedBrokerPort(); | ||||||||||||||
|
||||||||||||||
// start the clusters | ||||||||||||||
connect = connectBuilder.build(); | ||||||||||||||
connect.start(); | ||||||||||||||
|
@@ -813,8 +808,6 @@ public void testRequestTimeouts() throws Exception { | |||||||||||||
workerProps.put(SCHEDULED_REBALANCE_MAX_DELAY_MS_CONFIG, "0"); | ||||||||||||||
workerProps.put(METADATA_RECOVERY_STRATEGY_CONFIG, MetadataRecoveryStrategy.NONE.name); | ||||||||||||||
|
||||||||||||||
useFixedBrokerPort(); | ||||||||||||||
|
||||||||||||||
Comment on lines
-816
to
-817
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||||||||||||||
connect = connectBuilder | ||||||||||||||
.numWorkers(1) | ||||||||||||||
.build(); | ||||||||||||||
|
@@ -1431,23 +1424,6 @@ private Map<String, String> defaultSourceConnectorProps(String topic) { | |||||||||||||
return props; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private void useFixedBrokerPort() throws IOException { | ||||||||||||||
// Find a free port and use it in the Kafka broker's listeners config. We can't use port 0 in the listeners | ||||||||||||||
// config to get a random free port because in this test we want to stop the Kafka broker and then bring it | ||||||||||||||
// back up and listening on the same port in order to verify that the Connect cluster can re-connect to Kafka | ||||||||||||||
// and continue functioning normally. If we were to use port 0 here, the Kafka broker would most likely listen | ||||||||||||||
// on a different random free port the second time it is started. Note that we can only use the static port | ||||||||||||||
// because we have a single broker setup in this test. | ||||||||||||||
int listenerPort; | ||||||||||||||
try (ServerSocket s = new ServerSocket(0)) { | ||||||||||||||
listenerPort = s.getLocalPort(); | ||||||||||||||
} | ||||||||||||||
brokerProps.put(SocketServerConfigs.LISTENERS_CONFIG, String.format("EXTERNAL://localhost:%d,CONTROLLER://localhost:0", listenerPort)); | ||||||||||||||
connectBuilder | ||||||||||||||
.numBrokers(1) | ||||||||||||||
.brokerProps(brokerProps); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
Comment on lines
-1434
to
-1450
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this to pass the following two tests.
https://github.com/apache/kafka/actions/runs/12595111592?pr=18381 But I don't really know why, investigating... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, EmbeddedConnect uses EmbeddedKafkaCluster, and EmbeddedKafkaCluster uses KafkaClusterTestKit to build cluster, and since the brokers has assigned fixed ports in KafkaClusterTestKit, there is no need to modify the |
||||||||||||||
public static class EmptyTaskConfigsConnector extends SinkConnector { | ||||||||||||||
@Override | ||||||||||||||
public String version() { | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,18 @@ public ServerSocketChannel openServerSocket( | |
ServerSocketChannel socketChannel = getSocketForListenerAndMarkAsUsed( | ||
nodeId, | ||
listenerName); | ||
|
||
if (socketChannel != null) { | ||
if (socketChannel.isOpen()) { | ||
return socketChannel; | ||
} | ||
// bind the server socket with same port | ||
socketAddress = new InetSocketAddress(socketAddress.getHostString(), socketChannel.socket().getLocalPort()); | ||
socketChannel = ServerSocketFactory.INSTANCE.openServerSocket( | ||
listenerName, | ||
socketAddress, | ||
listenBacklogSize, | ||
recvBufferSize); | ||
Comment on lines
+52
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR depends #18337 |
||
return socketChannel; | ||
} | ||
return ServerSocketFactory.INSTANCE.openServerSocket( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto