示例#1
0
        public void DifferentInit()
        {
            var seq = new EsSequence {
                Index = TEST_INDEX, Url = TEST_URL, Initial = -2, Step = -3
            };

            Assert.AreEqual(-2, seq.Next());
            Assert.AreEqual(-5, seq.Next());
        }
示例#2
0
        public void BasicFunctionality()
        {
            var seq = new EsSequence {
                Index = TEST_INDEX, Url = TEST_URL
            };

            Assert.AreEqual(10, seq.Next());
            Assert.AreEqual(20, seq.Next());
        }
示例#3
0
        public void CanBeSet()
        {
            var seq = new EsSequence {
                Index = TEST_INDEX, Url = TEST_URL
            };

            Assert.AreEqual(10, seq.Next());
            Assert.AreEqual(20, seq.Next());
            seq.Set(10);
            Assert.AreEqual(20, seq.Next());
        }
示例#4
0
        public void CanGetCurrent()
        {
            var seq = new EsSequence {
                Index = TEST_INDEX, Url = TEST_URL
            };

            Assert.AreEqual(int.MinValue, seq.GetCurrent());
            Assert.AreEqual(10, seq.Next());
            Assert.AreEqual(20, seq.Next());
            Assert.AreEqual(20, seq.GetCurrent());
            Assert.AreEqual(30, seq.Next());
        }
示例#5
0
        public void DifferentSteps()
        {
            var seq = new EsSequence {
                Index = TEST_INDEX, Url = TEST_URL
            };
            var seq2 = new EsSequence {
                Index = TEST_INDEX, Url = TEST_URL, Step = 1
            };

            Assert.AreEqual(10, seq.Next());
            Assert.AreEqual(20, seq.Next());
            Assert.AreEqual(21, seq2.Next());
            Assert.AreEqual(31, seq.Next());
        }
示例#6
0
        public void DifferentKeys()
        {
            var seq = new EsSequence {
                Index = TEST_INDEX, Url = TEST_URL
            };
            var seq2 = new EsSequence {
                Index = TEST_INDEX, Url = TEST_URL, Key = "2"
            };

            Assert.AreEqual(10, seq.Next());
            Assert.AreEqual(20, seq.Next());
            Assert.AreEqual(10, seq2.Next());
            Assert.AreEqual(20, seq2.Next());
        }
示例#7
0
        public void OneThreadPerformance1000()
        {
            var sw  = Stopwatch.StartNew();
            var seq = new EsSequence {
                Index = TEST_INDEX, Url = TEST_URL, Step = 1, Initial = 0
            };

            for (var i = 0; i < 1000; i++)
            {
                var s = seq.Next();
                Assert.AreEqual(s, i);
            }
            sw.Stop();
            var ms = sw.ElapsedMilliseconds;

            Assert.LessOrEqual(ms, 2000);
        }
示例#8
0
        public void ConcurentThreadSafe()
        {
            ConcurrentDictionary <int, int> _result = new ConcurrentDictionary <int, int>();
            var tasks = new List <Task>();
            var seq   = new EsSequence {
                Index = TEST_INDEX, Url = TEST_URL, Step = 1, Initial = 0
            };

            for (var i = 0; i < 4 * 250; i++)
            {
                tasks.Add(Task.Run(() => {
                    var next = seq.Next();
                    _result.TryAdd(next, next);
                }));
            }
            Task.WaitAll(tasks.ToArray());
            Assert.AreEqual(1000, _result.Count);
        }