+
+ @Test
+ public void testUpdatePeerIds() {
+ RaftActorContextImpl context = new RaftActorContextImpl(actor, actor.underlyingActor().getContext(),
+ "self", new ElectionTermImpl(new NonPersistentDataProvider(), "test", log), -1, -1,
+ Maps.newHashMap(ImmutableMap.<String, String>of("peer1", "peerAddress1")),
+ new DefaultConfigParamsImpl(), new NonPersistentDataProvider(), log);
+
+ 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());
+ }
+
+ private static void verifyPeerInfo(RaftActorContextImpl context, String peerId, Boolean voting) {
+ PeerInfo peerInfo = context.getPeerInfo(peerId);
+ if(voting != null) {
+ assertNotNull("Expected peer " + peerId, peerInfo);
+ assertEquals("getVotingState for " + peerId, voting.booleanValue() ? VotingState.VOTING : VotingState.NON_VOTING,
+ peerInfo.getVotingState());
+ } else {
+ assertNull("Unexpected peer " + peerId, peerInfo);
+ }
+ }