cmccabe commented on code in PR #14306: URL: https://github.com/apache/kafka/pull/14306#discussion_r1312363063
########## core/src/test/scala/unit/kafka/server/ControllerRegistrationManagerTest.scala: ########## @@ -0,0 +1,272 @@ +/** + * 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 kafka.server + +import org.apache.kafka.common.{Node, Uuid} +import org.apache.kafka.common.message.ControllerRegistrationResponseData +import org.apache.kafka.common.metadata.{FeatureLevelRecord, RegisterControllerRecord} +import org.apache.kafka.common.protocol.Errors +import org.apache.kafka.common.requests.ControllerRegistrationResponse +import org.apache.kafka.common.utils.{ExponentialBackoff, Time} +import org.apache.kafka.image.loader.{LogDeltaManifest, SnapshotManifest} +import org.apache.kafka.image.{MetadataDelta, MetadataImage, MetadataProvenance} +import org.apache.kafka.metadata.{RecordTestUtils, VersionRange} +import org.apache.kafka.raft.LeaderAndEpoch +import org.apache.kafka.server.common.MetadataVersion +import org.apache.kafka.test.TestUtils +import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue} +import org.junit.jupiter.api.{Test, Timeout} +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource + +import java.util +import java.util.{OptionalInt, Properties} +import java.util.concurrent.{CompletableFuture, TimeUnit} + +@Timeout(value = 60) +class ControllerRegistrationManagerTest { + private val controller1 = new Node(1, "localhost", 7000) + + private def configProperties = { + val properties = new Properties() + properties.setProperty(KafkaConfig.LogDirsProp, "/tmp/foo") + properties.setProperty(KafkaConfig.ProcessRolesProp, "controller") + properties.setProperty(KafkaConfig.ListenerSecurityProtocolMapProp, s"CONTROLLER:PLAINTEXT") + properties.setProperty(KafkaConfig.ListenersProp, s"CONTROLLER://localhost:0") + properties.setProperty(KafkaConfig.ControllerListenerNamesProp, "CONTROLLER") + properties.setProperty(KafkaConfig.NodeIdProp, "1") + properties.setProperty(KafkaConfig.QuorumVotersProp, s"1@localhost:8000,2@localhost:5000,3@localhost:7000") + properties + } + + private def createSupportedFeatures( + highestSupportedMetadataVersion: MetadataVersion + ): java.util.Map[String, VersionRange] = { + val results = new util.HashMap[String, VersionRange]() + results.put(MetadataVersion.FEATURE_NAME, VersionRange.of( + MetadataVersion.MINIMUM_KRAFT_VERSION.featureLevel(), + highestSupportedMetadataVersion.featureLevel())) + results + } + + private def newControllerRegistrationManager( + context: RegistrationTestContext, + ): ControllerRegistrationManager = { + new ControllerRegistrationManager(context.config, + context.clusterId, + Time.SYSTEM, + "controller-registration-manager-test-", + createSupportedFeatures(MetadataVersion.IBP_3_6_IV2), + RecordTestUtils.createTestControllerRegistration(1, false).incarnationId(), + new ExponentialBackoff(1, 2, 100, 0.02)) + } + + private def registered(manager: ControllerRegistrationManager): Boolean = { + val registered = new CompletableFuture[Boolean] + manager.eventQueue.append(() => { + registered.complete(manager.registered) + }) + registered.get(30, TimeUnit.SECONDS) + } + + private def rpcStats(manager: ControllerRegistrationManager): (Long, Long, Long) = { + val failedAttempts = new CompletableFuture[(Long, Long, Long)] Review Comment: number of times we've tried to send an RPC and failed for some reason (or gotten back an error code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
