public void testGetMissing5() { Table<Integer> buf = new Table<Integer>(3, 10, 0); buf.add(1, 1); SeqnoList missing = buf.getMissing(); System.out.println("missing = " + missing); assert missing == null && buf.getNumMissing() == 0; buf = new Table<Integer>(3, 10, 0); buf.add(10, 10); missing = buf.getMissing(); System.out.println("missing = " + missing); assert buf.getNumMissing() == missing.size(); buf = new Table<Integer>(3, 10, 0); buf.add(5, 5); missing = buf.getMissing(); System.out.println("missing = " + missing); assert buf.getNumMissing() == missing.size(); buf = new Table<Integer>(3, 10, 0); buf.add(5, 5); buf.add(7, 7); missing = buf.getMissing(); System.out.println("missing = " + missing); assert missing.size() == 5; assert buf.getNumMissing() == missing.size(); }
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; }
public static void testGetNullMessages() { Table<Integer> table = new Table<Integer>(3, 10, 0); table.add(1, 1); table.add(100, 100); System.out.println("table = " + table); int num_null_elements = table.getNumMissing(); assert num_null_elements == 98; // [2 .. 99] table.add(50, 50); System.out.println("table = " + table); assert table.size() == 3; assert table.getNumMissing() == 97; }
public static void testRemoveManyWithWrapping2() { Table<Integer> table = new Table<Integer>(3, 10, 0); for (int seqno : Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 20)) table.add(seqno, seqno); System.out.println("table = " + table); assertIndices(table, 0, 0, 20); assert table.size() == 18 && table.getNumMissing() == 2; List<Integer> list = table.removeMany(false, 0); assert list.size() == 12; assertIndices(table, 0, 12, 20); assert table.size() == 6 && table.getNumMissing() == 2; table.purge(12); assertIndices(table, 12, 12, 20); assert table.size() == 6 && table.getNumMissing() == 2; }
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"; }
public static void testGetMissingFirst() { Table<Integer> table = new Table<Integer>(3, 10, 0); for (int num : Arrays.asList(2, 3, 4, 5)) table.add(num, num); System.out.println("table = " + table); SeqnoList missing = table.getMissing(); System.out.println("missing=" + missing); assert missing.size() == 1; assert table.getNumMissing() == 1; }
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; }
public void run() { for (Map.Entry<Address, ReceiverEntry> entry : recv_table.entrySet()) { Address target = entry.getKey(); // target to send retransmit requests to ReceiverEntry val = entry.getValue(); Table<Message> buf = val != null ? val.received_msgs : null; if (buf != null && buf.getNumMissing() > 0) { SeqnoList missing = buf.getMissing(); if (missing != null) retransmit(missing, target); } } }
public void testGetMissing4() { Table<Integer> buf = new Table<Integer>(3, 30, 0); for (int i : Arrays.asList(2, 5, 10, 11, 12, 13, 15, 20, 28, 30)) buf.add(i, i); System.out.println("buf = " + buf); int missing = buf.getNumMissing(); assert missing == 20; System.out.println("missing=" + missing); SeqnoList missing_list = buf.getMissing(); System.out.println("missing_list = " + missing_list); assert missing_list.size() == missing; }
public static void testRemoveMany() { Table<Integer> table = new Table<Integer>(3, 10, 0); for (int seqno : Arrays.asList(1, 2, 3, 4, 5, 7, 8, 9, 10)) table.add(seqno, seqno); System.out.println("table = " + table); assertIndices(table, 0, 0, 10); List<Integer> list = table.removeMany(true, 4); System.out.println("list=" + list + ", table=" + table); assert table.size() == 5 && table.getNumMissing() == 1; assert list != null && list.size() == 4; for (int num : Arrays.asList(1, 2, 3, 4)) assert list.contains(num); assertIndices(table, 4, 4, 10); }
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; }
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); }
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; }
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); }