Beispiel #1
0
  private V3LcapMessage makeTestVoteMessage(Collection voteBlocks) throws IOException {
    mPollMgr.setStateDir("key", tempDir);
    V3LcapMessage msg =
        new V3LcapMessage(
            "ArchivalID_2",
            "key",
            "Plug42",
            m_testBytes,
            m_testBytes,
            V3LcapMessage.MSG_VOTE,
            987654321,
            m_testID,
            tempDir,
            theDaemon);

    // Set msg vote blocks.
    for (Iterator ix = voteBlocks.iterator(); ix.hasNext(); ) {
      msg.addVoteBlock((VoteBlock) ix.next());
    }

    msg.setHashAlgorithm(LcapMessage.getDefaultHashAlgorithm());
    msg.setArchivalId(m_archivalID);
    msg.setPluginVersion("PlugVer42");
    return msg;
  }
Beispiel #2
0
 public void testNullPollNak() throws Exception {
   V3LcapMessage src = this.makePollAckMessage(null);
   InputStream srcStream = src.getInputStream();
   V3LcapMessage copy = new V3LcapMessage(srcStream, tempDir, theDaemon);
   assertEqualMessages(src, copy);
   assertNull(src.getNak());
   assertNull(copy.getNak());
 }
Beispiel #3
0
 public PollSpec(V3LcapMessage msg) {
   this(
       msg.getArchivalId(),
       (msg.getTargetUrl() == null) ? "lockssau:" : msg.getTargetUrl(),
       null,
       null,
       Poll.V3_POLL);
   protocolVersion = msg.getProtocolVersion();
   pluginVersion = msg.getPluginVersion();
 }
Beispiel #4
0
 public void testTestMessageToString() throws IOException {
   String expectedResult =
       "[V3LcapMessage: from "
           + m_testID.toString()
           + ", Vote AUID: TestAU_1.0 "
           + "Key:key "
           + "PN:AQIDBAUGBwgJAAECAwQFBgcICQA= "
           + "VN:AQIDBAUGBwgJAAECAwQFBgcICQA= "
           + "B:10 ver 3 rev 5]";
   assertEquals(expectedResult, m_testMsg.toString());
 }
Beispiel #5
0
 public void testDiskBasedStreamEncodingTest() throws Exception {
   // Make a list of vote blocks large enough to trigger on-disk
   // vote message creation.
   List testVoteBlocks = V3TestUtils.makeVoteBlockList(21);
   V3LcapMessage testMsg = makeTestVoteMessage(testVoteBlocks);
   assertTrue(testMsg.m_voteBlocks instanceof DiskVoteBlocks);
   // Encode the test message.
   InputStream is = testMsg.getInputStream();
   V3LcapMessage decodedMsg = new V3LcapMessage(is, tempDir, theDaemon);
   // Ensure that the decoded message matches the test message.
   assertEqualMessages(testMsg, decodedMsg);
 }
Beispiel #6
0
 public void testPollDuration() throws Exception {
   TimeBase.setSimulated(TimeBase.nowMs());
   V3LcapMessage src = this.makePollMessage(6 * Constants.WEEK);
   InputStream srcStream = src.getInputStream();
   V3LcapMessage copy = new V3LcapMessage(srcStream, tempDir, theDaemon);
   assertEqualMessages(src, copy);
   assertEquals(6 * Constants.WEEK, copy.getDuration());
 }
Beispiel #7
0
 public void testUnknownPollNak() throws Exception {
   MyV3LcapMessage src = makePollAckMessage(V3LcapMessage.PollNak.NAK_NO_TIME);
   src.setTestNak("KNACKERED");
   InputStream srcStream = src.getInputStream();
   V3LcapMessage copy = new V3LcapMessage(srcStream, tempDir, theDaemon);
   assertEqualMessages(src, copy);
   assertNotNull(src.getNak());
   assertNotNull(copy.getNak());
   assertEquals(V3LcapMessage.PollNak.NAK_NO_TIME, src.getNak());
   assertEquals(V3LcapMessage.PollNak.NAK_UNKNOWN, copy.getNak());
 }
