Beispiel #1
0
        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());
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
 uint ISaiFrameTransport.NextSendSeq()
 {
     return(_seqNoManager.GetAndUpdateSendSeq());
 }