コード例 #1
0
ファイル: TestPoll.java プロジェクト: fkautz/cmusv-practicum
 /** test for method stopVote(..) */
 public void testStopVote() {
   V1Poll p = testV1polls[1];
   p.m_pendingVotes = 3;
   p.stopVoteCheck();
   assertEquals(2, p.m_pendingVotes);
   p.m_pollstate = V1Poll.PS_COMPLETE;
 }
コード例 #2
0
ファイル: TestPoll.java プロジェクト: fkautz/cmusv-practicum
 /** test for method vote(..) */
 public void testVote() {
   V1Poll p = testV1polls[1];
   p.m_hash = ByteArray.makeRandomBytes(20);
   try {
     p.castOurVote();
   } catch (IllegalStateException e) {
     // the socket isn't inited and should squack
   }
   p.m_pollstate = V1Poll.PS_COMPLETE;
 }
コード例 #3
0
ファイル: TestPoll.java プロジェクト: fkautz/cmusv-practicum
 /** test for method scheduleVote(..) */
 public void testScheduleVote() {
   V1Poll p = testV1polls[1];
   assertTrue(p instanceof V1ContentPoll);
   log.debug3("testScheduleVote 1");
   p.scheduleVote();
   log.debug3("testScheduleVote 2");
   assertNotNull(p.m_voteTime);
   assertTrue(p.m_voteTime.getRemainingTime() < p.m_deadline.getRemainingTime());
   log.debug3("at end of testScheduleVote");
 }
コード例 #4
0
ファイル: TestPoll.java プロジェクト: fkautz/cmusv-practicum
 /** test for method stopPoll(..) */
 public void testStopPoll() {
   V1Poll p = testV1polls[1];
   p.m_tally.quorum = 10;
   p.m_tally.numAgree = 7;
   p.m_tally.numDisagree = 3;
   p.m_pollstate = V1Poll.PS_WAIT_TALLY;
   p.stopPoll();
   assertTrue(p.m_pollstate == V1Poll.PS_COMPLETE);
   p.startPoll();
   assertTrue(p.m_pollstate == V1Poll.PS_COMPLETE);
 }
コード例 #5
0
ファイル: TestPoll.java プロジェクト: fkautz/cmusv-practicum
  /** test for method voteInPoll(..) */
  public void testVoteInPoll() {
    V1Poll p = testV1polls[1];
    p.m_tally.quorum = 10;
    p.m_tally.numAgree = 5;
    p.m_tally.numDisagree = 2;
    p.m_tally.wtAgree = 2000;
    p.m_tally.wtDisagree = 200;
    p.m_hash = ByteArray.makeRandomBytes(20);
    try {
      p.voteInPoll();
    } catch (IllegalStateException e) {
      // the socket isn't inited and should squack
    }

    p.m_tally.numAgree = 20;
    try {
      p.voteInPoll();
    } catch (NullPointerException npe) {
      // the socket isn't inited and should squack
    }
    p.m_pollstate = V1Poll.PS_COMPLETE;
  }
コード例 #6
0
ファイル: TestPoll.java プロジェクト: fkautz/cmusv-practicum
  /** test for method tally(..) */
  public void testTally() {
    V1Poll p = testV1polls[0];
    LcapMessage msg = p.getMessage();
    PeerIdentity id = msg.getOriginatorId();
    p.m_tally.addVote(new Vote(msg, false), id, false);
    p.m_tally.addVote(new Vote(msg, false), id, false);
    p.m_tally.addVote(new Vote(msg, false), id, false);
    assertEquals(0, p.m_tally.numAgree);
    assertEquals(0, p.m_tally.wtAgree);
    assertEquals(3, p.m_tally.numDisagree);
    assertEquals(1500, p.m_tally.wtDisagree);

    p = testV1polls[1];
    msg = p.getMessage();
    p.m_tally.addVote(new Vote(msg, true), id, false);
    p.m_tally.addVote(new Vote(msg, true), id, false);
    p.m_tally.addVote(new Vote(msg, true), id, false);
    assertEquals(3, p.m_tally.numAgree);
    assertEquals(1500, p.m_tally.wtAgree);
    assertEquals(0, p.m_tally.numDisagree);
    assertEquals(0, p.m_tally.wtDisagree);
  }
