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
  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);
  }
Example #3
0
 public static void testMove3() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   for (int i = 1; i < 30; i++) table.add(i, i);
   table.removeMany(true, 23);
   System.out.println("table = " + table);
   table.add(30, 30); // triggers a resize() --> move()
   for (int i = 1; i <= 23; i++) assert table._get(i) == null;
   for (int i = 24; i < 30; i++) assert table._get(i) != null;
 }
Example #4
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;
  }
Example #5
0
  public void testRemoveManyWithNulling() {
    Table<Integer> buf = new Table<Integer>(3, 10, 0);
    for (int i : Arrays.asList(1, 2, 3, 4, 5, 6, 7, 9, 10)) buf.add(i, i);
    List<Integer> list = buf.removeMany(true, 3);
    System.out.println("list = " + list);
    assert list != null && list.size() == 3;
    for (int i : list) assert buf._get(i) == null;

    list = buf.removeMany(true, 0);
    System.out.println("list = " + list);
    assert list != null && list.size() == 4;
    for (int i : list) assert buf._get(i) == null;

    list = buf.removeMany(false, 10);
    assert list == null;

    buf.add(8, 8);
    list = buf.removeMany(true, 0);
    System.out.println("list = " + list);
    assert list != null && list.size() == 3;
    for (int i : list) assert buf._get(i) == null;
  }
Example #6
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 #7
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);
  }
Example #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";
  }
Example #9
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";
 }
Example #10
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);
  }