RaftActorContextImpl implements RaftActorContext { @Override public void updatePeerIds(final ServerConfigurationPayload serverConfig) { votingMember = true; boolean foundSelf = false; Set<String> currentPeers = new HashSet<>(this.getPeerIds()); for (ServerInfo server : serverConfig.getServerConfig()) { if (getId().equals(server.getId())) { foundSelf = true; if (!server.isVoting()) { votingMember = false; } } else { VotingState votingState = server.isVoting() ? VotingState.VOTING : VotingState.NON_VOTING; if (!currentPeers.contains(server.getId())) { this.addToPeers(server.getId(), null, votingState); } else { this.getPeerInfo(server.getId()).setVotingState(votingState); currentPeers.remove(server.getId()); } } } for (String peerIdToRemove : currentPeers) { this.removePeer(peerIdToRemove); } if (!foundSelf) { votingMember = false; } log.debug("{}: Updated server config: isVoting: {}, peers: {}", id, votingMember, peerInfoMap.values()); setDynamicServerConfigurationInUse(); } 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 testUpdatePeerIds() { RaftActorContextImpl context = new RaftActorContextImpl(actor, actor.underlyingActor().getContext(), "self", new ElectionTermImpl(createProvider(), "test", LOG), -1, -1, new HashMap<>(ImmutableMap.of("peer1", "peerAddress1")), new DefaultConfigParamsImpl(), createProvider(), applyState -> { }, LOG, MoreExecutors.directExecutor()); context.updatePeerIds(new ServerConfigurationPayload(Arrays.asList(new ServerInfo("self", false), new ServerInfo("peer2", true), new ServerInfo("peer3", false)))); verifyPeerInfo(context, "peer1", null); verifyPeerInfo(context, "peer2", true); verifyPeerInfo(context, "peer3", false); assertEquals("isVotingMember", false, context.isVotingMember()); context.updatePeerIds(new ServerConfigurationPayload(Arrays.asList(new ServerInfo("self", true), new ServerInfo("peer2", true), new ServerInfo("peer3", true)))); verifyPeerInfo(context, "peer2", true); verifyPeerInfo(context, "peer3", true); assertEquals("isVotingMember", true, context.isVotingMember()); context.updatePeerIds(new ServerConfigurationPayload(Arrays.asList(new ServerInfo("peer2", true), new ServerInfo("peer3", true)))); verifyPeerInfo(context, "peer2", true); verifyPeerInfo(context, "peer3", true); assertEquals("isVotingMember", false, context.isVotingMember()); }