Exemplo n.º 1
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.º 2
0
  /* 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();
    }
  }