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()); }
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. }
/* Shows the transactions made by the host we control */ private void showLocalTransaction(ClientConnection clientConnection) { try { final String formatString = "%-20s %-10s %-20s %-25s %-25s %-16s %s\n"; Vector<TransactionBlock> peerTransaction = clientConnection.getAllTransaction(); if (peerTransaction.isEmpty() == false) { this.ourShell.out.printf( formatString, "DataName", "Version", "Schedule", "Transaction start", "Transaction end", "Size", "#Files"); } for (TransactionBlock tBlock : peerTransaction) { Calendar transactionDate = Calendar.getInstance(); transactionDate.setTimeInMillis(tBlock.getTransactionStartTime()); String hrDateStart = SimpleDateFormat.getDateTimeInstance().format(transactionDate.getTime()); String hrDateEnd; if (tBlock.getTransactionEndTime() != 0) { transactionDate.setTimeInMillis(tBlock.getTransactionEndTime()); hrDateEnd = SimpleDateFormat.getDateTimeInstance().format(transactionDate.getTime()); } else { hrDateEnd = "In progress"; } String humanReadableSize = new SuffixedNumber(tBlock.getTransactionSize(), "bytes").toString(); this.ourShell.out.printf( formatString, tBlock.getDataName(), Long.toHexString(tBlock.getBlockId()), tBlock.getScheduleName(), hrDateStart, hrDateEnd, humanReadableSize, tBlock.getNumberOfHeaderBlocks()); } } catch (IOException e) { e.printStackTrace(); } }