Exemplo n.º 1
0
  public final void testLog() {
    tracker.logBlockWasSentTo(dBlock1, PEER1);
    assertEquals(PEER1, tracker.getPeerListForBlock(dBlock1.getBlockId()).get(0));

    tracker.logBlockWasSentTo(dBlock1, PEER2);
    assertEquals(PEER1, tracker.getPeerListForBlock(dBlock1.getBlockId()).get(0));
    assertEquals(PEER2, tracker.getPeerListForBlock(dBlock1.getBlockId()).get(1));
  }
Exemplo n.º 2
0
  public final void testGetDeleteableBlocks() {
    // HeaderBlock hBlock =
    TransactionBlock latestTransBlock = tracker.getLatestTransactionBlock(DATANAME1);
    assertEquals(tBlock1.getBlockId(), latestTransBlock.getBlockId());

    tracker.addTransaction(tBlock2);
    latestTransBlock = tracker.getLatestTransactionBlock(DATANAME1);
    assertEquals(tBlock2.getBlockId(), latestTransBlock.getBlockId());

    Vector<Long> blocksToDelete = tracker.getBlocksOnlyReferencedBy(tBlock1);
    assertEquals(2, blocksToDelete.size());
    assertEquals(hBlock1.getBlockId(), blocksToDelete.get(0).longValue());
    assertEquals(dBlock1.getBlockId(), blocksToDelete.get(1).longValue());
  }
Exemplo n.º 3
0
  public void setUp() {
    tracker = new BlockTracker(1, new MockNetwork());
    hBlock1.registerDataBlock(dBlock1, 0, 0);
    hBlock1.registerDataBlock(dBlock2, 100, 0);

    hBlock2.registerDataBlock(dBlock2, 0, 0);
    hBlock2.registerDataBlock(dBlock3, 100, 0);

    tracker.addHeaderBlock(hBlock1);

    tBlock1.addHeaderBlockToTransaction(hBlock1);
    tracker.addTransaction(tBlock1);

    tBlock2.addHeaderBlockToTransaction(hBlock2);
    // We do not add the second transaction yet.
  }
Exemplo n.º 4
0
  public final void testGetBlockListForFile() {
    HeaderBlock hBlock = tracker.getLatestHeaderBlockForFile(FILENAME);
    assertNotNull(hBlock);
    assertEquals(hBlock1.getBlockId(), hBlock.getBlockId());

    LinkedList<Long> blocksIds = hBlock.getAssociatedDataBlockId();
    assertEquals(2, blocksIds.size());
    assertEquals(dBlock1.getBlockId(), blocksIds.getLast().longValue());
    assertEquals(dBlock2.getBlockId(), blocksIds.getFirst().longValue());
    MetaDataBlock metaBlock = hBlock.getMetaDataForDataBlock(blocksIds.getFirst());
  }
Exemplo n.º 5
0
  public final void testGetLatestBlock() {
    assertSame(tBlock1, tracker.getLatestTransactionBlock(DATANAME1));
    assertSame(hBlock1, tracker.getLatestHeaderBlockForFile(FILENAME));

    tracker.addHeaderBlock(hBlock2);
    tracker.addTransaction(tBlock2);
    assertSame(tBlock2, tracker.getLatestTransactionBlock(DATANAME1));
    assertSame(hBlock2, tracker.getLatestHeaderBlockForFile(FILENAME));

    Vector<Long> blocksOfT1 = tracker.getBlocksOnlyReferencedBy(tBlock1);
    assertEquals(2, blocksOfT1.size());
    assertEquals(hBlock1.getBlockId(), blocksOfT1.get(0).longValue());
    assertEquals(dBlock1.getBlockId(), blocksOfT1.get(1).longValue());
  }
Exemplo n.º 6
0
 public final void testgetAllTransactionBlock() {
   Vector<TransactionBlock> tBlocks = tracker.getAllTransactionBlock();
   assertEquals(1, tBlocks.size());
   assertSame(tBlock1, tBlocks.get(0));
 }