+
+ @Test
+ public void testSetPeerAddress() {
+ DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
+ RaftActorContextImpl context = new RaftActorContextImpl(actor, actor.underlyingActor().getContext(),
+ "test", new ElectionTermImpl(createProvider(), "test", LOG), -1, -1,
+ Map.of("peer1", "peerAddress1"), configParams,
+ createProvider(), applyState -> { }, LOG, MoreExecutors.directExecutor());
+
+ context.setPeerAddress("peer1", "peerAddress1_1");
+ assertEquals("getPeerAddress", "peerAddress1_1", context.getPeerAddress("peer1"));
+
+ context.setPeerAddress("peer2", "peerAddress2");
+ assertEquals("getPeerAddress", null, context.getPeerAddress("peer2"));
+ }
+
+ @Test
+ public void testUpdatePeerIds() {
+ RaftActorContextImpl context = new RaftActorContextImpl(actor, actor.underlyingActor().getContext(),
+ "self", new ElectionTermImpl(createProvider(), "test", LOG), -1, -1,
+ Map.of("peer1", "peerAddress1"),
+ new DefaultConfigParamsImpl(), createProvider(), applyState -> { }, LOG,
+ MoreExecutors.directExecutor());
+
+ context.updatePeerIds(new ServerConfigurationPayload(List.of(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(List.of(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(List.of(new ServerInfo("peer2", true),
+ new ServerInfo("peer3", true))));
+ verifyPeerInfo(context, "peer2", true);
+ verifyPeerInfo(context, "peer3", true);
+ assertEquals("isVotingMember", false, context.isVotingMember());
+ }
+
+ private static DataPersistenceProvider createProvider() {
+ return new NonPersistentDataProvider(Runnable::run);
+ }
+
+ private static void verifyPeerInfo(final RaftActorContextImpl context, final String peerId, final Boolean voting) {
+ PeerInfo peerInfo = context.getPeerInfo(peerId);
+ if (voting != null) {
+ assertNotNull("Expected peer " + peerId, peerInfo);
+ assertEquals("getVotingState for " + peerId, voting
+ ? VotingState.VOTING : VotingState.NON_VOTING, peerInfo.getVotingState());
+ } else {
+ assertNull("Unexpected peer " + peerId, peerInfo);
+ }
+ }