Beispiel #8
0
 public void storeProps() throws IOException {
   super.storeProps();
   if (testNak != null) {
     m_props.setProperty("nak", testNak);
   }
 }
Beispiel #9
0
  public void testRandomNoOpMessageCreation() throws Exception {
    V3LcapMessage noopMsg1 = V3LcapMessage.makeNoOpMsg(m_testID, theDaemon);
    V3LcapMessage noopMsg2 = V3LcapMessage.makeNoOpMsg(m_testID, theDaemon);

    // now check the fields we expect to be valid
    assertEquals(V3LcapMessage.MSG_NO_OP, noopMsg1.getOpcode());
    assertEquals(V3LcapMessage.MSG_NO_OP, noopMsg2.getOpcode());
    assertTrue(noopMsg1.getOriginatorId() == m_testID);
    assertTrue(noopMsg1.getOriginatorId() == noopMsg2.getOriginatorId());
    assertFalse(noopMsg1.getPollerNonce() == noopMsg2.getPollerNonce());
    assertFalse(noopMsg1.getVoterNonce() == noopMsg2.getVoterNonce());
    assertEquals(null, noopMsg1.getVoterNonce2());
    assertEquals(null, noopMsg2.getVoterNonce2());
    assertEquals(null, noopMsg1.getVoteBlocks());
    assertEquals(null, noopMsg2.getVoteBlocks());
  }
Beispiel #10
0
 private V3LcapMessage makeRepairMessage(byte[] repairData) {
   V3LcapMessage msg =
       new V3LcapMessage(
           "ArchivalID_2",
           "key",
           "Plug42",
           m_testBytes,
           m_testBytes,
           V3LcapMessage.MSG_REPAIR_REP,
           987654321,
           m_testID,
           tempDir,
           theDaemon);
   msg.setHashAlgorithm(LcapMessage.getDefaultHashAlgorithm());
   msg.setTargetUrl(m_url);
   msg.setArchivalId(m_archivalID);
   msg.setPluginVersion("PlugVer42");
   msg.setRepairDataLength(repairData.length);
   msg.setRepairProps(m_repairProps);
   msg.setInputStream(new ByteArrayInputStream(repairData));
   return msg;
 }
Beispiel #11
0
  private void assertEqualMessages(V3LcapMessage a, V3LcapMessage b) throws Exception {
    assertTrue(a.getOriginatorId() == b.getOriginatorId());
    assertEquals(a.getOpcode(), b.getOpcode());
    assertEquals(a.getTargetUrl(), b.getTargetUrl());
    assertEquals(a.getArchivalId(), b.getArchivalId());
    assertEquals(a.getProtocolVersion(), b.getProtocolVersion());
    assertEquals(a.getPollerNonce(), b.getPollerNonce());
    assertEquals(a.getVoterNonce(), b.getVoterNonce());
    assertEquals(a.getVoterNonce2(), b.getVoterNonce2());
    assertEquals(a.getPluginVersion(), b.getPluginVersion());
    assertEquals(a.getHashAlgorithm(), b.getHashAlgorithm());
    assertEquals(a.isVoteComplete(), b.isVoteComplete());
    assertEquals(a.getRepairDataLength(), b.getRepairDataLength());
    assertEquals(a.getLastVoteBlockURL(), b.getLastVoteBlockURL());
    assertIsomorphic(a.getNominees(), b.getNominees());
    List aBlocks = new ArrayList();
    List bBlocks = new ArrayList();
    for (VoteBlocksIterator iter = a.getVoteBlockIterator(); iter.hasNext(); ) {
      aBlocks.add(iter.next());
    }
    for (VoteBlocksIterator iter = b.getVoteBlockIterator(); iter.hasNext(); ) {
      bBlocks.add(iter.next());
    }
    assertTrue(aBlocks.equals(bBlocks));

    //  TODO: Figure out how to test time.

  }
