|
@@ -45,6 +45,7 @@ import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
import static org.junit.Assert.assertNotEquals;
|
|
|
import static org.mockito.Matchers.any;
|
|
|
import static org.mockito.Matchers.anyString;
|
|
@@ -58,6 +59,7 @@ public class LeaderBeanTest {
|
|
|
private FileTxnSnapLog fileTxnSnapLog;
|
|
|
private LeaderZooKeeperServer zks;
|
|
|
private QuorumPeer qp;
|
|
|
+ private QuorumVerifier quorumVerifierMock;
|
|
|
|
|
|
@Before
|
|
|
public void setUp() throws IOException, X509Exception {
|
|
@@ -73,7 +75,7 @@ public class LeaderBeanTest {
|
|
|
new InetSocketAddress(clientIP, PortAssignment.unique()),
|
|
|
new InetSocketAddress(clientIP, clientPort), LearnerType.PARTICIPANT));
|
|
|
|
|
|
- QuorumVerifier quorumVerifierMock = mock(QuorumVerifier.class);
|
|
|
+ quorumVerifierMock = mock(QuorumVerifier.class);
|
|
|
when(quorumVerifierMock.getAllMembers()).thenReturn(peersView);
|
|
|
|
|
|
qp.setQuorumVerifier(quorumVerifierMock, false);
|
|
@@ -173,12 +175,21 @@ public class LeaderBeanTest {
|
|
|
|
|
|
@Test
|
|
|
public void testFollowerInfo() throws IOException {
|
|
|
+ Map<Long, QuorumServer> votingMembers = new HashMap<Long, QuorumServer>();
|
|
|
+ votingMembers.put(1L, null);
|
|
|
+ votingMembers.put(2L, null);
|
|
|
+ votingMembers.put(3L, null);
|
|
|
+ when(quorumVerifierMock.getVotingMembers()).thenReturn(votingMembers);
|
|
|
+
|
|
|
LearnerHandler follower = mock(LearnerHandler.class);
|
|
|
when(follower.getLearnerType()).thenReturn(LearnerType.PARTICIPANT);
|
|
|
when(follower.toString()).thenReturn("1");
|
|
|
+ when(follower.getSid()).thenReturn(1L);
|
|
|
leader.addLearnerHandler(follower);
|
|
|
+ leader.addForwardingFollower(follower);
|
|
|
|
|
|
assertEquals("1\n", leaderBean.followerInfo());
|
|
|
+ assertEquals("", leaderBean.nonVotingFollowerInfo());
|
|
|
|
|
|
LearnerHandler observer = mock(LearnerHandler.class);
|
|
|
when(observer.getLearnerType()).thenReturn(LearnerType.OBSERVER);
|
|
@@ -186,5 +197,18 @@ public class LeaderBeanTest {
|
|
|
leader.addLearnerHandler(observer);
|
|
|
|
|
|
assertEquals("1\n", leaderBean.followerInfo());
|
|
|
+ assertEquals("", leaderBean.nonVotingFollowerInfo());
|
|
|
+
|
|
|
+ LearnerHandler nonVotingFollower = mock(LearnerHandler.class);
|
|
|
+ when(nonVotingFollower.getLearnerType()).thenReturn(LearnerType.PARTICIPANT);
|
|
|
+ when(nonVotingFollower.toString()).thenReturn("5");
|
|
|
+ when(nonVotingFollower.getSid()).thenReturn(5L);
|
|
|
+ leader.addLearnerHandler(nonVotingFollower);
|
|
|
+ leader.addForwardingFollower(nonVotingFollower);
|
|
|
+
|
|
|
+ String followerInfo = leaderBean.followerInfo();
|
|
|
+ assertTrue(followerInfo.contains("1"));
|
|
|
+ assertTrue(followerInfo.contains("5"));
|
|
|
+ assertEquals("5\n", leaderBean.nonVotingFollowerInfo());
|
|
|
}
|
|
|
}
|