public void testNamePollTally() throws Exception { V1NamePoll np; // test a name poll we won np = makeCompletedNamePoll(4, 1, 0); assertEquals(5, np.m_tally.numAgree); assertEquals(1, np.m_tally.numDisagree); assertEquals(Tallier.RESULT_WON, np.m_tally.getTallyResult()); // test a name poll we lost with a dissenting vote np = makeCompletedNamePoll(1, 8, 1); assertEquals(2, np.m_tally.numAgree); assertEquals(9, np.m_tally.numDisagree); // build a master list np.buildPollLists(np.m_tally.pollVotes.iterator()); // these should be different since we lost the poll assertFalse(CollectionUtil.isIsomorphic(np.m_tally.localEntries, np.m_tally.votedEntries)); // the expected "correct" set is in our disagree msg assertTrue(CollectionUtil.isIsomorphic(disagree_entries, np.m_tally.votedEntries)); }
private V1NamePoll makeCompletedNamePoll(int numAgree, int numDisagree, int numDissenting) throws Exception { V1NamePoll np = null; V1LcapMessage agree_msg = null; V1LcapMessage disagree_msg1 = null; V1LcapMessage disagree_msg2 = null; Plugin plugin = testau.getPlugin(); PollSpec spec = new MockPollSpec(testau, rootV1urls[0], null, null, Poll.V1_NAME_POLL); ((MockCachedUrlSet) spec.getCachedUrlSet()).setHasContent(false); V1LcapMessage poll_msg = V1LcapMessage.makeRequestMsg( spec, null, ByteArray.makeRandomBytes(20), ByteArray.makeRandomBytes(20), V1LcapMessage.NAME_POLL_REQ, testduration, testID); // make our poll np = (V1NamePoll) new V1NamePoll( spec, pollmanager, poll_msg.getOriginatorId(), poll_msg.getChallenge(), poll_msg.getDuration(), poll_msg.getHashAlgorithm()); np.setMessage(poll_msg); // generate agree vote msg agree_msg = V1LcapMessage.makeReplyMsg( poll_msg, ByteArray.makeRandomBytes(20), poll_msg.getVerifier(), agree_entries, V1LcapMessage.NAME_POLL_REP, testduration, testID); // generate a disagree vote msg disagree_msg1 = V1LcapMessage.makeReplyMsg( poll_msg, ByteArray.makeRandomBytes(20), ByteArray.makeRandomBytes(20), disagree_entries, V1LcapMessage.NAME_POLL_REP, testduration, testID1); // generate a losing disagree vote msg disagree_msg2 = V1LcapMessage.makeReplyMsg( poll_msg, ByteArray.makeRandomBytes(20), ByteArray.makeRandomBytes(20), dissenting_entries, V1LcapMessage.NAME_POLL_REP, testduration, testID1); // add our vote V1LcapMessage msg = (V1LcapMessage) (np.getMessage()); PeerIdentity id = msg.getOriginatorId(); np.m_tally.addVote(np.makeNameVote(msg, true), id, true); // add the agree votes id = agree_msg.getOriginatorId(); for (int i = 0; i < numAgree; i++) { np.m_tally.addVote(np.makeNameVote(agree_msg, true), id, false); } // add the disagree votes id = disagree_msg1.getOriginatorId(); for (int i = 0; i < numDisagree; i++) { np.m_tally.addVote(np.makeNameVote(disagree_msg1, false), id, false); } // add dissenting disagree vote id = disagree_msg2.getOriginatorId(); for (int i = 0; i < numDissenting; i++) { np.m_tally.addVote(np.makeNameVote(disagree_msg2, false), id, false); } np.m_pollstate = V1Poll.PS_COMPLETE; np.m_tally.tallyVotes(); return np; }