jsancio commented on code in PR #15859: URL: https://github.com/apache/kafka/pull/15859#discussion_r1595784042
########## raft/src/test/java/org/apache/kafka/raft/internals/VoterSetTest.java: ########## @@ -79,20 +81,79 @@ void testRemoveVoter() { ); } + @Test + void testIsVoterWithDirectoryId() { + Map<Integer, VoterSet.VoterNode> aVoterMap = voterMap(Arrays.asList(1, 2, 3), true); + VoterSet voterSet = new VoterSet(new HashMap<>(aVoterMap)); + + assertTrue(voterSet.isVoter(aVoterMap.get(1).voterKey())); + assertFalse(voterSet.isVoter(ReplicaKey.of(1, Optional.of(Uuid.randomUuid())))); + assertFalse(voterSet.isVoter(ReplicaKey.of(1, Optional.empty()))); + assertFalse( + voterSet.isVoter(ReplicaKey.of(2, aVoterMap.get(1).voterKey().directoryId())) + ); + assertFalse( + voterSet.isVoter(ReplicaKey.of(4, aVoterMap.get(1).voterKey().directoryId())) + ); + assertFalse(voterSet.isVoter(ReplicaKey.of(4, Optional.empty()))); + } + + @Test + void testIsVoterWithoutDirectoryId() { + Map<Integer, VoterSet.VoterNode> aVoterMap = voterMap(Arrays.asList(1, 2, 3), false); + VoterSet voterSet = new VoterSet(new HashMap<>(aVoterMap)); + + assertTrue(voterSet.isVoter(ReplicaKey.of(1, Optional.empty()))); + assertTrue(voterSet.isVoter(ReplicaKey.of(1, Optional.of(Uuid.randomUuid())))); + assertFalse(voterSet.isVoter(ReplicaKey.of(4, Optional.of(Uuid.randomUuid())))); + assertFalse(voterSet.isVoter(ReplicaKey.of(4, Optional.empty()))); + } + + @Test + void testStandaloneAndOnlyVoter() { + Map<Integer, VoterSet.VoterNode> aVoterMap = voterMap(Arrays.asList(1), true); + VoterSet voterSet = new VoterSet(new HashMap<>(aVoterMap)); + + assertTrue(voterSet.isOnlyVoter(aVoterMap.get(1).voterKey())); + assertFalse(voterSet.isOnlyVoter(ReplicaKey.of(1, Optional.of(Uuid.randomUuid())))); + assertFalse(voterSet.isOnlyVoter(ReplicaKey.of(1, Optional.empty()))); + assertFalse( + voterSet.isOnlyVoter(ReplicaKey.of(4, aVoterMap.get(1).voterKey().directoryId())) + ); + assertFalse(voterSet.isOnlyVoter(ReplicaKey.of(4, Optional.empty()))); + } + + @Test + void testOnlyVoter() { Review Comment: Fair. I renamed it to `testNotStandaloneAndIsOnlyVoter`. I mean to the behavior of `isOnlyVoter` when there are more than one voter in the set of voters. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org