Exemple #1
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";
  }
Exemple #2
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);
  }
Exemple #3
0
  protected void handleAckReceived(Address sender, long seqno, short conn_id) {
    if (log.isTraceEnabled())
      log.trace(
          new StringBuilder()
              .append(local_addr)
              .append(" <-- ACK(")
              .append(sender)
              .append(": #")
              .append(seqno)
              .append(", conn-id=")
              .append(conn_id)
              .append(')'));
    SenderEntry entry = send_table.get(sender);

    if (entry != null && entry.send_conn_id != conn_id) {
      if (log.isTraceEnabled())
        log.trace(
            local_addr
                + ": my conn_id ("
                + entry.send_conn_id
                + ") != received conn_id ("
                + conn_id
                + "); discarding ACK");
      return;
    }

    Table<Message> win = entry != null ? entry.sent_msgs : null;
    if (win != null) {
      win.purge(seqno, true); // removes all messages <= seqno (forced purge)
      num_acks_received++;
    }
  }
Exemple #4
0
  public void testResizeWithPurge2() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 50; i++) addAndGet(table, i);
    System.out.println("table = " + table);
    assert table.size() == 50;
    assertCapacity(table.capacity(), table.getNumRows(), 10);
    assertIndices(table, 0, 0, 50);
    table.removeMany(false, 43);
    System.out.println("table = " + table);
    assertIndices(table, 0, 43, 50);
    table.purge(43);
    System.out.println("table = " + table);
    assertIndices(table, 43, 43, 50);
    addAndGet(table, 52);
    assert table.get(43) == null;

    for (long i = 44; i <= 50; i++) {
      Integer num = table.get(i);
      assert num != null && num == i;
    }

    assert table.get(50) != null;
    assert table.get(51) == null;
    Integer num = table.get(52);
    assert num != null && num == 52;
    assert table.get(53) == null;
  }
Exemple #5
0
 public void testPurge4() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   for (int i = 1; i <= 100; i++) table.add(i, i);
   System.out.println("table = " + table);
   table.removeMany(false, 53);
   table.purge(53);
   for (int i = 54; i <= 100; i++) assert table.get(i) == i;
 }
Exemple #6
0
 public void testIndex() {
   Table<Integer> buf = new Table<Integer>(3, 10, 5);
   assert buf.getHighestDelivered() == 5;
   assert buf.getHighestReceived() == 5;
   buf.add(6, 6);
   buf.add(7, 7);
   buf.remove(false);
   buf.remove(false);
   long low = buf.getLow();
   assert low == 5;
   buf.purge(4);
   buf.purge(5);
   buf.purge(6);
   buf.purge(7);
   System.out.println("buf = " + buf);
   for (long i = low; i <= 7; i++)
     assert buf._get(i) == null : "message with seqno=" + i + " is not null";
 }
Exemple #7
0
  public void testPurge5() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 100; i++) table.add(i, i);
    System.out.println("table = " + table);
    table.removeMany(false, 0);

    table.purge(10);
    for (int i = 1; i <= 10; i++) assert table._get(i) == null;
    for (int i = 11; i <= 100; i++) assert table.get(i) == i;

    table.purge(10);
    for (int i = 11; i <= 100; i++) assert table.get(i) == i;

    table.purge(50);
    for (int i = 1; i <= 50; i++) assert table._get(i) == null;
    for (int i = 51; i <= 100; i++) assert table.get(i) == i;

    table.purge(100);
    for (int i = 51; i <= 100; i++) assert table._get(i) == null;
  }
Exemple #8
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";
  }
Exemple #9
0
 public static void testRemoveManyWithWrapping2() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   for (int seqno : Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 20))
     table.add(seqno, seqno);
   System.out.println("table = " + table);
   assertIndices(table, 0, 0, 20);
   assert table.size() == 18 && table.getNumMissing() == 2;
   List<Integer> list = table.removeMany(false, 0);
   assert list.size() == 12;
   assertIndices(table, 0, 12, 20);
   assert table.size() == 6 && table.getNumMissing() == 2;
   table.purge(12);
   assertIndices(table, 12, 12, 20);
   assert table.size() == 6 && table.getNumMissing() == 2;
 }
Exemple #10
0
  public void testResizeWithPurge() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 100; i++) addAndGet(table, i);
    System.out.println("table: " + table);

    // now remove 60 messages
    for (int i = 1; i <= 60; i++) {
      Integer num = table.remove();
      assert num != null && num == i;
    }
    System.out.println("table after removal of seqno 60: " + table);

    table.purge(50);
    System.out.println("now triggering a resize() by addition of seqno=120");
    addAndGet(table, 120);
  }
