Ejemplo n.º 1
0
        public async Task TestPriority()
        {
            var rand = new Random();

            var priorities = Enumerable.Range(1, 200).OrderBy(q => rand.Next()).ToList();

            var queue = new SimpleQueue <SimpleDocument>(this.GetType().FullName);

            await queue.Clear();

            foreach (var priority in priorities)
            {
                await queue.Enqueue(
                    new SimpleDocument()
                {
                    Value = priority.ToString()
                },
                    new EnqueOptions()
                {
                    Priority = (byte)priority
                });
            }

            for (byte i = 200; i >= 1; i--)
            {
                Assert.AreEqual(i.ToString(), (await queue.Dequeue()).Payload.Value);
            }
        }
Ejemplo n.º 2
0
        public async Task TestEnqueueDeque()
        {
            var queue = new SimpleQueue <SimpleDocument>(this.GetType().FullName);

            await queue.Clear();

            var simpleStrings = new List <string>();

            for (int i = 0; i < 100; i++)
            {
                simpleStrings.Add(Guid.NewGuid().ToString().Replace("-", ""));
            }

            var documents = simpleStrings.Select(q => new SimpleDocument()
            {
                Value = q
            });


            await Task.WhenAll(documents.Select(simpleDocument => queue.Enqueue(simpleDocument, new EnqueOptions())));

            for (int i = 0; i < 100; i++)
            {
                Assert.IsNotNull(await queue.Dequeue(new DequeueOptions()));
            }
            var document = await queue.Dequeue(new DequeueOptions());

            Assert.IsNull(document);
        }
Ejemplo n.º 3
0
        public async Task TestConfirmed()
        {
            var queue = new SimpleQueue <SimpleDocument>(GetType().FullName);
            await queue.Clear();

            await queue.Enqueue(new SimpleDocument()
            {
                Value = "test"
            });

            var value = await queue.Dequeue(new DequeueOptions()
            {
                ConfirmTime = TimeSpan.FromMilliseconds(500)
            });

            Assert.AreEqual("test", value.Payload.Value);

            await queue.Confirm(value);


            value = await queue.Dequeue();

            Assert.IsNull(value);

            await Task.Delay(1000);

            value = await queue.Dequeue();

            Assert.IsNull(value);
        }
Ejemplo n.º 4
0
        public async Task Test()
        {
            var queue = new SimpleQueue <SimpleDocument>(this.GetType().FullName);
            await queue.Clear();

            var producers = new List <Task>();

            for (int i = 0; i < 4; i++)
            {
                producers.Add(Task.Run(() => Produce(10)));
            }


            var consumers = new List <Task>();

            for (int i = 0; i < 8; i++)
            {
                consumers.Add(Task.Run(Consume));
            }


            await Task.WhenAll(producers.Concat(consumers));


            Assert.AreEqual(40, _totalConsumed);
        }
Ejemplo n.º 5
0
        public void TestClearBehavior()
        {
            List <char> chars = new List <char> {
                'a', 'b', 'c'
            };

            SimpleQueue <char> charQueue = new SimpleQueue <char>(chars);

            charQueue.Clear();

            Assert.AreEqual(0, charQueue.Count);
            Assert.AreEqual(true, charQueue.IsEmpty());
        }
Ejemplo n.º 6
0
        public async Task TestNoPriority()
        {
            var queue = new SimpleQueue <SimpleDocument>(this.GetType().FullName);

            await queue.Clear();

            for (int i = 0; i < 100; i++)
            {
                await queue.Enqueue(
                    new SimpleDocument()
                {
                    Value = i.ToString()
                });
            }


            for (int i = 0; i < 100; i++)
            {
                Assert.AreEqual(i.ToString(), (await queue.Dequeue()).Payload.Value);
            }
        }
Ejemplo n.º 7
0
        public void TC_SimpleQueue()
        {
            var queue = new SimpleQueue <double>();

            var input = GetDoubleTestList();

            foreach (var item in input)
            {
                queue.Add(item, item);
            }
            Assert.AreEqual(input.Count, queue.GetSize());

            List <double> poppedItems = new List <double>();

            while (queue.GetSize() > 0)
            {
                poppedItems.Add(queue.RemoveMin());
            }
            Assert.IsTrue(CollectionsEquality.Equals(input, poppedItems));

            queue.Clear();
            Assert.AreEqual(0, queue.GetSize());
            Assert.AreEqual("Simple Queue", queue.GetName());
        }
Ejemplo n.º 8
0
 private void Reset()
 {
     _set.Clear();
     _queue.Clear();
     Array.Clear(_buffer, 0, _buffer.Length);
 }