KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > protocol > delivery > SendStateMachineTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.net.protocol.delivery;
5
6 import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
7
8 import com.tc.net.protocol.tcm.MessageMonitor;
9 import com.tc.net.protocol.tcm.NullMessageMonitor;
10 import com.tc.net.protocol.tcm.msgs.PingMessage;
11
12 import junit.framework.TestCase;
13
14 /**
15  *
16  */

17 public class SendStateMachineTest extends TestCase {
18   public void tests() throws Exception JavaDoc {
19     TestProtocolMessageDelivery delivery = new TestProtocolMessageDelivery(new LinkedQueue());
20     LinkedQueue sendQueue = new LinkedQueue();
21     SendStateMachine ssm = new SendStateMachine(delivery, sendQueue);
22     ssm.start();
23     ssm.resume();
24
25     TestProtocolMessage tpm = new TestProtocolMessage(null, -1, -1);
26     tpm.isSend = true;
27     
28     //SEND
29
MessageMonitor monitor = new NullMessageMonitor();
30     sendQueue.put(new PingMessage(monitor));
31     ssm.execute(null);
32     assertTrue(delivery.created);
33     assertTrue(delivery.msg.getSent() == 0);
34     delivery.clear();
35
36     //Call send an extra time with nothing on the send queue
37
ssm.execute(tpm);
38     assertTrue(delivery.created == false);
39     tpm.isSend = false;
40
41     sendQueue.put(new PingMessage(monitor));
42     sendQueue.put(new PingMessage(monitor));
43     tpm.ack = 0;
44
45     //ACK
46
ssm.execute(tpm);
47     ssm.execute(tpm);
48     assertTrue(delivery.created);
49     assertTrue(delivery.msg.getSent() == 1);
50
51     //RESEND
52
delivery.clear();
53     tpm.ack = 0;
54     ssm.execute(tpm);
55     assertTrue(delivery.created);
56     assertTrue(delivery.msg.getSent() == 1);
57
58     tpm.ack = 1;
59     ssm.execute(tpm);
60
61     delivery.clear();
62
63     //SEND
64
ssm.execute(tpm);
65     assertTrue(delivery.created);
66     assertTrue(delivery.msg.getSent() == 2);
67
68     ssm.pause();
69     assertTrue(ssm.isPaused());
70
71     delivery.clear();
72     //test ack request
73
ssm.resume();
74     assertFalse(ssm.isPaused());
75     assertTrue(!delivery.created);
76     assertTrue(delivery.sentAckRequest);
77   }
78 }
Popular Tags