zzzk1 commented on code in PR #16909: URL: https://github.com/apache/kafka/pull/16909#discussion_r1720874919
########## raft/src/main/java/org/apache/kafka/raft/Endpoints.java: ########## @@ -104,6 +105,27 @@ public BeginQuorumEpochRequestData.LeaderEndpointCollection toBeginQuorumEpochRe return leaderEndpoints; } + // mock invalid listener. + public AddRaftVoterRequestData.ListenerCollection buildTestAddVoterRequest() { + AddRaftVoterRequestData.ListenerCollection listeners = + new AddRaftVoterRequestData.ListenerCollection(endpoints.size()); + for (Map.Entry<ListenerName, InetSocketAddress> entry : endpoints.entrySet()) { + AddRaftVoterRequestData.Listener listener = new AddRaftVoterRequestData.Listener(); + listener.setName(entry.getKey().value()); + listener.setHost(entry.getValue().getHostString()); + Class<?> clazz = listener.getClass(); + try { + Field port = clazz.getDeclaredField("port"); + port.setAccessible(true); + port.setInt(listener, -1); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + listeners.add(listener); + } + return listeners; + } Review Comment: <img width="1855" alt="截屏2024-08-18 上午10 23 31" src="https://github.com/user-attachments/assets/2bbdbde8-b2d1-4796-aff5-a7d48cac6d07"> I wanted to create a `Listener` using reflection to bypass the validation in `Listener#setPort`, but when I hit the breakpoint, I noticed that the port value had changed. -- 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