Пример #1
0
  public static void testResize() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    assertCapacity(table.capacity(), table.getNumRows(), 10);
    addAndGet(table, 30);
    addAndGet(table, 35);
    assertCapacity(table.capacity(), table.getNumRows(), 10);
    addAndGet(table, 500);
    assertCapacity(table.capacity(), table.getNumRows(), 10);

    addAndGet(table, 515);
    assertCapacity(table.capacity(), table.getNumRows(), 10);
  }
Пример #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;
  }
Пример #3
0
 public static void testAdditionWithOffset() {
   Table<Integer> table = new Table<Integer>(3, 10, 100);
   addAndGet(table, 101, 105, 109, 110, 111, 119, 120, 129);
   System.out.println("table: " + table.dump());
   assert table.size() == 8;
   assertCapacity(table.capacity(), 3, 10);
   assertIndices(table, 100, 100, 129);
 }
Пример #4
0
 public static void testMove() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   for (int i = 1; i < 50; i++) addAndGet(table, i);
   table.removeMany(true, 49);
   assert table.isEmpty();
   addAndGet(table, 50);
   assert table.size() == 1;
   assertCapacity(table.capacity(), table.getNumRows(), 10);
 }
Пример #5
0
 public static void testMassAddition() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   final int NUM_ELEMENTS = 10005;
   for (int i = 1; i <= NUM_ELEMENTS; i++) table.add(i, i);
   System.out.println("table = " + table);
   assert table.size() == NUM_ELEMENTS;
   assertCapacity(table.capacity(), table.getNumRows(), 10);
   assertIndices(table, 0, 0, NUM_ELEMENTS);
   assert table.getNumMissing() == 0;
 }
Пример #6
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);
 }
Пример #7
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);
  }
Пример #8
0
 public static void testAddition() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   assert !table.add(0, 0);
   addAndGet(table, 1, 5, 9, 10, 11, 19, 20, 29);
   System.out.println("table: " + table.dump());
   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);
 }
Пример #9
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);
 }
Пример #10
0
 public void testCompact() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   for (int i = 1; i <= 80; i++) addAndGet(table, i);
   assert table.size() == 80;
   assertIndices(table, 0, 0, 80);
   List<Integer> list = table.removeMany(false, 60);
   assert list.size() == 60;
   assert list.get(0) == 1 && list.get(list.size() - 1) == 60;
   assertIndices(table, 0, 60, 80);
   table.purge(60);
   assertIndices(table, 60, 60, 80);
   assert table.size() == 20;
   table.compact();
   assertIndices(table, 60, 60, 80);
   assert table.size() == 20;
   assertCapacity(table.capacity(), table.getNumRows(), 10);
 }
Пример #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);
  }