Exemplo n.º 1
0
  public void testPurgeForce() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 30; i++) table.add(i, i);
    System.out.println("table = " + table);
    table.purge(15, true);
    System.out.println("table = " + table);
    assertIndices(table, 15, 15, 30);
    for (int i = 1; i <= 15; i++) assert table._get(i) == null;
    for (int i = 16; i <= 30; i++) assert table._get(i) != null;
    assert table.get(5) == null && table.get(25) != null;

    table.purge(30, true);
    System.out.println("table = " + table);
    assertIndices(table, 30, 30, 30);
    assert table.isEmpty();
    for (int i = 1; i <= 30; i++) assert table._get(i) == null;

    for (int i = 31; i <= 40; i++) table.add(i, i);
    System.out.println("table = " + table);
    assert table.size() == 10;
    assertIndices(table, 30, 30, 40);

    table.purge(50, true);
    System.out.println("table = " + table);
    assert table.isEmpty();
    assertIndices(table, 40, 40, 40);
  }
Exemplo n.º 2
0
  public void testAddWithWrapAround() {
    Table<Integer> buf = new Table<Integer>(3, 10, 5);
    for (int i = 6; i <= 15; i++) assert buf.add(i, i) : "addition of seqno " + i + " failed";
    System.out.println("buf = " + buf);
    for (int i = 0; i < 3; i++) {
      Integer val = buf.remove(false);
      System.out.println("removed " + val);
      assert val != null;
    }
    System.out.println("buf = " + buf);

    long low = buf.getLow();
    buf.purge(8);
    System.out.println("buf = " + buf);
    assert buf.getLow() == 8;
    for (long i = low; i <= 8; i++)
      assert buf._get(i) == null : "message with seqno=" + i + " is not null";

    for (int i = 16; i <= 18; i++) assert buf.add(i, i);
    System.out.println("buf = " + buf);

    while (buf.remove(false) != null) ;
    System.out.println("buf = " + buf);
    assert buf.isEmpty();
    assert buf.getNumMissing() == 0;
    low = buf.getLow();
    buf.purge(18);
    assert buf.getLow() == 18;
    for (long i = low; i <= 18; i++)
      assert buf._get(i) == null : "message with seqno=" + i + " is not null";
  }
Exemplo n.º 3
0
 public static void testMove() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   for (int i = 1; i < 50; i++) addAndGet(table, i);
   table.removeMany(true, 49);
   assert table.isEmpty();
   addAndGet(table, 50);
   assert table.size() == 1;
   assertCapacity(table.capacity(), table.getNumRows(), 10);
 }
Exemplo n.º 4
0
  public void testAddWithInvalidSeqno() {
    Table<Integer> buf = new Table<Integer>(3, 10, 20);
    boolean success = buf.add(10, 0);
    assert !success;

    success = buf.add(20, 0);
    assert !success;
    assert buf.isEmpty();
  }
Exemplo n.º 5
0
 public void run() {
   for (SenderEntry val : send_table.values()) {
     Table<Message> buf = val != null ? val.sent_msgs : null;
     if (buf != null && !buf.isEmpty()) {
       long from = buf.getHighestDelivered() + 1, to = buf.getHighestReceived();
       List<Message> list = buf.get(from, to);
       if (list != null) {
         for (Message msg : list) retransmit(msg);
       }
     }
   }
 }
Exemplo n.º 6
0
  public void testPurge2() {
    Table<Integer> buf = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 7; i++) {
      buf.add(i, i);
      buf.remove(false);
    }
    System.out.println("buf = " + buf);
    assert buf.isEmpty();
    long low = buf.getLow();
    buf.purge(3);
    assert buf.getLow() == 3;
    for (long i = low; i <= 3; i++)
      assert buf._get(i) == null : "message with seqno=" + i + " is not null";

    buf.purge(6);
    assert buf._get(6) == null;
    buf.purge(7);
    assert buf._get(7) == null;
    assert buf.getLow() == 7;
    assert buf.isEmpty();

    for (int i = 7; i <= 14; i++) {
      buf.add(i, i);
      buf.remove(false);
    }

    System.out.println("buf = " + buf);
    assert buf.isEmpty();

    low = buf.getLow();
    assert low == 7;
    buf.purge(12);
    System.out.println("buf = " + buf);
    assert buf.getLow() == 12;
    for (long i = low; i <= 12; i++)
      assert buf._get(i) == null : "message with seqno=" + i + " is not null";
  }
Exemplo n.º 7
0
 /**
  * Appends the table differences of the given schema difference to the result
  *
  * @param schemaDifference The difference, not null
  * @param result The result to append to, not null
  */
 protected void appendTableDifferences(SchemaDifference schemaDifference, StringBuilder result) {
   for (TableDifference tableDifference : schemaDifference.getTableDifferences()) {
     Table table = tableDifference.getTable();
     if (table.isEmpty()) {
       result.append("\nExpected table to be empty but found rows for table ");
       appendTableName(schemaDifference.getSchema(), table, result);
       result.append("\n");
       continue;
     }
     result.append("\nFound differences for table ");
     appendTableName(schemaDifference.getSchema(), table, result);
     result.append(":\n");
     appendMissingRowDifferences(tableDifference, result);
     appendBestRowDifferences(tableDifference, result);
   }
 }
