mimaison commented on code in PR #18998: URL: https://github.com/apache/kafka/pull/18998#discussion_r1986366041
########## raft/src/test/java/org/apache/kafka/raft/QuorumConfigTest.java: ########## @@ -0,0 +1,68 @@ +/* + * 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.raft; + +import org.apache.kafka.common.config.AbstractConfig; +import org.apache.kafka.common.config.ConfigException; + +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class QuorumConfigTest { + @Test + public void testLegalConfig() { + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_ELECTION_TIMEOUT_MS_CONFIG, "0")); + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_FETCH_TIMEOUT_MS_CONFIG, "0")); + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_ELECTION_BACKOFF_MAX_MS_CONFIG, "0")); + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_LINGER_MS_CONFIG, "-1")); + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_REQUEST_TIMEOUT_MS_CONFIG, "-1")); + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_RETRY_BACKOFF_MS_CONFIG, "-1")); + } + + private void verifyLegalConfig(Map<String, Object> overrideConfig) { Review Comment: It's a bit strange to have a method called `verifyLegalConfig` but expect it to throw. ########## raft/src/test/java/org/apache/kafka/raft/QuorumConfigTest.java: ########## @@ -0,0 +1,68 @@ +/* + * 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.raft; + +import org.apache.kafka.common.config.AbstractConfig; +import org.apache.kafka.common.config.ConfigException; + +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class QuorumConfigTest { + @Test + public void testLegalConfig() { + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_ELECTION_TIMEOUT_MS_CONFIG, "0")); + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_FETCH_TIMEOUT_MS_CONFIG, "0")); + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_ELECTION_BACKOFF_MAX_MS_CONFIG, "0")); + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_LINGER_MS_CONFIG, "-1")); + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_REQUEST_TIMEOUT_MS_CONFIG, "-1")); + verifyLegalConfig(Map.of(QuorumConfig.QUORUM_RETRY_BACKOFF_MS_CONFIG, "-1")); + } + + private void verifyLegalConfig(Map<String, Object> overrideConfig) { + Map<String, Object> props = new HashMap<>(); + props.put(QuorumConfig.QUORUM_VOTERS_CONFIG, "1@localhost:9092"); + props.put(QuorumConfig.QUORUM_BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); + props.put(QuorumConfig.QUORUM_ELECTION_TIMEOUT_MS_CONFIG, "10"); + props.put(QuorumConfig.QUORUM_FETCH_TIMEOUT_MS_CONFIG, "10"); + props.put(QuorumConfig.QUORUM_ELECTION_BACKOFF_MAX_MS_CONFIG, "10"); + props.put(QuorumConfig.QUORUM_LINGER_MS_CONFIG, "10"); + props.put(QuorumConfig.QUORUM_REQUEST_TIMEOUT_MS_CONFIG, "10"); + props.put(QuorumConfig.QUORUM_RETRY_BACKOFF_MS_CONFIG, "10"); + + props.putAll(overrideConfig); + + assertThrows(ConfigException.class, () -> new QuorumConfig(new QuorumTestConfig(props))); Review Comment: Could we do something like: ``` assertThrows(ConfigException.class, () -> QuorumConfig.CONFIG_DEF.parse(props)); ``` instead of defining `QuorumTestConfig`? ########## raft/src/main/java/org/apache/kafka/raft/QuorumConfig.java: ########## @@ -102,12 +103,12 @@ public class QuorumConfig { public static final ConfigDef CONFIG_DEF = new ConfigDef() .define(QUORUM_VOTERS_CONFIG, LIST, DEFAULT_QUORUM_VOTERS, new ControllerQuorumVotersValidator(), HIGH, QUORUM_VOTERS_DOC) .define(QUORUM_BOOTSTRAP_SERVERS_CONFIG, LIST, DEFAULT_QUORUM_BOOTSTRAP_SERVERS, new ControllerQuorumBootstrapServersValidator(), HIGH, QUORUM_BOOTSTRAP_SERVERS_DOC) - .define(QUORUM_ELECTION_TIMEOUT_MS_CONFIG, INT, DEFAULT_QUORUM_ELECTION_TIMEOUT_MS, null, HIGH, QUORUM_ELECTION_TIMEOUT_MS_DOC) - .define(QUORUM_FETCH_TIMEOUT_MS_CONFIG, INT, DEFAULT_QUORUM_FETCH_TIMEOUT_MS, null, HIGH, QUORUM_FETCH_TIMEOUT_MS_DOC) - .define(QUORUM_ELECTION_BACKOFF_MAX_MS_CONFIG, INT, DEFAULT_QUORUM_ELECTION_BACKOFF_MAX_MS, null, HIGH, QUORUM_ELECTION_BACKOFF_MAX_MS_DOC) - .define(QUORUM_LINGER_MS_CONFIG, INT, DEFAULT_QUORUM_LINGER_MS, null, MEDIUM, QUORUM_LINGER_MS_DOC) - .define(QUORUM_REQUEST_TIMEOUT_MS_CONFIG, INT, DEFAULT_QUORUM_REQUEST_TIMEOUT_MS, null, MEDIUM, QUORUM_REQUEST_TIMEOUT_MS_DOC) - .define(QUORUM_RETRY_BACKOFF_MS_CONFIG, INT, DEFAULT_QUORUM_RETRY_BACKOFF_MS, null, LOW, QUORUM_RETRY_BACKOFF_MS_DOC); + .define(QUORUM_ELECTION_TIMEOUT_MS_CONFIG, INT, DEFAULT_QUORUM_ELECTION_TIMEOUT_MS, atLeast(1), HIGH, QUORUM_ELECTION_TIMEOUT_MS_DOC) + .define(QUORUM_FETCH_TIMEOUT_MS_CONFIG, INT, DEFAULT_QUORUM_FETCH_TIMEOUT_MS, atLeast(1), HIGH, QUORUM_FETCH_TIMEOUT_MS_DOC) + .define(QUORUM_ELECTION_BACKOFF_MAX_MS_CONFIG, INT, DEFAULT_QUORUM_ELECTION_BACKOFF_MAX_MS, atLeast(1), HIGH, QUORUM_ELECTION_BACKOFF_MAX_MS_DOC) Review Comment: It seems a quorum can start if this is set to 0. I'm not saying it makes sense to set it to 0 but why use `atLeast(1)` here? -- 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