@Test(dataProvider = "createTimer") public void test9(TimeScheduler timer) throws Exception { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); win.add(1, new Message()); win.add(2, new Message()); win.add(3, new Message()); win.add(4, new Message()); win.add(6, new Message()); System.out.println("win: " + win); while ((win.remove()) != null) ; win.stable(6); // 6 is ignore as it is >= highest delivered message System.out.println("win: " + win); assert win.get(2) != null; check(win, 0, 6, 4); win.add(5, new Message()); check(win, 0, 6, 4); while ((win.remove()) != null) ; check(win, 0, 6, 6); win.stable(6); check(win, 6, 6, 6); } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void test8(TimeScheduler timer) throws Exception { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); win.add(1, new Message()); win.add(2, new Message()); win.add(3, new Message()); win.add(4, new Message()); win.add(6, new Message()); check(win, 0, 6, 0); // haven't delivered a message yet while (win.remove() != null) ; check(win, 0, 6, 4); win.add(5, new Message()); check(win, 0, 6, 4); win.remove(); check(win, 0, 6, 5); win.remove(); check(win, 0, 6, 6); win.stable(4); check(win, 4, 6, 6); win.stable(6); check(win, 6, 6, 6); } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void test12(TimeScheduler timer) throws Exception { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); win.add(1, new Message(null, null, new Integer(1))); win.add(2, new Message(null, null, new Integer(2))); win.add(3, new Message(null, null, new Integer(3))); Assert.assertEquals(1, ((Integer) win.remove().getObject()).intValue()); Assert.assertEquals(2, ((Integer) win.remove().getObject()).intValue()); Assert.assertEquals(3, ((Integer) win.remove().getObject()).intValue()); } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void testMissingMessages5(TimeScheduler timer) throws Exception { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 100, timer); win.add(101, new Message()); check(win, 0, 101, 100); win.add(108, new Message()); check(win, 0, 108, 100); win.remove(); win.add(109, new Message()); check(win, 0, 109, 101); System.out.println("win: " + win); win.add(102, new Message()); check(win, 0, 109, 101); win.add(103, new Message()); win.add(104, new Message()); check(win, 0, 109, 101); win.add(107, new Message()); check(win, 0, 109, 101); win.add(106, new Message()); win.add(105, new Message()); check(win, 0, 109, 101); win.add(110, new Message()); check(win, 0, 110, 101); win.add(110, new Message()); check(win, 0, 110, 101); System.out.println("win: " + win); } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void testHighestDelivered(TimeScheduler timer) throws Exception { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); win.add(1, new Message()); win.add(2, new Message()); win.add(3, new Message()); win.add(4, new Message()); check(win, 0, 4, 0); win.add(10, new Message()); check(win, 0, 10, 0); System.out.println("win: " + win); win.add(9, new Message()); win.add(7, new Message()); win.add(8, new Message()); win.add(6, new Message()); win.add(5, new Message()); System.out.println("win: " + win); check(win, 0, 10, 0); while ((win.remove()) != null) ; check(win, 0, 10, 10); win.stable(5); System.out.println("win: " + win); check(win, 5, 10, 10); win.stable(10); System.out.println("win: " + win); check(win, 10, 10, 10); } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void testAdd(TimeScheduler timer) throws Exception { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); check(win, 0, 0, 0); win.add(0, new Message()); // discarded, next expected is 1 check(win, 0, 0, 0); win.add(1, new Message()); check(win, 0, 1, 0); win.add(2, new Message()); win.add(3, new Message()); win.add(4, new Message()); check(win, 0, 4, 0); win.add(6, new Message()); check(win, 0, 6, 0); win.add(5, new Message()); check(win, 0, 6, 0); while (win.remove() != null) ; check(win, 0, 6, 6); win.stable(4); check(win, 4, 6, 6); win.stable(6); check(win, 6, 6, 6); } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void test6(TimeScheduler timer) throws Exception { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 100, timer); win.add(101, new Message()); System.out.println("win: " + win); win.add(100, new Message()); System.out.println("win: " + win); check(win, 0, 101, 100); win.remove(); System.out.println("win: " + win); check(win, 0, 101, 101); while ((win.remove()) != null) ; check(win, 0, 101, 101); } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void testHasMessagesToRemove(TimeScheduler timer) { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); assert !win.hasMessagesToRemove(); win.add(2, new Message()); assert !win.hasMessagesToRemove(); win.add(1, oob()); assert win.hasMessagesToRemove(); win.remove(); assert win.hasMessagesToRemove(); win.remove(); assert !win.hasMessagesToRemove(); } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void test3(TimeScheduler timer) throws Exception { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); win.add(1, new Message()); assert win.get(1) != null; check(win, 0, 1, 0); win.add(2, new Message()); check(win, 0, 2, 0); assert win.get(2) != null; win.remove(); check(win, 0, 2, 1); win.remove(); check(win, 0, 2, 2); } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void testRemoveOOBMessage(TimeScheduler timer) { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); System.out.println("win = " + win); win.add(2, msg()); System.out.println("win = " + win); assert win.removeOOBMessage() == null; assert win.remove() == null; win.add(1, oob()); System.out.println("win = " + win); assert win.removeOOBMessage() != null; System.out.println("win = " + win); assert win.removeOOBMessage() == null; assert win.remove() != null; assert win.remove() == null; assert win.removeOOBMessage() == null; } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void test10(TimeScheduler timer) throws Exception { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); win.add(1, new Message()); win.add(2, new Message()); win.add(3, new Message()); win.add(4, new Message()); while ((win.remove()) != null) ; check(win, 0, 4, 4); } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void testRemoveRegularAndOOBMessages(TimeScheduler timer) { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); win.add(1, msg()); System.out.println("win = " + win); win.remove(); System.out.println("win = " + win); assert win.getHighestDelivered() == 1; win.add(3, msg()); win.remove(); System.out.println("win = " + win); assert win.getHighestDelivered() == 1; win.add(2, oob()); win.removeOOBMessage(); System.out.println("win = " + win); assert win.getHighestDelivered() == 2; } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void test7(TimeScheduler timer) throws Exception { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); win.add(1, new Message()); win.add(2, new Message()); win.add(3, new Message()); win.add(4, new Message()); check(win, 0, 4, 0); System.out.println("Note that the subsequent warning is expected:"); win.stable(4); // no-op because we haven't even removed 4 messages check(win, 0, 4, 0); while (win.remove() != null) ; check(win, 0, 4, 4); win.stable(4); check(win, 4, 4, 4); } finally { timer.stop(); } }
@Test(dataProvider = "createTimer") public void testRemoveOOBMessages(TimeScheduler timer) { try { NakReceiverWindow win = new NakReceiverWindow(sender, cmd, 0, timer); win.add(0, msg()); List<Message> list = win.removeOOBMessages(); assert list.isEmpty(); win.add(1, oob()); win.add(2, oob()); win.add(3, msg()); win.add(4, oob()); list = win.removeOOBMessages(); assert list.size() == 2; list = win.removeOOBMessages(); assert list.isEmpty(); win.remove(); list = win.removeOOBMessages(); assert list.size() == 1; } finally { timer.stop(); } }