1 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 17 public class SendStateMachineTest extends TestCase { 18 public void tests() throws Exception { 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 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 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 ssm.execute(tpm); 47 ssm.execute(tpm); 48 assertTrue(delivery.created); 49 assertTrue(delivery.msg.getSent() == 1); 50 51 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 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 ssm.resume(); 74 assertFalse(ssm.isPaused()); 75 assertTrue(!delivery.created); 76 assertTrue(delivery.sentAckRequest); 77 } 78 } | Popular Tags |