RaftActorContextImpl implements RaftActorContext { @Override public String getPeerAddress(final String peerId) { String peerAddress; PeerInfo peerInfo = peerInfoMap.get(peerId); if (peerInfo != null) { peerAddress = peerInfo.getAddress(); if (peerAddress == null) { peerAddress = configParams.getPeerAddressResolver().resolve(peerId); peerInfo.setAddress(peerAddress); } } else { peerAddress = configParams.getPeerAddressResolver().resolve(peerId); } return peerAddress; } RaftActorContextImpl(final ActorRef actor, final ActorContext context, final String id,
            final @NonNull ElectionTerm termInformation, final long commitIndex, final long lastApplied,
            final @NonNull Map<String, String> peerAddresses,
            final @NonNull ConfigParams configParams, final @NonNull DataPersistenceProvider persistenceProvider,
            final @NonNull Consumer<ApplyState> applyStateConsumer, final @NonNull Logger logger,
            final @NonNull Executor executor); @VisibleForTesting void setPayloadVersion(final short payloadVersion); @Override short getPayloadVersion(); void setConfigParams(final ConfigParams configParams); @Override ActorRef actorOf(final Props props); @Override ActorSelection actorSelection(final String path); @Override String getId(); @Override ActorRef getActor(); @Override final Executor getExecutor(); @Override @SuppressWarnings("checkstyle:IllegalCatch") Optional<Cluster> getCluster(); @Override ElectionTerm getTermInformation(); @Override long getCommitIndex(); @Override void setCommitIndex(final long commitIndex); @Override long getLastApplied(); @Override void setLastApplied(final long lastApplied); @Override void setReplicatedLog(final ReplicatedLog replicatedLog); @Override ReplicatedLog getReplicatedLog(); @Override ActorSystem getActorSystem(); @Override Logger getLogger(); @Override Collection<String> getPeerIds(); @Override Collection<PeerInfo> getPeers(); @Override PeerInfo getPeerInfo(final String peerId); @Override String getPeerAddress(final String peerId); @Override void updatePeerIds(final ServerConfigurationPayload serverConfig); @Override ConfigParams getConfigParams(); @Override void addToPeers(final String peerId, final String address, final VotingState votingState); @Override void removePeer(final String name); @Override ActorSelection getPeerActorSelection(final String peerId); @Override void setPeerAddress(final String peerId, final String peerAddress); @Override SnapshotManager getSnapshotManager(); @Override long getTotalMemory(); @Override void setTotalMemoryRetriever(final LongSupplier retriever); @Override boolean hasFollowers(); @Override DataPersistenceProvider getPersistenceProvider(); @Override RaftPolicy getRaftPolicy(); @Override boolean isDynamicServerConfigurationInUse(); @Override void setDynamicServerConfigurationInUse(); @Override ServerConfigurationPayload getPeerServerInfo(final boolean includeSelf); @Override boolean isVotingMember(); @Override boolean anyVotingPeers(); @Override RaftActorBehavior getCurrentBehavior(); @Override Consumer<ApplyState> getApplyStateConsumer(); @Override FileBackedOutputStreamFactory getFileBackedOutputStreamFactory(); @Override RaftActorLeadershipTransferCohort getRaftActorLeadershipTransferCohort(); @Override @SuppressWarnings("checkstyle:hiddenField") void setRaftActorLeadershipTransferCohort(final RaftActorLeadershipTransferCohort leadershipTransferCohort);  }
@Test public void testGetPeerAddress() { Map<String, String> peerMap = new HashMap<>(); peerMap.put("peer1", "peerAddress1"); peerMap.put("peer2", null); DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl(); RaftActorContextImpl context = new RaftActorContextImpl(actor, actor.underlyingActor().getContext(), "test", new ElectionTermImpl(createProvider(), "test", LOG), -1, -1, peerMap, configParams, createProvider(), applyState -> { }, LOG, MoreExecutors.directExecutor()); assertEquals("getPeerAddress", "peerAddress1", context.getPeerAddress("peer1")); assertEquals("getPeerAddress", null, context.getPeerAddress("peer2")); PeerAddressResolver mockResolver = mock(PeerAddressResolver.class); doReturn("peerAddress2").when(mockResolver).resolve("peer2"); doReturn("peerAddress3").when(mockResolver).resolve("peer3"); configParams.setPeerAddressResolver(mockResolver); assertEquals("getPeerAddress", "peerAddress2", context.getPeerAddress("peer2")); assertEquals("getPeerAddress", "peerAddress3", context.getPeerAddress("peer3")); reset(mockResolver); assertEquals("getPeerAddress", "peerAddress1", context.getPeerAddress("peer1")); assertEquals("getPeerAddress", "peerAddress2", context.getPeerAddress("peer2")); verify(mockResolver, never()).resolve(anyString()); }