1 3 package org.jgroups.tests; 4 5 6 import junit.framework.TestCase; 7 import org.jgroups.Address; 8 import org.jgroups.stack.Retransmitter; 9 10 11 public class RetransmitterTest extends TestCase { 12 private final Address sender=new org.jgroups.stack.IpAddress(5555); 13 Retransmitter xmitter; 14 15 protected void setUp() throws Exception { 16 super.setUp(); 17 xmitter=new Retransmitter(sender, new MyXmitter()); 18 xmitter.setRetransmitTimeouts(new long[]{1000, 2000, 4000, 8000}); 19 } 20 21 22 public static void main(String [] args) { 23 String [] testCaseName={RetransmitterTest.class.getName()}; 24 junit.textui.TestRunner.main(testCaseName); 25 } 26 27 28 public void testNoEntry() { 29 int size=xmitter.size(); 30 System.out.println("xmitter: " + xmitter); 31 assertEquals(0, size); 32 } 33 34 public void testSingleEntry() { 35 xmitter.add(1, 1); 36 int size=xmitter.size(); 37 System.out.println("xmitter: " + xmitter); 38 assertEquals(1, size); 39 } 40 41 public void testEntry() { 42 xmitter.add(1, 10); 43 int size=xmitter.size(); 44 System.out.println("xmitter: " + xmitter); 45 assertEquals(10, size); 46 } 47 48 public void testMultipleEntries() { 49 xmitter.add(1, 10); 50 int size=xmitter.size(); 51 System.out.println("xmitter: " + xmitter); 52 assertEquals(10, size); 53 54 xmitter.add(12,13); 55 size=xmitter.size(); 56 System.out.println("xmitter: " + xmitter); 57 assertEquals(12, size); 58 59 xmitter.remove(5); 60 size=xmitter.size(); 61 System.out.println("xmitter: " + xmitter); 62 assertEquals(11, size); 63 64 xmitter.remove(13); 65 size=xmitter.size(); 66 System.out.println("xmitter: " + xmitter); 67 assertEquals(10, size); 68 69 xmitter.remove(1); 70 size=xmitter.size(); 71 System.out.println("xmitter: " + xmitter); 72 assertEquals(9, size); 73 74 xmitter.remove(13); 75 size=xmitter.size(); 76 System.out.println("xmitter: " + xmitter); 77 assertEquals(9, size); 78 79 xmitter.remove(12); 80 size=xmitter.size(); 81 System.out.println("xmitter: " + xmitter); 82 assertEquals(8, size); 83 84 for(int i=8; i >= 0; i--) 85 xmitter.remove(i); 86 size=xmitter.size(); 87 System.out.println("xmitter: " + xmitter); 88 assertEquals(2, size); 89 90 xmitter.remove(10); 91 size=xmitter.size(); 92 System.out.println("xmitter: " + xmitter); 93 assertEquals(1, size); 94 95 xmitter.remove(9); 96 size=xmitter.size(); 97 System.out.println("xmitter: " + xmitter); 98 assertEquals(0, size); 99 } 100 101 102 static class MyXmitter implements Retransmitter.RetransmitCommand { 103 104 public void retransmit(long first_seqno, long last_seqno, Address sender) { 105 } 106 } 107 108 } 109 | Popular Tags |