Esempio 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);
  }
Esempio n. 2
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;
  }
Esempio n. 3
0
 public void testGet() {
   final Table<Integer> buf = new Table<Integer>(3, 10, 0);
   for (int i : Arrays.asList(1, 2, 3, 4, 5)) buf.add(i, i);
   assert buf.get(0) == null;
   assert buf.get(1) == 1;
   assert buf.get(10) == null;
   assert buf.get(5) == 5;
   assert buf.get(6) == null;
 }
Esempio n. 4
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));
      }
    }
  }
Esempio n. 5
0
  public void testGetList() {
    final Table<Integer> buf = new Table<Integer>(3, 10, 0);
    for (int i : Arrays.asList(1, 2, 3, 4, 5)) buf.add(i, i);
    List<Integer> elements = buf.get(3, 5);
    System.out.println("elements = " + elements);
    assert elements != null && elements.size() == 3;
    assert elements.contains(3) && elements.contains(4) && elements.contains(5);

    elements = buf.get(4, 10);
    System.out.println("elements = " + elements);
    assert elements != null && elements.size() == 2;
    assert elements.contains(4) && elements.contains(5);

    elements = buf.get(10, 20);
    assert elements == null;
  }
Esempio n. 6
0
 public void testPurge3() {
   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(true, 53);
   for (int i = 54; i <= 100; i++) assert table.get(i) == i;
 }
Esempio n. 7
0
 public static void testDuplicateAddition() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   addAndGet(table, 1, 5, 9, 10);
   assert !table.add(5, 5);
   assert table.get(5) == 5;
   assert table.size() == 4;
   assertIndices(table, 0, 0, 10);
 }
Esempio n. 8
0
 public static void testCreation() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   System.out.println("table = " + table);
   int size = table.size();
   assert size == 0;
   assert table.get(15) == null;
   assertIndices(table, 0, 0, 0);
 }
Esempio n. 9
0
 protected static void addAndGet(Table<Integer> table, int... seqnos) {
   for (int seqno : seqnos) {
     boolean added = table.add((long) seqno, seqno);
     assert added;
     Integer val = table.get(seqno);
     assert val != null && val == seqno;
   }
 }
Esempio n. 10
0
 public static void testAdditionListWithOffset() {
   Table<Integer> table = new Table<Integer>(3, 10, 100);
   long seqnos[] = {101, 105, 109, 110, 111, 119, 120, 129};
   List<Tuple<Long, Integer>> msgs = createList(seqnos);
   System.out.println("table: " + table.dump());
   assert table.add(msgs);
   assert table.size() == 8;
   for (long seqno : seqnos) assert table.get(seqno) == seqno;
   assertCapacity(table.capacity(), 3, 10);
   assertIndices(table, 100, 100, 129);
 }
Esempio n. 11
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;
  }
Esempio n. 12
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);
       }
     }
   }
 }
Esempio n. 13
0
 public static void testAdditionList() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   List<Tuple<Long, Integer>> msgs = createList(0);
   assert !table.add(msgs);
   long[] seqnos = {1, 5, 9, 10, 11, 19, 20, 29};
   msgs = createList(seqnos);
   assert table.add(msgs);
   System.out.println("table: " + table.dump());
   for (long seqno : seqnos) assert table.get(seqno) == seqno;
   assert table.size() == 8;
   int size = table.computeSize();
   assert size == 8;
   assert table.size() == table.computeSize();
   assertCapacity(table.capacity(), 3, 10);
   assertIndices(table, 0, 0, 29);
 }
Esempio n. 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));
      }
    }
  }
Esempio n. 15
0
  protected void handleXmitRequest(Address sender, SeqnoList missing) {
    if (log.isTraceEnabled())
      log.trace(
          new StringBuilder()
              .append(local_addr)
              .append(" <-- XMIT(")
              .append(sender)
              .append(": #")
              .append(missing)
              .append(')'));

    SenderEntry entry = send_table.get(sender);
    xmit_reqs_received.addAndGet(missing.size());
    Table<Message> win = entry != null ? entry.sent_msgs : null;
    if (win != null) {
      for (long seqno : missing) {
        Message msg = win.get(seqno);
        if (msg == null) {
          if (log.isWarnEnabled() && !local_addr.equals(sender)) {
            StringBuilder sb = new StringBuilder();
            sb.append("(requester=").append(sender).append(", local_addr=").append(this.local_addr);
            sb.append(") message ").append(sender).append("::").append(seqno);
            sb.append(" not found in retransmission table of ")
                .append(sender)
                .append(":\n")
                .append(win);
            log.warn(sb.toString());
          }
          continue;
        }

        down_prot.down(new Event(Event.MSG, msg));
        xmit_rsps_sent.incrementAndGet();
      }
    }
  }