1 package org.jgroups.tests; 2 3 4 import junit.framework.Test; 5 import junit.framework.TestCase; 6 import junit.framework.TestSuite; 7 import org.jgroups.Message; 8 import org.jgroups.stack.AckReceiverWindow; 9 10 11 15 public class AckReceiverWindowTest extends TestCase { 16 AckReceiverWindow win; 17 18 19 public AckReceiverWindowTest(String name) { 20 super(name); 21 } 22 23 public void setUp() throws Exception { 24 super.setUp(); 25 } 26 27 public void tearDown() throws Exception { 28 super.tearDown(); 29 } 30 31 public void test1() { 32 Message m; 33 win=new AckReceiverWindow(10); 34 assertEquals(0, win.size()); 35 win.add(9, msg()); 36 assertEquals(0, win.size()); 37 38 win.add(10, msg()); 39 assertEquals(1, win.size()); 40 41 win.add(13, msg()); 42 assertEquals(2, win.size()); 43 44 m=win.remove(); 45 assertNotNull(m); 46 assertEquals(1, win.size()); 47 48 m=win.remove(); 49 assertNull(m); 50 assertEquals(1, win.size()); 51 52 win.add(11, msg()); 53 win.add(12, msg()); 54 assertEquals(3, win.size()); 55 56 m=win.remove(); 57 assertNotNull(m); 58 m=win.remove(); 59 assertNotNull(m); 60 m=win.remove(); 61 assertNotNull(m); 62 assertEquals(0, win.size()); 63 m=win.remove(); 64 assertNull(m); 65 } 66 67 68 public void testDuplicates() { 69 boolean rc; 70 win=new AckReceiverWindow(2); 71 assertEquals(0, win.size()); 72 rc=win.add(9, msg()); 73 assertTrue(rc); 74 rc=win.add(1, msg()); 75 assertFalse(rc); 76 rc=win.add(2, msg()); 77 assertTrue(rc); 78 rc=win.add(2, msg()); 79 assertFalse(rc); 80 rc=win.add(0, msg()); 81 assertFalse(rc); 82 rc=win.add(3, msg()); 83 assertTrue(rc); 84 rc=win.add(4, msg()); 85 assertTrue(rc); 86 rc=win.add(4, msg()); 87 assertFalse(rc); 88 } 89 90 private Message msg() { 91 return new Message(); 92 } 93 94 95 public static Test suite() { 96 return new TestSuite(AckReceiverWindowTest.class); 97 } 98 99 100 public static void main(String [] args) { 101 String [] testCaseName={AckReceiverWindowTest.class.getName()}; 102 junit.textui.TestRunner.main(testCaseName); 103 } 104 105 } 106 | Popular Tags |