Beispiel #12
0
  public void testRequestMessageCreation() throws Exception {
    V3LcapMessage reqMsg =
        new V3LcapMessage(
            "ArchivalID_2",
            "key",
            "Plug42",
            m_testBytes,
            m_testBytes,
            V3LcapMessage.MSG_REPAIR_REQ,
            987654321,
            m_testID,
            tempDir,
            theDaemon);
    reqMsg.setTargetUrl("http://foo.com/");

    for (Iterator ix = m_testVoteBlocks.iterator(); ix.hasNext(); ) {
      reqMsg.addVoteBlock((VoteBlock) ix.next());
    }

    assertEquals(3, reqMsg.getProtocolVersion());
    assertEquals("Plug42", reqMsg.getPluginVersion());
    assertTrue(m_testID == reqMsg.getOriginatorId());
    assertEquals(V3LcapMessage.MSG_REPAIR_REQ, reqMsg.getOpcode());
    assertEquals("ArchivalID_2", reqMsg.getArchivalId());
    assertEquals("http://foo.com/", reqMsg.getTargetUrl());
    assertEquals(m_testBytes, reqMsg.getPollerNonce());
    assertEquals(m_testBytes, reqMsg.getVoterNonce());
    assertEquals(null, reqMsg.getVoterNonce2());
    List aBlocks = new ArrayList();
    List bBlocks = new ArrayList();
    for (VoteBlocksIterator iter = m_testMsg.getVoteBlockIterator(); iter.hasNext(); ) {
      aBlocks.add(iter.next());
    }
    for (VoteBlocksIterator iter = reqMsg.getVoteBlockIterator(); iter.hasNext(); ) {
      bBlocks.add(iter.next());
    }
    assertEquals(aBlocks, bBlocks);

    // Actual size of test vote blocks is unpredictable
    assertTrue(reqMsg.getEstimatedEncodedLength() > V3LcapMessage.EST_ENCODED_HEADER_LENGTH);
  }
Beispiel #13
0
 public void testNonNullPollNak1() throws Exception {
   V3LcapMessage src = this.makePollAckMessage(V3LcapMessage.PollNak.NAK_GROUP_MISMATCH);
   InputStream srcStream = src.getInputStream();
   V3LcapMessage copy = new V3LcapMessage(srcStream, tempDir, theDaemon);
   assertEqualMessages(src, copy);
   assertNotNull(src.getNak());
   assertNotNull(copy.getNak());
   assertEquals(V3LcapMessage.PollNak.NAK_GROUP_MISMATCH, src.getNak());
   assertEquals(V3LcapMessage.PollNak.NAK_GROUP_MISMATCH, copy.getNak());
 }
Beispiel #14
0
  public void testNoOpMessageCreation() throws Exception {
    // Without voterNonce2
    V3LcapMessage noopMsg =
        V3LcapMessage.makeNoOpMsg(m_testID, m_testBytes, m_testBytes, theDaemon);
    // With voterNonce2
    V3LcapMessage noopMsg2 =
        V3LcapMessage.makeNoOpMsg(m_testID, m_testBytes, m_testBytes, m_testBytes, theDaemon);

    // now check the fields we expect to be valid
    assertEquals(V3LcapMessage.MSG_NO_OP, noopMsg.getOpcode());
    assertTrue(m_testID == noopMsg.getOriginatorId());
    assertEquals(m_testBytes, noopMsg.getPollerNonce());
    assertEquals(m_testBytes, noopMsg.getVoterNonce());
    assertEquals(null, noopMsg.getVoterNonce2());
    assertEquals(null, noopMsg.getVoteBlocks());
    assertEquals(V3LcapMessage.EST_ENCODED_HEADER_LENGTH, noopMsg.getEstimatedEncodedLength());

    // Same for msg with voterNonce2
    assertEquals(V3LcapMessage.MSG_NO_OP, noopMsg2.getOpcode());
    assertTrue(m_testID == noopMsg2.getOriginatorId());
    assertEquals(m_testBytes, noopMsg2.getPollerNonce());
    assertEquals(m_testBytes, noopMsg2.getVoterNonce());
    assertEquals(m_testBytes, noopMsg2.getVoterNonce2());
    assertEquals(null, noopMsg2.getVoteBlocks());
    assertEquals(V3LcapMessage.EST_ENCODED_HEADER_LENGTH, noopMsg2.getEstimatedEncodedLength());
  }
