001: // $Id: RetransmitterTest.java,v 1.2 2005/08/29 11:52:22 belaban Exp $
002:
003: package org.jgroups.tests;
004:
005: import junit.framework.TestCase;
006: import org.jgroups.Address;
007: import org.jgroups.stack.Retransmitter;
008:
009: public class RetransmitterTest extends TestCase {
010: private final Address sender = new org.jgroups.stack.IpAddress(5555);
011: Retransmitter xmitter;
012:
013: protected void setUp() throws Exception {
014: super .setUp();
015: xmitter = new Retransmitter(sender, new MyXmitter());
016: xmitter.setRetransmitTimeouts(new long[] { 1000, 2000, 4000,
017: 8000 });
018: }
019:
020: public static void main(String[] args) {
021: String[] testCaseName = { RetransmitterTest.class.getName() };
022: junit.textui.TestRunner.main(testCaseName);
023: }
024:
025: public void testNoEntry() {
026: int size = xmitter.size();
027: System.out.println("xmitter: " + xmitter);
028: assertEquals(0, size);
029: }
030:
031: public void testSingleEntry() {
032: xmitter.add(1, 1);
033: int size = xmitter.size();
034: System.out.println("xmitter: " + xmitter);
035: assertEquals(size, 1);
036: }
037:
038: public void testEntry() {
039: xmitter.add(1, 10);
040: int size = xmitter.size();
041: System.out.println("xmitter: " + xmitter);
042: assertEquals(10, size);
043: }
044:
045: public void testMultipleEntries() {
046: xmitter.add(1, 10);
047: int size = xmitter.size();
048: System.out.println("xmitter: " + xmitter);
049: assertEquals(10, size);
050:
051: xmitter.add(12, 13);
052: size = xmitter.size();
053: System.out.println("xmitter: " + xmitter);
054: assertEquals(12, size);
055:
056: xmitter.remove(5);
057: size = xmitter.size();
058: System.out.println("xmitter: " + xmitter);
059: assertEquals(11, size);
060:
061: xmitter.remove(13);
062: size = xmitter.size();
063: System.out.println("xmitter: " + xmitter);
064: assertEquals(10, size);
065:
066: xmitter.remove(1);
067: size = xmitter.size();
068: System.out.println("xmitter: " + xmitter);
069: assertEquals(9, size);
070:
071: xmitter.remove(13);
072: size = xmitter.size();
073: System.out.println("xmitter: " + xmitter);
074: assertEquals(9, size);
075:
076: xmitter.remove(12);
077: size = xmitter.size();
078: System.out.println("xmitter: " + xmitter);
079: assertEquals(8, size);
080:
081: for (int i = 8; i >= 0; i--)
082: xmitter.remove(i);
083: size = xmitter.size();
084: System.out.println("xmitter: " + xmitter);
085: assertEquals(2, size);
086:
087: xmitter.remove(10);
088: size = xmitter.size();
089: System.out.println("xmitter: " + xmitter);
090: assertEquals(1, size);
091:
092: xmitter.remove(9);
093: size = xmitter.size();
094: System.out.println("xmitter: " + xmitter);
095: assertEquals(0, size);
096: }
097:
098: class MyXmitter implements Retransmitter.RetransmitCommand {
099:
100: public void retransmit(long first_seqno, long last_seqno,
101: Address sender) {
102: }
103: }
104:
105: }
|