예제 #1
0
  public static void testSetAndGetWith5Seqnos() {
    SeqnoRange range = new SeqnoRange(10, 15);
    System.out.println("range=" + print(range));

    assert range.size() == 6;
    assert range.getNumberOfMissingMessages() == 6;
    assert range.getNumberOfReceivedMessages() == 0;

    range.set(10);
    assert range.getNumberOfMissingMessages() == 5;
    assert range.getNumberOfReceivedMessages() == 1;

    assert range.get(10);

    range.set(13);
    assert range.size() == 6;
    assert range.getNumberOfMissingMessages() == 4;
    assert range.getNumberOfReceivedMessages() == 2;

    range.set(13);
    assert range.size() == 6;
    assert range.getNumberOfMissingMessages() == 4;
    assert range.getNumberOfReceivedMessages() == 2;

    System.out.println("range=" + print(range));

    Collection<Range> xmits = range.getMessagesToRetransmit();
    Collection<Range> cleared_bits = range.getBits(false);

    System.out.println("xmits = " + xmits);
    System.out.println("cleared_bits = " + cleared_bits);

    assert xmits.equals(cleared_bits);
  }
예제 #2
0
  public static void testLargeRange() {
    SeqnoRange range = new SeqnoRange(0, 1500);

    Set<Integer> sorted_set = new TreeSet<>();
    for (int i = 0; i < 500; i++) {
      int num = (int) Util.random(1499);
      sorted_set.add(num);
    }

    for (int num : sorted_set) range.set(num);

    int num_set = sorted_set.size();
    System.out.println("set " + num_set + " bits");
    assert range.getNumberOfReceivedMessages() == num_set;
    Collection<Range> missing = range.getMessagesToRetransmit();
    System.out.println("missing = " + missing);
  }
예제 #3
0
  public static void testSet() {
    SeqnoRange range = new SeqnoRange(10, 15);
    range.set(11, 12, 13, 14);
    System.out.println("range=" + print(range));
    assert range.size() == 6;
    assert range.getNumberOfReceivedMessages() == 4;
    assert range.getNumberOfMissingMessages() == 2;
    Collection<Range> xmits = range.getMessagesToRetransmit();
    assert xmits.size() == 2;
    Iterator<Range> it = xmits.iterator();
    Range r = it.next();
    assert r.low == 10 && r.high == 10;
    r = it.next();
    assert r.low == 15 && r.high == 15;

    range = new SeqnoRange(10, 15);
    range.set(10, 11, 12, 13, 14);
    System.out.println("range=" + print(range));
    assert range.size() == 6;
    assert range.getNumberOfReceivedMessages() == 5;
    assert range.getNumberOfMissingMessages() == 1;
    xmits = range.getMessagesToRetransmit();
    assert xmits.size() == 1;
    it = xmits.iterator();
    r = it.next();
    assert r.low == 15 && r.high == 15;

    range = new SeqnoRange(10, 15);
    range.set(11, 12, 13, 14, 15);
    System.out.println("range=" + print(range));
    assert range.size() == 6;
    assert range.getNumberOfReceivedMessages() == 5;
    assert range.getNumberOfMissingMessages() == 1;
    xmits = range.getMessagesToRetransmit();
    assert xmits.size() == 1;
    it = xmits.iterator();
    r = it.next();
    assert r.low == 10 && r.high == 10;

    range = new SeqnoRange(10, 15);
    range.set(10, 11, 12, 13, 14, 15);
    System.out.println("range=" + print(range));
    assert range.size() == 6;
    assert range.getNumberOfReceivedMessages() == 6;
    assert range.getNumberOfMissingMessages() == 0;
    xmits = range.getMessagesToRetransmit();
    assert xmits.isEmpty();

    range = new SeqnoRange(10, 15);
    range.set(11, 12, 14, 15);
    System.out.println("range=" + print(range));
    assert range.size() == 6;
    assert range.getNumberOfReceivedMessages() == 4;
    assert range.getNumberOfMissingMessages() == 2;
    xmits = range.getMessagesToRetransmit();
    assert xmits.size() == 2;
    it = xmits.iterator();
    r = it.next();
    assert r.low == 10 && r.high == 10;
    r = it.next();
    assert r.low == 13 && r.high == 13;

    range.set(13);
    assert range.getNumberOfReceivedMessages() == 5;
    assert range.getNumberOfMissingMessages() == 1;
    xmits = range.getMessagesToRetransmit();
    it = xmits.iterator();
    r = it.next();
    assert r.low == 10 && r.high == 10;

    range.set(10);
    System.out.println("range=" + print(range));
    assert range.getNumberOfReceivedMessages() == 6;
    assert range.getNumberOfMissingMessages() == 0;
    xmits = range.getMessagesToRetransmit();
    assert xmits.isEmpty();
  }