mumrah commented on code in PR #14784: URL: https://github.com/apache/kafka/pull/14784#discussion_r1399331512
########## clients/src/main/java/org/apache/kafka/common/requests/BrokerRegistrationRequest.java: ########## @@ -45,6 +45,10 @@ public short oldestAllowedVersion() { @Override public BrokerRegistrationRequest build(short version) { + if (version < 2) { + // Reset the PreviousBrokerEpoch to default if not supported. + data.setPreviousBrokerEpoch(new BrokerRegistrationRequestData().previousBrokerEpoch()); Review Comment: This stuck me as a little backwards. Usually in request builders we will only set a field if it's supported at the version, e.g. ``` if (version >= 2) data.setPreviousBrokerEpoch ``` but I see we're not really using the builder pattern in BrokerRegistrationRequest. The caller is just creating the BrokerRegistrationRequestData directly and passing it into this builer. This fix is okay for now, I'll file a follow-up JIRA to refactor this builder class a bit ########## clients/src/test/java/org/apache/kafka/common/requests/BrokerRegistrationRequestTest.java: ########## @@ -0,0 +1,61 @@ +/* + * 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.kafka.common.requests; + +import org.apache.kafka.common.Uuid; +import org.apache.kafka.common.message.BrokerRegistrationRequestData; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class BrokerRegistrationRequestTest { + private static Stream<Arguments> BrokerRegistrationRequestVersions() { + return IntStream.range(BrokerRegistrationRequestData.LOWEST_SUPPORTED_VERSION, BrokerRegistrationRequestData.HIGHEST_SUPPORTED_VERSION + 1).mapToObj(version -> Arguments.of((short) version)); Review Comment: nit: break up this long line -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org