Exemplo n.º 8
0
 public static void testRemoveManyWithFilterAcceptNone() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   for (int i = 1; i <= 10; i++) table.add(i, i);
   List<Integer> list =
       table.removeMany(
           null,
           true,
           0,
           new Filter<Integer>() {
             public boolean accept(Integer element) {
               return false;
             }
           });
   System.out.println("list = " + list);
   System.out.println("table = " + table);
   assert list == null;
   assert table.isEmpty();
 }
Exemplo n.º 9
0
 public static void testRemoveManyWithFilter() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   for (int i = 1; i <= 10; i++) table.add(i, i);
   List<Integer> list =
       table.removeMany(
           null,
           true,
           0,
           new Filter<Integer>() {
             public boolean accept(Integer element) {
               return element % 2 == 0;
             }
           });
   System.out.println("list = " + list);
   System.out.println("table = " + table);
   assert list.size() == 5;
   assert table.isEmpty();
   for (Integer num : Arrays.asList(2, 4, 6, 8, 10)) assert list.contains(num);
 }
Exemplo n.º 10
0
  public void testAddWithWrapAroundAndRemoveMany() {
    Table<Integer> buf = new Table<Integer>(3, 10, 5);
    for (int i = 6; i <= 15; i++) assert buf.add(i, i) : "addition of seqno " + i + " failed";
    System.out.println("buf = " + buf);
    List<Integer> removed = buf.removeMany(true, 3);
    System.out.println("removed " + removed);
    System.out.println("buf = " + buf);
    for (int i : removed) assert buf._get(i) == null;
    assertIndices(buf, 8, 8, 15);

    for (int i = 16; i <= 18; i++) assert buf.add(i, i);
    System.out.println("buf = " + buf);

    removed = buf.removeMany(true, 0);
    System.out.println("buf = " + buf);
    System.out.println("removed = " + removed);
    assert removed.size() == 10;
    for (int i : removed) assert buf._get(i) == null;

    assert buf.isEmpty();
    assert buf.getNumMissing() == 0;
    assertIndices(buf, 18, 18, 18);
  }
Exemplo n.º 11
0
  public DatabaseDiff(final Database fromDatabase, final Database toDatabase) {
    this.fromDatabase = fromDatabase;
    this.toDatabase = toDatabase;

    final List<Table> addedTables = Lists.newArrayList();
    final List<Table> identicalTables = Lists.newArrayList();
    final List<Table> modifiedTables = Lists.newArrayList();
    final List<Table> removedTables = Lists.newArrayList();

    for (final String tableName : Sets.newTreeSet(fromDatabase.getTableNames())) {
      final Table fromTable = fromDatabase.getTable(tableName);
      final Table toTable = toDatabase.getTable(tableName);

      if (fromTable.isEmpty() && toTable.isEmpty()) continue;

      final Rows identicalRows = new Rows();
      final Rows modifiedRows = new Rows();
      final Rows removedRows = new Rows();
      final Rows addedRows = toDatabase.find(tableName);

      final Rows fromRows = fromDatabase.find(tableName);

      for (final Row fromRow : fromRows) {
        // Search by tables pkey values
        final Rows toRows = toTable.find(fromRow);
        if (toRows.isEmpty()) {
          // Deleted
          removedRows.add(fromRow);
          continue;
        }

        // [EB]: this only happens when a table fails to specify a primary key column
        if (toRows.size() > 1) {
          throw new IllegalStateException("This cannot happen unless the schema is broken :(");
        }

        // Now look for the *exact* match in the 'to' Rows
        final Rows record = toRows.find(fromRow);
        if (!record.isEmpty()) {
          // Identical
          addedRows.remove(record.get(0));
          identicalRows.add(record.get(0));
        } else {
          // Changed
          final Row updatedRow = toTable.get(toRows.get(0));
          final Row row = toTable.rowDiff(fromRow, updatedRow);

          addedRows.remove(updatedRow);
          modifiedRows.add(row);
        }
      }

      if (!addedRows.isEmpty()) addedTables.add(new Table(fromTable, addedRows));
      if (!modifiedRows.isEmpty()) modifiedTables.add(new Table(fromTable, modifiedRows));
      if (!removedRows.isEmpty()) removedTables.add(new Table(fromTable, removedRows));
      if (!identicalRows.isEmpty()) identicalTables.add(new Table(fromTable, identicalRows));
    }

    added = new Database(addedTables);
    modified = new Database(modifiedTables);
    removed = new Database(removedTables);
    identical = new Database(identicalTables);
  }