-
Notifications
You must be signed in to change notification settings - Fork 14.8k
KAFKA-18275: Restarting broker in testing should use the same port #18381
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
Conversation
|
|
||
| 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); |
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.
This PR depends #18337
| 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); | ||
| } | ||
|
|
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.
Remove this to pass the following two tests.
| Module | Test | Message | Time |
|---|---|---|---|
| ConnectWorkerIntegrationTest | testBrokerCoordinator() | org.opentest4j.AssertionFailedError: The Kafka cluster used in this test was not able to start successfully in time. If no recent changes have altered the behavior of Kafka brokers or clients, and this error is not occurring frequently, it is probably the result of the testing machine being temporarily overloaded and can be safely ignored. | 62.84s |
| ConnectWorkerIntegrationTest | testRequestTimeouts() | org.opentest4j.AssertionFailedError: The Kafka cluster used in this test was not able to start successfully in time. If no recent changes have altered the behavior of Kafka brokers or clients, and this error is not occurring frequently, it is probably the result of the testing machine being temporarily overloaded and can be safely ignored. | 60.51s |
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 comment
The 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 LISTENERS_CONFIG for them
| useFixedBrokerPort(); | ||
|
|
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
| useFixedBrokerPort(); | ||
|
|
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
84e8137 to
df01bb6
Compare
…rt-after-broker-restart
| Map<Integer, ControllerServer> controllers = new HashMap<>(); | ||
| Map<Integer, BrokerServer> brokers = new HashMap<>(); | ||
| Map<Integer, SharedServer> jointServers = new HashMap<>(); | ||
| File baseDirectory = null; | ||
| File jaasFile = null; | ||
|
|
||
| private Optional<File> maybeSetupJaasFile() throws Exception { | ||
| if (brokerSecurityProtocol.equals(SecurityProtocol.SASL_PLAINTEXT.name)) { | ||
| jaasFile = JaasUtils.writeJaasContextsToFile(Set.of( | ||
| File file = JaasUtils.writeJaasContextsToFile(Set.of( | ||
| new JaasUtils.JaasSection(JaasUtils.KAFKA_SERVER_CONTEXT_NAME, | ||
| List.of( | ||
| JaasModule.plainLoginModule( | ||
| JaasUtils.KAFKA_PLAIN_ADMIN, JaasUtils.KAFKA_PLAIN_ADMIN_PASSWORD, | ||
| JaasUtils.KAFKA_PLAIN_ADMIN, | ||
| JaasUtils.KAFKA_PLAIN_ADMIN_PASSWORD, | ||
| true, | ||
| Map.of( | ||
| JaasUtils.KAFKA_PLAIN_USER1, JaasUtils.KAFKA_PLAIN_USER1_PASSWORD, | ||
| JaasUtils.KAFKA_PLAIN_ADMIN, JaasUtils.KAFKA_PLAIN_ADMIN_PASSWORD) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| )); | ||
| JaasUtils.refreshJavaLoginConfigParam(jaasFile); | ||
| JaasUtils.refreshJavaLoginConfigParam(file); | ||
| return Optional.of(file); | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| public KafkaClusterTestKit build() throws Exception { | ||
| Map<Integer, ControllerServer> controllers = new HashMap<>(); | ||
| Map<Integer, BrokerServer> brokers = new HashMap<>(); | ||
| Map<Integer, SharedServer> jointServers = new HashMap<>(); | ||
| File baseDirectory = null; | ||
| Optional<File> jaasFile = maybeSetupJaasFile(); |
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.
This is for resolving the NComplexity error.
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.
@peterxcli thanks for this patch!
| } | ||
| } | ||
|
|
||
| @ClusterTest(types = {Type.KRAFT}, brokers = 1) |
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.
Should we test CO_KRAFT as well?
| producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); | ||
|
|
||
| try (Admin admin = cluster.admin(); | ||
| Producer<String, String> producer = cluster.producer(Utils.propsToMap(producerProps))) { |
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.
Could you please use Map.of instead?
|
@peterxcli could you please fix the conflicts? |
…rt-after-broker-restart
|
@chia7712 Resolved. PTAL, Thanks! |
…ache#18381) Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
…ache#18381) Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
Enable brokers to restart with the same port in ClusterTest.
Tests
In the newly added test
testBrokerRestart, if we don't have:to preallocate the ports for brokers, it would failed with following logs and error: