You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "masonyc (via GitHub)" <gi...@apache.org> on 2024/07/23 04:20:56 UTC
[PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
masonyc opened a new pull request, #16659:
URL: https://github.com/apache/kafka/pull/16659
Add tests to test all the public methods for class raft/Endpoints.java
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "masonyc (via GitHub)" <gi...@apache.org>.
masonyc commented on code in PR #16659:
URL: https://github.com/apache/kafka/pull/16659#discussion_r1689240352
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
Review Comment:
updated
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
Review Comment:
updated
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
Review Comment:
merged to `testSize()`, also merged `testIsEmpty()`
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
Review Comment:
updated
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "masonyc (via GitHub)" <gi...@apache.org>.
masonyc commented on code in PR #16659:
URL: https://github.com/apache/kafka/pull/16659#discussion_r1689240908
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ ListenerName listener = ListenerName.normalised("listener");
+ ListenerName listener1 = ListenerName.normalised("listener1");
+ InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 9092);
+ InetSocketAddress address1 = InetSocketAddress.createUnresolved("localhost", 9093);
+ endpointMap.put(listener, address);
+ endpointMap.put(listener1, address1);
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ String expectedString = String.format(
+ "Endpoints(endpoints={%s=%s, %s=%s})",
+ listener,
+ address,
+ listener1,
+ address1
+ );
+
+ assertEquals(expectedString, endpoints.toString());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(1, leaderEndpoints.size());
+
+ Iterator<BeginQuorumEpochRequestData.LeaderEndpoint> iterator = leaderEndpoints.iterator();
+ BeginQuorumEpochRequestData.LeaderEndpoint endpoint = iterator.next();
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(0, leaderEndpoints.size());
+ }
+
+ @Test
+ void testEmpty() {
+ Endpoints emptyEndpoints = Endpoints.empty();
+
+ assertEquals(Endpoints.fromInetSocketAddresses(Collections.emptyMap()), emptyEndpoints);
+ }
+
+ @Test
+ void testFromInetSocketAddressesWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(1, endpoints.size());
+ }
+
+ @Test
+ void testFromVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ List<VotersRecord.Endpoint> votersEndpoints = new ArrayList<>();
+ votersEndpoints.add(
+ new VotersRecord.Endpoint()
+ .setName("listener")
+ .setHost("localhost")
+ .setPort(9092)
+ );
+
+ Endpoints createdEndpoints = Endpoints.fromVotersRecordEndpoints(votersEndpoints);
+
+ assertEquals(endpoints, createdEndpoints);
+ }
+
+ @Test
+ void testFromVotersRecordEndpointsWithEmptyEndpoint() {
+ List<VotersRecord.Endpoint> votersEndpoints = new ArrayList<>();
Review Comment:
updated
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "masonyc (via GitHub)" <gi...@apache.org>.
masonyc commented on PR #16659:
URL: https://github.com/apache/kafka/pull/16659#issuecomment-2247049018
Thanks for the feedback @OmniaGM , I have updated code to address most issues in comments. Regarding hashcode() & toString() methods, I feel like there is a need to make sure they work as we expected. Happy to remove them if I am on the wrong direction.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "masonyc (via GitHub)" <gi...@apache.org>.
masonyc commented on PR #16659:
URL: https://github.com/apache/kafka/pull/16659#issuecomment-2258239927
Thanks for the feedback @OmniaGM , updated to address the latest comments as well.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe merged PR #16659:
URL: https://github.com/apache/kafka/pull/16659
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "OmniaGM (via GitHub)" <gi...@apache.org>.
OmniaGM commented on code in PR #16659:
URL: https://github.com/apache/kafka/pull/16659#discussion_r1689425703
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
Review Comment:
I don't see `toString` has any impact to be tested in the context of this class. We do test `toString` for example for metrics related code because it has an impact but this one not that much. If you checked the code you will see that we don't actively testing `toString`
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "masonyc (via GitHub)" <gi...@apache.org>.
masonyc commented on code in PR #16659:
URL: https://github.com/apache/kafka/pull/16659#discussion_r1689562688
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
Review Comment:
removed
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "OmniaGM (via GitHub)" <gi...@apache.org>.
OmniaGM commented on code in PR #16659:
URL: https://github.com/apache/kafka/pull/16659#discussion_r1688336616
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
Review Comment:
BTW we have `Utils.mkMap` that can be used to define this in one statement instead of two
```
Utils.mkMap` that can be used to define like
`Utils.mkMap(Utils.mkEntry(ListenerName.normalised("listener"),InetSocketAddress.createUnresolved("localhost", 9092)));
```
or use simple java
```
new HashMap<>() {{
put(ListenerName.normalised("listener"), InetSocketAddress.createUnresolved("localhost", 9092));
```
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
Review Comment:
Maybe we can combine these two lines to `assertEquals(0, Endpoints.empty().size());` and drop size variable
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ ListenerName listener = ListenerName.normalised("listener");
+ ListenerName listener1 = ListenerName.normalised("listener1");
+ InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 9092);
+ InetSocketAddress address1 = InetSocketAddress.createUnresolved("localhost", 9093);
+ endpointMap.put(listener, address);
+ endpointMap.put(listener1, address1);
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ String expectedString = String.format(
+ "Endpoints(endpoints={%s=%s, %s=%s})",
+ listener,
+ address,
+ listener1,
+ address1
+ );
+
+ assertEquals(expectedString, endpoints.toString());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(1, leaderEndpoints.size());
+
+ Iterator<BeginQuorumEpochRequestData.LeaderEndpoint> iterator = leaderEndpoints.iterator();
+ BeginQuorumEpochRequestData.LeaderEndpoint endpoint = iterator.next();
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(0, leaderEndpoints.size());
Review Comment:
`leaderEndpoints` in the assert can be replaced by its value `endpoints.toBeginQuorumEpochRequest()`
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
Review Comment:
Also `ListenerName.normalised("listener")` and `InetSocketAddress.createUnresolved("localhost", 9092)` seem to be duplicated in every test maybe we can define them on top of the test.
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
Review Comment:
What the value of testing `toString`? what public interfaces will `toString` impact if it change to any other string?
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
Review Comment:
the assert and endpoints variable line can be merged into one line `assertFalse(Endpoints.fromInetSocketAddresses(endpointMap).isEmpty());`
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
Review Comment:
Am not sure what the value of this test? can you explain it a bit as I recall we rarely test `hashCode` method.
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ ListenerName listener = ListenerName.normalised("listener");
+ ListenerName listener1 = ListenerName.normalised("listener1");
+ InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 9092);
+ InetSocketAddress address1 = InetSocketAddress.createUnresolved("localhost", 9093);
+ endpointMap.put(listener, address);
+ endpointMap.put(listener1, address1);
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ String expectedString = String.format(
+ "Endpoints(endpoints={%s=%s, %s=%s})",
+ listener,
+ address,
+ listener1,
+ address1
+ );
+
+ assertEquals(expectedString, endpoints.toString());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(1, leaderEndpoints.size());
+
+ Iterator<BeginQuorumEpochRequestData.LeaderEndpoint> iterator = leaderEndpoints.iterator();
+ BeginQuorumEpochRequestData.LeaderEndpoint endpoint = iterator.next();
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(0, leaderEndpoints.size());
+ }
+
+ @Test
+ void testEmpty() {
+ Endpoints emptyEndpoints = Endpoints.empty();
+
+ assertEquals(Endpoints.fromInetSocketAddresses(Collections.emptyMap()), emptyEndpoints);
+ }
+
+ @Test
+ void testFromInetSocketAddressesWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(1, endpoints.size());
+ }
+
+ @Test
+ void testFromVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ List<VotersRecord.Endpoint> votersEndpoints = new ArrayList<>();
+ votersEndpoints.add(
+ new VotersRecord.Endpoint()
+ .setName("listener")
+ .setHost("localhost")
+ .setPort(9092)
+ );
+
+ Endpoints createdEndpoints = Endpoints.fromVotersRecordEndpoints(votersEndpoints);
+
+ assertEquals(endpoints, createdEndpoints);
+ }
+
+ @Test
+ void testFromVotersRecordEndpointsWithEmptyEndpoint() {
+ List<VotersRecord.Endpoint> votersEndpoints = new ArrayList<>();
Review Comment:
Can't `votersEndpoints` be `Collections.emptyList` instead? Then `createdEndpoints` can be `Endpoints.fromVotersRecordEndpoints(Collections.emptyList());`
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ ListenerName listener = ListenerName.normalised("listener");
+ ListenerName listener1 = ListenerName.normalised("listener1");
+ InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 9092);
+ InetSocketAddress address1 = InetSocketAddress.createUnresolved("localhost", 9093);
+ endpointMap.put(listener, address);
+ endpointMap.put(listener1, address1);
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ String expectedString = String.format(
+ "Endpoints(endpoints={%s=%s, %s=%s})",
+ listener,
+ address,
+ listener1,
+ address1
+ );
+
+ assertEquals(expectedString, endpoints.toString());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(1, leaderEndpoints.size());
+
+ Iterator<BeginQuorumEpochRequestData.LeaderEndpoint> iterator = leaderEndpoints.iterator();
+ BeginQuorumEpochRequestData.LeaderEndpoint endpoint = iterator.next();
Review Comment:
maybe better name here is `leaderEndpoint`? as `endpoints` above was referring to `Endpoints`
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
Review Comment:
I can see that we keep calling `ListenerName.normalised("listener")` once for `endpointMap` and second time to asset the `ListenerName::value` or to pass it to `Endpoints::address`. Why not extract it to a variable at the beginning of the test? same can go to `InetSocketAddress.createUnresolved("localhost", 9092)`
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ ListenerName listener = ListenerName.normalised("listener");
+ ListenerName listener1 = ListenerName.normalised("listener1");
+ InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 9092);
+ InetSocketAddress address1 = InetSocketAddress.createUnresolved("localhost", 9093);
+ endpointMap.put(listener, address);
+ endpointMap.put(listener1, address1);
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ String expectedString = String.format(
+ "Endpoints(endpoints={%s=%s, %s=%s})",
+ listener,
+ address,
+ listener1,
+ address1
+ );
+
+ assertEquals(expectedString, endpoints.toString());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(1, leaderEndpoints.size());
+
+ Iterator<BeginQuorumEpochRequestData.LeaderEndpoint> iterator = leaderEndpoints.iterator();
+ BeginQuorumEpochRequestData.LeaderEndpoint endpoint = iterator.next();
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(0, leaderEndpoints.size());
+ }
+
+ @Test
+ void testEmpty() {
+ Endpoints emptyEndpoints = Endpoints.empty();
+
+ assertEquals(Endpoints.fromInetSocketAddresses(Collections.emptyMap()), emptyEndpoints);
Review Comment:
What is the value of this test if we are testing `Endpoints::size`?
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
Review Comment:
I feel `testSizeWithOneEndpoint` and `testSizeWithEmptyEndpoint` can be merged into one test and `assertEquals(1, Endpoints.fromInetSocketAddresses(endpointMap).size());`
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on PR #16659:
URL: https://github.com/apache/kafka/pull/16659#issuecomment-2299840543
Thanks, @masonyc . This looks good! And thanks to @OmniaGM for reviewing the first versions. LGTM.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "masonyc (via GitHub)" <gi...@apache.org>.
masonyc commented on PR #16659:
URL: https://github.com/apache/kafka/pull/16659#issuecomment-2268919709
Hi @OmniaGM @jsancio please take another look when free, thanks.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "masonyc (via GitHub)" <gi...@apache.org>.
masonyc commented on code in PR #16659:
URL: https://github.com/apache/kafka/pull/16659#discussion_r1689562407
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ ListenerName listener = ListenerName.normalised("listener");
+ ListenerName listener1 = ListenerName.normalised("listener1");
+ InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 9092);
+ InetSocketAddress address1 = InetSocketAddress.createUnresolved("localhost", 9093);
+ endpointMap.put(listener, address);
+ endpointMap.put(listener1, address1);
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ String expectedString = String.format(
+ "Endpoints(endpoints={%s=%s, %s=%s})",
+ listener,
+ address,
+ listener1,
+ address1
+ );
+
+ assertEquals(expectedString, endpoints.toString());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(1, leaderEndpoints.size());
+
+ Iterator<BeginQuorumEpochRequestData.LeaderEndpoint> iterator = leaderEndpoints.iterator();
+ BeginQuorumEpochRequestData.LeaderEndpoint endpoint = iterator.next();
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(0, leaderEndpoints.size());
+ }
+
+ @Test
+ void testEmpty() {
+ Endpoints emptyEndpoints = Endpoints.empty();
+
+ assertEquals(Endpoints.fromInetSocketAddresses(Collections.emptyMap()), emptyEndpoints);
Review Comment:
Removed
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on code in PR #16659:
URL: https://github.com/apache/kafka/pull/16659#discussion_r1724025225
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
Review Comment:
Seems reasonable to test `equals`
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "OmniaGM (via GitHub)" <gi...@apache.org>.
OmniaGM commented on code in PR #16659:
URL: https://github.com/apache/kafka/pull/16659#discussion_r1689421639
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ ListenerName listener = ListenerName.normalised("listener");
+ ListenerName listener1 = ListenerName.normalised("listener1");
+ InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 9092);
+ InetSocketAddress address1 = InetSocketAddress.createUnresolved("localhost", 9093);
+ endpointMap.put(listener, address);
+ endpointMap.put(listener1, address1);
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ String expectedString = String.format(
+ "Endpoints(endpoints={%s=%s, %s=%s})",
+ listener,
+ address,
+ listener1,
+ address1
+ );
+
+ assertEquals(expectedString, endpoints.toString());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(1, leaderEndpoints.size());
+
+ Iterator<BeginQuorumEpochRequestData.LeaderEndpoint> iterator = leaderEndpoints.iterator();
+ BeginQuorumEpochRequestData.LeaderEndpoint endpoint = iterator.next();
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(0, leaderEndpoints.size());
+ }
+
+ @Test
+ void testEmpty() {
+ Endpoints emptyEndpoints = Endpoints.empty();
+
+ assertEquals(Endpoints.fromInetSocketAddresses(Collections.emptyMap()), emptyEndpoints);
Review Comment:
I feel it is redundant
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "masonyc (via GitHub)" <gi...@apache.org>.
masonyc commented on PR #16659:
URL: https://github.com/apache/kafka/pull/16659#issuecomment-2258003845
Hi @jsancio @OmniaGM , could you please have a look at the updated pr when free? Thanks.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "OmniaGM (via GitHub)" <gi...@apache.org>.
OmniaGM commented on code in PR #16659:
URL: https://github.com/apache/kafka/pull/16659#discussion_r1696734269
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,367 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+import org.apache.kafka.common.utils.Utils;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ private ListenerName testListener = ListenerName.normalised("listener");
+ private InetSocketAddress testSocketAddress = InetSocketAddress.createUnresolved("localhost", 9092);
+
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = Utils.mkMap(
+ Utils.mkEntry(testListener, testSocketAddress));
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(testListener);
+
+ assertEquals(Optional.of(testSocketAddress), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = Utils.mkMap(
+ Utils.mkEntry(testListener, testSocketAddress));
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ VotersRecord.Endpoint endpoint = endpoints.votersRecordEndpoints().next();
+
+ assertEquals(testListener.value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertFalse(endpoints.votersRecordEndpoints().hasNext());
Review Comment:
This test can be one line `assertFalse(Endpoints.empty().votersRecordEndpoints().hasNext());`
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,367 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+import org.apache.kafka.common.utils.Utils;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ private ListenerName testListener = ListenerName.normalised("listener");
+ private InetSocketAddress testSocketAddress = InetSocketAddress.createUnresolved("localhost", 9092);
+
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = Utils.mkMap(
+ Utils.mkEntry(testListener, testSocketAddress));
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(testListener);
+
+ assertEquals(Optional.of(testSocketAddress), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = Utils.mkMap(
+ Utils.mkEntry(testListener, testSocketAddress));
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ VotersRecord.Endpoint endpoint = endpoints.votersRecordEndpoints().next();
+
+ assertEquals(testListener.value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertFalse(endpoints.votersRecordEndpoints().hasNext());
+ }
+
+ @Test
+ void testSize() {
+ Map<ListenerName, InetSocketAddress> endpointMap = Utils.mkMap(
+ Utils.mkEntry(testListener, testSocketAddress));
+
+ assertEquals(1, Endpoints.fromInetSocketAddresses(endpointMap).size());
+ assertEquals(0, Endpoints.empty().size());
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = Utils.mkMap(
+ Utils.mkEntry(testListener, testSocketAddress));
+
+ assertFalse(Endpoints.fromInetSocketAddresses(endpointMap).isEmpty());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = Utils.mkMap(
+ Utils.mkEntry(testListener, testSocketAddress));
+
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = Utils.mkMap(
+ Utils.mkEntry(testListener, testSocketAddress));
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = Utils.mkMap(
+ Utils.mkEntry(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)));
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = Utils.mkMap(
+ Utils.mkEntry(testListener, testSocketAddress));
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(1, leaderEndpoints.size());
+
+ BeginQuorumEpochRequestData.LeaderEndpoint leaderEndpoint = leaderEndpoints.iterator().next();
+ assertEquals(testListener.value(), leaderEndpoint.name());
+ assertEquals("localhost", leaderEndpoint.host());
+ assertEquals(9092, leaderEndpoint.port());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.toBeginQuorumEpochRequest().size());
Review Comment:
same `assertEquals(0, Endpoints.empty().toBeginQuorumEpochRequest().size());`
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on PR #16659:
URL: https://github.com/apache/kafka/pull/16659#issuecomment-2276941493
Thanks for the review @OmniaGM and the PR @masonyc . I take a look tomorrow.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "masonyc (via GitHub)" <gi...@apache.org>.
masonyc commented on PR #16659:
URL: https://github.com/apache/kafka/pull/16659#issuecomment-2292596008
Thanks @jsancio @OmniaGM for looking into it. Please let me know if I need to update anything.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17169: Add an EndpointsTest suite that test all of the public methods [kafka]
Posted by "masonyc (via GitHub)" <gi...@apache.org>.
masonyc commented on code in PR #16659:
URL: https://github.com/apache/kafka/pull/16659#discussion_r1689240668
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
Review Comment:
Don't we need to make sure the overridden `equals()` method performs correctly? Happy to remove it is not needed.
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
Review Comment:
Was thinking it is a good idea to make sure it conforms to the overridden format. Happy to remove it if needed.
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ ListenerName listener = ListenerName.normalised("listener");
+ ListenerName listener1 = ListenerName.normalised("listener1");
+ InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 9092);
+ InetSocketAddress address1 = InetSocketAddress.createUnresolved("localhost", 9093);
+ endpointMap.put(listener, address);
+ endpointMap.put(listener1, address1);
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ String expectedString = String.format(
+ "Endpoints(endpoints={%s=%s, %s=%s})",
+ listener,
+ address,
+ listener1,
+ address1
+ );
+
+ assertEquals(expectedString, endpoints.toString());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(1, leaderEndpoints.size());
+
+ Iterator<BeginQuorumEpochRequestData.LeaderEndpoint> iterator = leaderEndpoints.iterator();
+ BeginQuorumEpochRequestData.LeaderEndpoint endpoint = iterator.next();
Review Comment:
updated
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ ListenerName listener = ListenerName.normalised("listener");
+ ListenerName listener1 = ListenerName.normalised("listener1");
+ InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 9092);
+ InetSocketAddress address1 = InetSocketAddress.createUnresolved("localhost", 9093);
+ endpointMap.put(listener, address);
+ endpointMap.put(listener1, address1);
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ String expectedString = String.format(
+ "Endpoints(endpoints={%s=%s, %s=%s})",
+ listener,
+ address,
+ listener1,
+ address1
+ );
+
+ assertEquals(expectedString, endpoints.toString());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(1, leaderEndpoints.size());
+
+ Iterator<BeginQuorumEpochRequestData.LeaderEndpoint> iterator = leaderEndpoints.iterator();
+ BeginQuorumEpochRequestData.LeaderEndpoint endpoint = iterator.next();
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(0, leaderEndpoints.size());
Review Comment:
updated
##########
raft/src/test/java/org/apache/kafka/raft/EndpointsTest.java:
##########
@@ -0,0 +1,489 @@
+/*
+ * 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.message.BeginQuorumEpochRequestData;
+import org.apache.kafka.common.message.BeginQuorumEpochResponseData;
+import org.apache.kafka.common.message.EndQuorumEpochRequestData;
+import org.apache.kafka.common.message.EndQuorumEpochResponseData;
+import org.apache.kafka.common.message.FetchResponseData;
+import org.apache.kafka.common.message.FetchSnapshotResponseData;
+import org.apache.kafka.common.message.VoteResponseData;
+import org.apache.kafka.common.message.VotersRecord;
+import org.apache.kafka.common.network.ListenerName;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+final class EndpointsTest {
+ @Test
+ void testAddressWithValidEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("listener"));
+
+ assertEquals(Optional.of(InetSocketAddress.createUnresolved("localhost", 9092)), address);
+ }
+
+ @Test
+ void testAddressWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Optional<InetSocketAddress> address = endpoints.address(ListenerName.normalised("nonExistentListener"));
+
+ assertEquals(Optional.empty(), address);
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ VotersRecord.Endpoint endpoint = iterator.next();
+
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testVotersRecordEndpointsWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ Iterator<VotersRecord.Endpoint> iterator = endpoints.votersRecordEndpoints();
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ void testSizeWithOneEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ int size = endpoints.size();
+
+ assertEquals(1, size);
+ }
+
+ @Test
+ void testSizeWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ int size = endpoints.size();
+
+ assertEquals(0, size);
+ }
+
+ @Test
+ void testIsEmptyWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertFalse(endpoints.isEmpty());
+ }
+
+ @Test
+ void testIsEmptyWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ assertEquals(0, endpoints.size());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithSameEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Endpoints sameEndpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ assertEquals(endpoints, sameEndpoints);
+ assertEquals(endpoints.hashCode(), sameEndpoints.hashCode());
+ }
+
+ @Test
+ void testEqualsAndHashCodeWithDifferentEndpoints() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ Map<ListenerName, InetSocketAddress> anotherEndpointMap = new HashMap<>();
+ anotherEndpointMap.put(
+ ListenerName.normalised("another"),
+ InetSocketAddress.createUnresolved("localhost", 9093)
+ );
+ Endpoints differentEndpoints = Endpoints.fromInetSocketAddresses(anotherEndpointMap);
+
+ assertNotEquals(endpoints, differentEndpoints);
+ assertNotEquals(endpoints.hashCode(), differentEndpoints.hashCode());
+ }
+
+ @Test
+ void testToString() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ ListenerName listener = ListenerName.normalised("listener");
+ ListenerName listener1 = ListenerName.normalised("listener1");
+ InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 9092);
+ InetSocketAddress address1 = InetSocketAddress.createUnresolved("localhost", 9093);
+ endpointMap.put(listener, address);
+ endpointMap.put(listener1, address1);
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ String expectedString = String.format(
+ "Endpoints(endpoints={%s=%s, %s=%s})",
+ listener,
+ address,
+ listener1,
+ address1
+ );
+
+ assertEquals(expectedString, endpoints.toString());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEndpoint() {
+ Map<ListenerName, InetSocketAddress> endpointMap = new HashMap<>();
+ endpointMap.put(
+ ListenerName.normalised("listener"),
+ InetSocketAddress.createUnresolved("localhost", 9092)
+ );
+ Endpoints endpoints = Endpoints.fromInetSocketAddresses(endpointMap);
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(1, leaderEndpoints.size());
+
+ Iterator<BeginQuorumEpochRequestData.LeaderEndpoint> iterator = leaderEndpoints.iterator();
+ BeginQuorumEpochRequestData.LeaderEndpoint endpoint = iterator.next();
+ assertEquals(ListenerName.normalised("listener").value(), endpoint.name());
+ assertEquals("localhost", endpoint.host());
+ assertEquals(9092, endpoint.port());
+ }
+
+ @Test
+ void testToBeginQuorumEpochRequestWithEmptyEndpoint() {
+ Endpoints endpoints = Endpoints.empty();
+
+ BeginQuorumEpochRequestData.LeaderEndpointCollection leaderEndpoints = endpoints.toBeginQuorumEpochRequest();
+
+ assertEquals(0, leaderEndpoints.size());
+ }
+
+ @Test
+ void testEmpty() {
+ Endpoints emptyEndpoints = Endpoints.empty();
+
+ assertEquals(Endpoints.fromInetSocketAddresses(Collections.emptyMap()), emptyEndpoints);
Review Comment:
My thought was we want to test around if object returned from `empty()` matches the object from `initialization with Collection.emptyMap()` . Happy to remove it if you think its redundant.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org