Esempio n. 1
0
  public void testAddMissing() {
    Table<Integer> buf = new Table<Integer>(3, 10, 0);
    for (int i : Arrays.asList(1, 2, 4, 5, 6)) buf.add(i, i);
    System.out.println("buf = " + buf);
    assert buf.size() == 5 && buf.getNumMissing() == 1;

    Integer num = buf.remove();
    assert num == 1;
    num = buf.remove();
    assert num == 2;
    num = buf.remove();
    assert num == null;

    buf.add(3, 3);
    System.out.println("buf = " + buf);
    assert buf.size() == 4 && buf.getNumMissing() == 0;

    for (int i = 3; i <= 6; i++) {
      num = buf.remove();
      System.out.println("buf = " + buf);
      assert num == i;
    }

    num = buf.remove();
    assert num == null;
  }
Esempio n. 2
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";
  }
Esempio n. 3
0
  public void testRemove2() {
    final Table<Integer> buf = new Table<Integer>(3, 10, 0);
    for (int i : Arrays.asList(1, 2, 3, 4, 5)) buf.add(i, i);
    System.out.println("buf = " + buf);
    assertIndices(buf, 0, 0, 5);

    Integer el = buf.remove(true);
    System.out.println("el = " + el);
    assert el.equals(1);

    el = buf.remove(false); // not encouraged ! nullify should always be true or false
    System.out.println("el = " + el);
    assert el.equals(2);

    el = buf.remove(true);
    System.out.println("el = " + el);
    assert el.equals(3);
  }
Esempio n. 4
0
 public static void testComputeSize2() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   table.add(1, 1);
   System.out.println("table = " + table);
   assert table.computeSize() == table.size();
   assert table.computeSize() == 1;
   table.remove(false);
   System.out.println("table = " + table);
   assert table.computeSize() == table.size();
   assert table.computeSize() == 0;
 }
Esempio n. 5
0
  public void testCompact2() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 80; i++) addAndGet(table, i);
    assert table.size() == 80;
    for (long i = 1; i <= 60; i++) table.remove();

    assert table.size() == 20;
    table.compact();
    assert table.size() == 20;
    assertCapacity(table.capacity(), table.getNumRows(), 10);
  }
Esempio n. 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";
  }
Esempio n. 7
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);
  }
Esempio n. 8
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();
  }
Esempio n. 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";
 }
Esempio n. 10
0
  public static void testRemove() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 9; i++) table.add(i, i);
    table.add(20, 20);
    System.out.println("table = " + table);
    assert table.size() == 10;
    assertIndices(table, 0, 0, 20);

    int num_null_msgs = table.getNumMissing();
    System.out.println("num_null_msgs = " + num_null_msgs);
    assert num_null_msgs == 10;

    for (long i = 1; i <= 10; i++) // 10 is missing
    table.remove();
    System.out.println("table = " + table);
    assert table.size() == 1;
    assertIndices(table, 9, 9, 20);

    num_null_msgs = table.getNumMissing();
    System.out.println("num_null_msgs = " + num_null_msgs);
    assert num_null_msgs == 10;
  }
Esempio n. 11
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);
  }
Esempio n. 12
0
  public static void testGetNullMessages2() {
    Table<Integer> table = new Table<Integer>(1, 10, 0);
    table.add(1, 1);
    table.add(5, 5);
    System.out.println("table = " + table);
    int num_null_elements = table.getNumMissing();
    assert num_null_elements == 3; // [2 .. 4]

    table.add(10, 10);
    System.out.println("table = " + table);
    assert table.size() == 3;
    assert table.getNumMissing() == 7;

    table.add(14, 14);
    System.out.println("table = " + table);
    assert table.size() == 4;
    assert table.getNumMissing() == 10;

    while (table.remove() != null) ;
    System.out.println("table = " + table);
    assert table.size() == 3;
    assert table.getNumMissing() == 10;
  }