Exemple #11
0
  public static void testPurge() {
    Table<Integer> table = new Table<Integer>(5, 10, 0);
    for (int seqno = 1; seqno <= 25; seqno++) table.add(seqno, seqno);

    int[] seqnos = {30, 31, 32, 37, 38, 39, 40, 41, 42, 47, 48, 49};
    for (int seqno : seqnos) table.add(seqno, seqno);

    System.out.println("table (before remove):\n" + table.dump());
    for (int seqno = 1; seqno <= 22; seqno++) table.remove(false);

    System.out.println("\ntable (after remove 22, before purge):\n" + table.dump());
    table.purge(22);
    System.out.println("\ntable: (after purge 22):\n" + table.dump());
    assert table.size() == 3 + seqnos.length;
    assert table.computeSize() == table.size();
  }
Exemple #12
0
 public void testCompact() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   for (int i = 1; i <= 80; i++) addAndGet(table, i);
   assert table.size() == 80;
   assertIndices(table, 0, 0, 80);
   List<Integer> list = table.removeMany(false, 60);
   assert list.size() == 60;
   assert list.get(0) == 1 && list.get(list.size() - 1) == 60;
   assertIndices(table, 0, 60, 80);
   table.purge(60);
   assertIndices(table, 60, 60, 80);
   assert table.size() == 20;
   table.compact();
   assertIndices(table, 60, 60, 80);
   assert table.size() == 20;
   assertCapacity(table.capacity(), table.getNumRows(), 10);
 }
Exemple #13
0
 /** Add the ACK to hashtable.sender.sent_msgs */
 protected void handleAckReceived(Address sender, long seqno) {
   if (log.isTraceEnabled())
     log.trace(
         new StringBuilder()
             .append(local_addr)
             .append(" <-- ACK(")
             .append(sender)
             .append(": #")
             .append(seqno)
             .append(')'));
   SenderEntry entry = send_table.get(sender);
   Table<Message> win = entry != null ? entry.sent_msgs : null;
   if (win != null) {
     win.purge(seqno, true); // removes all messages <= seqno (forced purge)
     num_acks_received++;
   }
 }
Exemple #14
0
  /**
   * Purge all messages in window for local_addr, which are <= low. Check if the window's highest
   * received message is > high: if true, retransmit all messages from high - win.high to sender
   *
   * @param sender
   * @param hd Highest delivered seqno
   * @param hr Highest received seqno
   */
  protected void stable(Address sender, short conn_id, long hd, long hr) {
    SenderEntry entry = send_table.get(sender);
    Table<Message> win = entry != null ? entry.sent_msgs : null;
    if (win == null) return;

    if (log.isTraceEnabled())
      log.trace(
          new StringBuilder()
                  .append(local_addr)
                  .append(" <-- STABLE(")
                  .append(sender)
                  .append(": ")
                  .append(hd)
                  .append("-")
                  .append(hr)
                  .append(", conn_id=" + conn_id)
              + ")");

    if (entry.send_conn_id != conn_id) {
      log.warn(
          local_addr
              + ": my conn_id ("
              + entry.send_conn_id
              + ") != received conn_id ("
              + conn_id
              + "); discarding STABLE message !");
      return;
    }

    win.purge(hd, true);
    long win_hr = win.getHighestReceived();
    if (win_hr > hr) {
      for (long seqno = hr; seqno <= win_hr; seqno++) {
        Message msg =
            win.get(
                seqno); // destination is still the same (the member which sent the STABLE message)
        if (msg != null) down_prot.down(new Event(Event.MSG, msg));
      }
    }
  }
Exemple #15
0
  public void testResizeWithPurgeAndGetOfNonExistingElement() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 50; i++) addAndGet(table, i);
    System.out.println("table: " + table);
    assertIndices(table, 0, 0, 50);
    assert table.size() == 50 && table.getNumMissing() == 0;

    // now remove 15 messages
    for (long i = 1; i <= 15; i++) {
      Integer num = table.remove(false);
      assert num != null && num == i;
    }
    System.out.println("table after removal of seqno 15: " + table);
    assertIndices(table, 0, 15, 50);
    assert table.size() == 35 && table.getNumMissing() == 0;

    table.purge(15);
    System.out.println("now triggering a resize() by addition of seqno=55");
    addAndGet(table, 55);
    assertIndices(table, 15, 15, 55);
    assert table.size() == 36 && table.getNumMissing() == 4;

    // now we have elements 40-49 in row 1 and 55 in row 2:
    List<Integer> list = new ArrayList<Integer>(20);
    for (int i = 16; i < 50; i++) list.add(i);
    list.add(55);

    for (long i = table.getOffset(); i < table.capacity() + table.getOffset(); i++) {
      Integer num = table._get(i);
      if (num != null) {
        System.out.println("num=" + num);
        list.remove(num);
      }
    }

    System.out.println("table:\n" + table.dump());
    assert list.isEmpty() : " list: " + Util.print(list);
  }