public void Test_IsExpected() { uint initialValue = 0; uint maxValue = 255; var mgr = new SeqNoManager(initialValue, maxValue, 3); mgr.UpdateAckSeq(0); var actual = mgr.IsExpected(1); Assert.AreEqual(true, actual); actual = mgr.IsExpected(2); Assert.AreEqual(true, actual); actual = mgr.IsExpected(3); Assert.AreEqual(true, actual); actual = mgr.IsExpected(4); Assert.AreEqual(false, actual); actual = mgr.IsExpected(5); Assert.AreEqual(false, actual); mgr.UpdateAckSeq(254); actual = mgr.IsExpected(255); Assert.AreEqual(true, actual); actual = mgr.IsExpected(0); Assert.AreEqual(true, actual); actual = mgr.IsExpected(1); Assert.AreEqual(true, actual); actual = mgr.IsExpected(2); Assert.AreEqual(false, actual); }
public void Test_UpdateSendSeq_MultiThread() { uint minValue = 0; uint maxValue = 65535; var result = new List <uint>(); uint singleCount = 100; var mgr = new SeqNoManager(minValue, maxValue, 1); var job = new Action(() => { for (var i = mgr.MinSendSeq; i <= singleCount; i++) { var value = mgr.GetAndUpdateSendSeq(); result.Add(value); } }); var jobCount = 5; var jobs = new List <Task>(); for (int i = 0; i < jobCount; i++) { var task1 = Task.Factory.StartNew(job); jobs.Add(task1); } jobs.ForEach(p => p.Wait()); Assert.AreEqual(jobCount * singleCount + jobCount - 1, result.Last()); }
/// <summary> /// 构造函数。 /// </summary> private SaiConnection(RsspEndPoint rsspEP, ISaiConnectionObserver observer) { _rsspEndPoint = rsspEP; _observer = observer; _seqNoManager = new SeqNoManager(0, ushort.MaxValue, rsspEP.SeqNoThreshold); _handshakeTimeoutMgr = new HandshakeTimeoutManager(SaiConnection.HandshakeTimeout, this); this.Initialize(); }
/// <summary> /// 构造函数。 /// </summary> protected AleConnection(RsspEndPoint rsspEP, IAuMessageBuilder auMsgProvider, IAleConnectionObserver observer, IAleTunnelEventNotifier tunnelEventNotifier) { _rsspEndPoint = rsspEP; _auMsgBuilder = auMsgProvider; _observer = observer; _tunnelEventNotifier = tunnelEventNotifier; _seqNoManager = new SeqNoManager(0, UInt16.MaxValue, rsspEP.SeqNoThreshold); this.Initialize(); }
public void Test_IsBeyondRange() { uint initialValue = 0; uint maxValue = 255; var mgr = new SeqNoManager(initialValue, maxValue, 6); mgr.UpdateAckSeq(252); var actual = mgr.IsBeyondRange(250); Assert.AreEqual(false, actual); actual = mgr.IsBeyondRange(251); Assert.AreEqual(false, actual); actual = mgr.IsBeyondRange(252); Assert.AreEqual(false, actual); actual = mgr.IsBeyondRange(253); Assert.AreEqual(false, actual); actual = mgr.IsBeyondRange(254); Assert.AreEqual(false, actual); actual = mgr.IsBeyondRange(255); Assert.AreEqual(false, actual); actual = mgr.IsBeyondRange(0); Assert.AreEqual(false, actual); actual = mgr.IsBeyondRange(1); Assert.AreEqual(false, actual); actual = mgr.IsBeyondRange(2); Assert.AreEqual(false, actual); actual = mgr.IsBeyondRange(3); Assert.AreEqual(true, actual); actual = mgr.IsBeyondRange(4); Assert.AreEqual(true, actual); actual = mgr.IsBeyondRange(5); Assert.AreEqual(true, actual); actual = mgr.IsBeyondRange(10); Assert.AreEqual(true, actual); }
public void Test_UpdateSendSeq() { uint number = 3; uint initialValue = 0; uint maxValue = 255; var mgr = new SeqNoManager(initialValue, maxValue, 3); for (uint i = initialValue; i < number * maxValue; i++) { var seqNo = mgr.GetAndUpdateSendSeq(); var expectedValue = i % (maxValue - initialValue + 1) + initialValue; Assert.AreEqual(expectedValue, seqNo); } }