Beispiel #15
0
 public void testDiskRepairMessage() throws Exception {
   int len = 100 * 1024;
   byte[] repairData = ByteArray.makeRandomBytes(len);
   V3LcapMessage src = makeRepairMessage(repairData);
   assertEquals(len, src.getRepairDataLength());
   assertEquals(V3LcapMessage.EST_ENCODED_HEADER_LENGTH + len, src.getEstimatedEncodedLength());
   InputStream srcStream = src.getInputStream();
   V3LcapMessage copy = new V3LcapMessage(srcStream, tempDir, theDaemon);
   assertEqualMessages(src, copy);
   assertEquals(len, copy.getRepairDataLength());
   assertEquals(V3LcapMessage.EST_ENCODED_HEADER_LENGTH + len, src.getEstimatedEncodedLength());
   InputStream in = copy.getRepairDataInputStream();
   assertTrue(in + "", in instanceof FileInputStream);
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   StreamUtil.copy(in, out);
   byte[] repairCopy = out.toByteArray();
   assertEquals(repairData, repairCopy);
   // ensure that repeated delete doesn't cause error
   copy.delete();
   copy.delete();
 }
Beispiel #16
0
 public void testNoOpEncoding() throws Exception {
   V3LcapMessage noopMsg =
       V3LcapMessage.makeNoOpMsg(m_testID, m_testBytes, m_testBytes, theDaemon);
   InputStream fromMsg = noopMsg.getInputStream();
   V3LcapMessage msg = new V3LcapMessage(fromMsg, tempDir, theDaemon);
   // now test to see if we got back what we started with
   assertTrue(m_testID == msg.getOriginatorId());
   assertEquals(V3LcapMessage.MSG_NO_OP, msg.getOpcode());
   assertEquals(m_testBytes, msg.getPollerNonce());
   assertEquals(m_testBytes, msg.getVoterNonce());
   assertEquals(null, msg.getVoterNonce2());
 }
Beispiel #17
0
 public void getGroup() throws Exception {
   m_testMsg.setGroups(null);
   assertNull(m_testMsg.getGroups());
   assertNull(m_testMsg.getGroupList());
   m_testMsg.setGroups("foo");
   assertEquals("foo", m_testMsg.getGroups());
   assertEquals(ListUtil.list("foo"), m_testMsg.getGroupList());
   m_testMsg.setGroups("foo;bar");
   assertEquals("foo;bar", m_testMsg.getGroups());
   assertEquals(ListUtil.list("foo", "bar"), m_testMsg.getGroupList());
   m_testMsg.setGroups("foo;bar;baz");
   assertEquals("foo;bar;baz", m_testMsg.getGroups());
   assertEquals(ListUtil.list("foo", "bar", "baz"), m_testMsg.getGroupList());
 }
Beispiel #18
0
 public void testNoOpMessageToString() throws IOException {
   V3LcapMessage noopMsg =
       V3LcapMessage.makeNoOpMsg(m_testID, m_testBytes, m_testBytes, theDaemon);
   String expectedResult = "[V3LcapMessage: from " + m_testID.toString() + ", NoOp]";
   assertEquals(expectedResult, noopMsg.toString());
 }