コード例 #7
0
ファイル: TestPoll.java プロジェクト: fkautz/cmusv-practicum
  /** test for method checkVote(..) */
  public void testCheckVote() throws Exception {
    V1LcapMessage msg = null;
    log.debug3("starting testCheeckVote");
    msg =
        V1LcapMessage.makeReplyMsg(
            testV1polls[0].getMessage(),
            ByteArray.makeRandomBytes(20),
            ByteArray.makeRandomBytes(20),
            null,
            V1LcapMessage.NAME_POLL_REP,
            testduration,
            testID);
    log.debug3("testCheeckVote 2");
    V1Poll p = null;
    p = createCompletedPoll(theDaemon, testau, msg, 8, 2, pollmanager);
    assertTrue(p instanceof V1NamePoll);
    log.debug3("testCheeckVote 3");
    assertNotNull(p);
    PeerIdentity id = msg.getOriginatorId();
    assertNotNull(id);
    assertNotNull(p.m_tally);
    int rep = p.m_tally.wtAgree + idmgr.getReputation(id);

    // good vote check

    p.checkVote(msg.getHashed(), new Vote(msg, false));
    assertEquals(9, p.m_tally.numAgree);
    assertEquals(2, p.m_tally.numDisagree);
    assertEquals(rep, p.m_tally.wtAgree);

    rep = p.m_tally.wtDisagree + idmgr.getReputation(id);

    // bad vote check
    p.checkVote(ByteArray.makeRandomBytes(20), new Vote(msg, false));
    assertEquals(9, p.m_tally.numAgree);
    assertEquals(3, p.m_tally.numDisagree);
    assertEquals(rep, p.m_tally.wtDisagree);
  }
コード例 #8
0
ファイル: TestPoll.java プロジェクト: fkautz/cmusv-practicum
  public void testScheduleOurHash() {
    V1Poll p = testV1polls[0];
    p.m_pollstate = V1Poll.PS_WAIT_HASH;
    // no time has elapsed - so we should be able to schedule our hash
    assertTrue(p.scheduleOurHash());
    // half the time has elapsed so we should be able to schedule our hash
    TimeBase.step(p.m_deadline.getRemainingTime() / 2);
    assertTrue(p.scheduleOurHash());

    // all of the time has elapsed we should not be able to schedule our hash
    TimeBase.step(p.m_deadline.getRemainingTime() - 1000);
    assertFalse(p.scheduleOurHash());
    p.m_pollstate = V1Poll.PS_COMPLETE;
  }
コード例 #9
0
ファイル: TestPoll.java プロジェクト: fkautz/cmusv-practicum
 public static V1Poll createCompletedPoll(
     LockssDaemon daemon,
     ArchivalUnit au,
     V1LcapMessage testmsg,
     int numAgree,
     int numDisagree,
     PollManager pollmanager)
     throws Exception {
   log.debug(
       "createCompletedPoll: au: "
           + au.toString()
           + " peer "
           + testmsg.getOriginatorId()
           + " votes "
           + numAgree
           + "/"
           + numDisagree);
   CachedUrlSetSpec cusSpec = null;
   if ((testmsg.getLwrBound() != null)
       && (testmsg.getLwrBound().equals(PollSpec.SINGLE_NODE_LWRBOUND))) {
     cusSpec = new SingleNodeCachedUrlSetSpec(testmsg.getTargetUrl());
   } else {
     cusSpec =
         new RangeCachedUrlSetSpec(
             testmsg.getTargetUrl(), testmsg.getLwrBound(), testmsg.getUprBound());
   }
   CachedUrlSet cus = au.makeCachedUrlSet(cusSpec);
   PollSpec spec = new PollSpec(cus, Poll.V1_CONTENT_POLL);
   ((MockCachedUrlSet) spec.getCachedUrlSet()).setHasContent(false);
   V1Poll p = null;
   if (testmsg.isContentPoll()) {
     p =
         new V1ContentPoll(
             spec,
             pollmanager,
             testmsg.getOriginatorId(),
             testmsg.getChallenge(),
             testmsg.getDuration(),
             testmsg.getHashAlgorithm());
   } else if (testmsg.isNamePoll()) {
     p =
         new V1NamePoll(
             spec,
             pollmanager,
             testmsg.getOriginatorId(),
             testmsg.getChallenge(),
             testmsg.getDuration(),
             testmsg.getHashAlgorithm());
   } else if (testmsg.isVerifyPoll()) {
     p =
         new V1VerifyPoll(
             spec,
             pollmanager,
             testmsg.getOriginatorId(),
             testmsg.getChallenge(),
             testmsg.getDuration(),
             testmsg.getHashAlgorithm(),
             testmsg.getVerifier());
   }
   assertNotNull(p);
   p.setMessage(testmsg);
   p.m_tally.quorum = numAgree + numDisagree;
   p.m_tally.numAgree = numAgree;
   p.m_tally.numDisagree = numDisagree;
   p.m_tally.wtAgree = 2000;
   p.m_tally.wtDisagree = 200;
   p.m_tally.localEntries = makeEntries(1, 3);
   p.m_tally.votedEntries = makeEntries(1, 5);
   p.m_tally.votedEntries.remove(1);
   p.m_pollstate = V1Poll.PS_COMPLETE;
   p.m_callerID = testmsg.getOriginatorId();
   log.debug3("poll " + p.toString());
   p.m_tally.tallyVotes();
   return p;
 }
コード例 #10
0
ファイル: TestPoll.java プロジェクト: fkautz/cmusv-practicum
 public void testStartPoll() {
   V1Poll p = testV1polls[0];
   p.startPoll();
   assertEquals(V1Poll.PS_WAIT_HASH, p.m_pollstate);
   p.m_pollstate = V1Poll.PS_COMPLETE;
 }