Example #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";
  }
Example #2
0
 protected static <T> void assertIndices(Table<T> table, long low, long hd, long hr) {
   assert table.getLow() == low : "expected low=" + low + " but was " + table.getLow();
   assert table.getHighestDelivered() == hd
       : "expected hd=" + hd + " but was " + table.getHighestDelivered();
   assert table.getHighestReceived() == hr
       : "expected hr=" + hr + " but was " + table.getHighestReceived();
 }
Example #3
0
  /**
   * We need to resend our first message with our conn_id
   *
   * @param sender
   * @param seqno Resend the non null messages in the range [lowest .. seqno]
   */
  protected void handleResendingOfFirstMessage(Address sender, long seqno) {
    if (log.isTraceEnabled())
      log.trace(local_addr + " <-- SEND_FIRST_SEQNO(" + sender + "," + seqno + ")");
    SenderEntry entry = send_table.get(sender);
    Table<Message> win = entry != null ? entry.sent_msgs : null;
    if (win == null) {
      if (log.isErrorEnabled())
        log.error(local_addr + ": sender window for " + sender + " not found");
      return;
    }

    boolean first_sent = false;
    for (long i = win.getLow() + 1; i <= seqno; i++) {
      Message rsp = win.get(i);
      if (rsp == null) continue;
      if (first_sent) {
        down_prot.down(new Event(Event.MSG, rsp));
      } else {
        first_sent = true;
        // We need to copy the UnicastHeader and put it back into the message because Message.copy()
        // doesn't copy
        // the headers and therefore we'd modify the original message in the sender retransmission
        // window
        // (https://jira.jboss.org/jira/browse/JGRP-965)
        Message copy = rsp.copy();
        Unicast2Header hdr = (Unicast2Header) copy.getHeader(this.id);
        Unicast2Header newhdr = hdr.copy();
        newhdr.first = true;
        copy.putHeader(this.id, newhdr);
        down_prot.down(new Event(Event.MSG, copy));
      }
    }
  }
Example #4
0
  public static void testForEach() {
    class MyVisitor<T> implements Table.Visitor<T> {
      List<int[]> list = new ArrayList<int[]>(20);

      public boolean visit(long seqno, T element, int row, int column) {
        System.out.println("#" + seqno + ": " + element + ", row=" + row + ", column=" + column);
        list.add(new int[] {row, column});
        return true;
      }
    }
    MyVisitor<Integer> visitor = new MyVisitor<Integer>();

    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 20; i++) table.add(i, i);
    System.out.println("table = " + table);
    table.forEach(table.getLow() + 1, table.getHighestReceived() - 1, visitor);
    int count = 1;
    for (int[] pair : visitor.list) {
      int row = pair[0], column = pair[1];
      if (count < Util.getNextHigherPowerOfTwo(10)) {
        assert row == 0;
        assert column == count;
      } else {
        assert row == 1;
        assert column == count - Util.getNextHigherPowerOfTwo(10);
      }
      count++;
    }
  }
Example #5
0
 public void testIndexWithRemoveMany() {
   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);
   long low = buf.getLow();
   buf.removeMany(true, 0);
   System.out.println("buf = " + buf);
   for (long i = low; i <= 7; i++)
     assert buf._get(i) == null : "message with seqno=" + i + " is not null";
   assertIndices(buf, 7, 7, 7);
 }
Example #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";
  }
Example #7
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";
 }