01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.net.protocol.delivery;
05:
06: import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
07:
08: import com.tc.net.protocol.tcm.NullMessageMonitor;
09: 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 {
19: LinkedQueue receiveQueue = new LinkedQueue();
20: TestProtocolMessageDelivery delivery = new TestProtocolMessageDelivery(
21: receiveQueue);
22: ReceiveStateMachine rsm = new ReceiveStateMachine(delivery);
23: TestProtocolMessage tpm = new TestProtocolMessage();
24: tpm.isHandshake = true;
25:
26: rsm.start();
27:
28: tpm.msg = new PingMessage(new NullMessageMonitor());
29: tpm.sent = 0;
30: tpm.isSend = true;
31:
32: assertEquals(0, delivery.receivedMessageCount);
33: //REceive message
34: rsm.execute(tpm);
35: int received = delivery.receivedMessageCount;
36: assertTrue(delivery.receivedMessageCount > 0);
37: assertTrue(receiveQueue.poll(0) != null);
38:
39: //Receive a second time
40: rsm.execute(tpm);
41: assertEquals(received, delivery.receivedMessageCount);
42: assertTrue(receiveQueue.poll(0) == null);
43: }
44: }
|