Exemple #1
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.

  }
Exemple #2
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();
 }