KickJava   Java API By Example, From Geeks To Geeks.

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


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.NullMessageMonitor;
9 import com.tc.net.protocol.tcm.msgs.PingMessage;
10
11 import junit.framework.TestCase;
12
13 /**
14  *
15  */

16 public class ReceiveStateMachineTest extends TestCase {
17
18   public void tests() throws Exception JavaDoc {
19     LinkedQueue receiveQueue = new LinkedQueue();
20     TestProtocolMessageDelivery delivery = new TestProtocolMessageDelivery(receiveQueue);
21     ReceiveStateMachine rsm = new ReceiveStateMachine(delivery);
22     TestProtocolMessage tpm = new TestProtocolMessage();
23     tpm.isAckRequest = true;
24
25     rsm.start();
26
27     // Ack request
28
rsm.execute(tpm);
29     assertTrue(delivery.sentAck);
30
31     delivery.clear();
32
33     tpm.msg = new PingMessage(new NullMessageMonitor());
34     tpm.sent = 0;
35     tpm.isAckRequest = false;
36
37     assertEquals(0, delivery.receivedMessageCount);
38     //REceive message
39
rsm.execute(tpm);
40     int received = delivery.receivedMessageCount;
41     assertTrue(delivery.receivedMessageCount > 0);
42     assertTrue(receiveQueue.poll(0) != null);
43     
44     //Receive a second time
45
rsm.execute(tpm);
46     assertEquals(received, delivery.receivedMessageCount);
47     assertTrue(receiveQueue.poll(0) == null);
48   }
49 }
Popular Tags