kevin-wu24 commented on code in PR #22505:
URL: https://github.com/apache/kafka/pull/22505#discussion_r3383614941
##########
raft/src/test/java/org/apache/kafka/raft/KafkaNetworkChannelTest.java:
##########
@@ -234,27 +235,32 @@ public void testFetchRequestDowngrade(short version) {
}
}
- private RaftRequest.Outbound sendTestRequest(ApiKeys apiKey, Node
destination) {
+ record SendRequestResult(RaftRequest.Outbound request,
CompletionStage<RaftResponse.Inbound> stage) { }
+
+ private SendRequestResult sendTestRequest(ApiKeys apiKey, Node
destination) {
int correlationId = channel.newCorrelationId();
long createdTimeMs = time.milliseconds();
ApiMessage apiRequest = buildTestRequest(apiKey);
- RaftRequest.Outbound request = new RaftRequest.Outbound(
+ var request = new RaftRequest.Outbound(
Review Comment:
Another minor comment, but what do you think about using `final var` since
java does not have `val` like scala`? I remember in some PRs I wrote in the
past that it would be nice to establish that pattern for readability.
##########
raft/src/test/java/org/apache/kafka/raft/internals/ChangeVoterHandlerStateTest.java:
##########
@@ -0,0 +1,437 @@
+/*
+ * 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.internals;
+
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.common.message.AddRaftVoterResponseData;
+import org.apache.kafka.common.message.RemoveRaftVoterResponseData;
+import org.apache.kafka.common.metrics.KafkaMetric;
+import org.apache.kafka.common.metrics.Metrics;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.common.utils.MockTime;
+import org.apache.kafka.raft.Endpoints;
+import org.apache.kafka.raft.ReplicaKey;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ChangeVoterHandlerStateTest {
+
+ private KafkaMetric getMetric(Metrics metrics, String name) {
+ return metrics.metrics().get(metrics.metricName(name, "raft-metrics"));
+ }
+
+ @Test
+ public void testAddVoterLifecycle() {
Review Comment:
This is not in-scope for this PR, but I wanted to ask, since I had this
thought when initially looking at `ChangeVoterHandlerState` and these unit
tests make me feel stronger about it. I feel like `AddVoterHandlerState` and
`RemoveVoterHandlerState` is essentially duplication and could be modeled
better.
The thing that stands out to me is why do we have two separate `State`
objects to represent a "pending operation," of which the leader can only have
one. What do you think? If you agree I'll file a JIRA to clean this up in the
future.
--
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]