Beispiel #1
0
        public void DropUnconfirmed_Works_Event()
        {
            var queue = new TestQueue();

            queue.Enqueue(UserId, FFXIVRole.DPS, EventId);
            queue.Enqueue(0, FFXIVRole.Tank, EventId);
            queue.Enqueue(1, FFXIVRole.Healer, EventId);
            queue.Enqueue(2, FFXIVRole.Healer, EventId);
            queue.Enqueue(3, FFXIVRole.Tank, EventId);
            queue.DropUnconfirmed(EventId);
            Assert.IsEmpty(queue.GetAllSlots());
        }
Beispiel #2
0
        public void DropUnconfirmed_DoesNothing_NoEvent()
        {
            var queue = new TestQueue();

            queue.Enqueue(UserId, FFXIVRole.DPS, null);
            queue.Enqueue(0, FFXIVRole.Tank, "");
            queue.Enqueue(1, FFXIVRole.Healer, null);
            queue.Enqueue(2, FFXIVRole.Healer, null);
            queue.Enqueue(3, FFXIVRole.Tank, null);
            queue.DropUnconfirmed(null);
            Assert.IsNotEmpty(queue.GetAllSlots());
        }
Beispiel #3
0
        public void ExpireEvent_DoesNothing_NoEvent()
        {
            var rand  = new Random(1234);
            var queue = new TestQueue();

            for (ulong i = 0; i < 1000; i++)
            {
                var nextRole = rand.Next(0, 3) switch
                {
                    0 => FFXIVRole.DPS,
                    1 => FFXIVRole.Healer,
                    2 => FFXIVRole.Tank,
                    _ => throw new NotImplementedException(),
                };
                queue.Enqueue(i, nextRole, null);
            }

            queue.ExpireEvent(null);

            var slots = queue.GetAllSlots();

            foreach (var slot in slots)
            {
                Assert.That(string.IsNullOrEmpty(slot.EventId));
            }
        }
Beispiel #4
0
        public async Task RefreshEvent_DoesNothing_NoEvent()
        {
            var rand  = new Random(1234);
            var queue = new TestQueue();

            for (ulong i = 0; i < 1000; i++)
            {
                var nextRole = rand.Next(0, 3) switch
                {
                    0 => FFXIVRole.DPS,
                    1 => FFXIVRole.Healer,
                    2 => FFXIVRole.Tank,
                    _ => throw new NotImplementedException(),
                };
                queue.Enqueue(i, nextRole, null);
                await Task.Delay(rand.Next(1, 20));
            }
            queue.RefreshEvent(EventId);
            var timestamps = queue.GetAllSlots()
                             .ToList();
            var firstTimestamp = timestamps.First().QueueTime;

            foreach (var slot in timestamps.Skip(1))
            {
                Assert.AreNotEqual(firstTimestamp, slot.QueueTime);
            }
        }
Beispiel #5
0
 private void PopulateTestQueue()
 {
     for (int i = 0; i < SampleSize; i++)
     {
         TestQueue.Enqueue(i + 2);
     }
 }
Beispiel #6
0
        public void Dequeue_IsThreadSafe()
        {
            var rand   = new Random(1234);
            var queue  = new TestQueue();
            var counts = new Dictionary <FFXIVRole, int>
            {
                { FFXIVRole.DPS, 0 },
                { FFXIVRole.Healer, 0 },
                { FFXIVRole.Tank, 0 },
            };

            for (ulong i = 0; i < 1000; i++)
            {
                var curI     = i;
                var nextRole = rand.Next(0, 3) switch
                {
                    0 => FFXIVRole.DPS,
                    1 => FFXIVRole.Healer,
                    2 => FFXIVRole.Tank,
                    _ => throw new NotImplementedException(),
                };
                counts[nextRole]++;
                queue.Enqueue(curI, nextRole, "");
            }

            var threads = new List <Thread>();
            var outList = new SynchronizedCollection <ulong>();
            var roles   = new[] { FFXIVRole.DPS, FFXIVRole.Healer, FFXIVRole.Tank };

            foreach (var role in roles)
            {
                for (var i = 0; i < counts[role]; i++)
                {
                    var thread = new Thread(() =>
                    {
                        Thread.Sleep(rand.Next(0, 1001));
                        var id = queue.Dequeue(role, null);
                        if (id != null)
                        {
                            outList.Add(id.Value);
                        }
                    });
                    thread.Start();
                    threads.Add(thread);
                }
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            var slots = queue.GetAllSlots().ToList();

            Assert.That(!slots.Any());
            Assert.That(outList.Count == 1000);
        }
Beispiel #7
0
        public void TestTryPeek()
        {
            Assert.False(TestQueue.TryPeek(out int?badResult));
            Assert.Null(badResult);

            TestQueue.Enqueue(100);
            Assert.True(TestQueue.TryPeek(out int?goodResult));
            Assert.Equal(100, goodResult);
            Assert.Single(TestQueue);
        }
Beispiel #8
0
        public void TestTryDequeue()
        {
            Assert.False(TestQueue.TryDequeue(out int?badResult));
            Assert.Null(badResult);

            TestQueue.Enqueue(100);
            Assert.True(TestQueue.TryDequeue(out int?goodResult));
            Assert.Equal(100, goodResult);
            Assert.Empty(TestQueue);
        }
Beispiel #9
0
        private static void Main()
        {
            var TestQueue = new TestQueue <int>(1);

            // Добавляем элементы в очередь
            TestQueue.Enqueue(1);
            TestQueue.Enqueue(2);
            TestQueue.Enqueue(3);
            TestQueue.Enqueue(4);
            TestQueue.Enqueue(5);
            TestQueue.Enqueue(6);


            // Получаем очеред в виде массива и выводим
            foreach (int i in TestQueue.ToArray())
            {
                Console.WriteLine(i);
            }

            Console.WriteLine();

            // Удаляем все элементы из очереди и выводим
            while (TestQueue.Count > 0)
            {
                Console.WriteLine(TestQueue.Dequeue());
            }

            Console.ReadKey();
        }
Beispiel #10
0
        public void TestArrayResize()
        {
            const int initCapacity = DataStructures.Queue <int?> .InitCapacity;

            Assert.Equal(initCapacity, TestQueue.Capacity);

            TestQueue.Enqueue(1);
            TestQueue.Enqueue(2);
            TestQueue.Enqueue(3);
            TestQueue.Enqueue(4);
            Assert.Equal(initCapacity, TestQueue.Capacity);

            TestQueue.Enqueue(5);
            Assert.Equal(initCapacity * 2, TestQueue.Capacity);
        }
Beispiel #11
0
        public void TestEnqueue()
        {
            PopulateTestQueue();
            Assert.Equal(SampleSize, TestQueue.Count);

            int currentValue = 2;

            do
            {
                Assert.Equal(currentValue, TestQueue.Dequeue());
                currentValue++;
            } while (TestQueue.Count > 0);

            TestQueue.Enqueue(null);
            Assert.Null(TestQueue.Dequeue());
        }
Beispiel #12
0
        public void Enqueue_IsThreadSafe()
        {
            var rand    = new Random(1234);
            var queue   = new TestQueue();
            var threads = new List <Thread>();

            for (ulong i = 0; i < 1000; i++)
            {
                var curI     = i;
                var nextRole = rand.Next(0, 3) switch
                {
                    0 => FFXIVRole.DPS,
                    1 => FFXIVRole.Healer,
                    2 => FFXIVRole.Tank,
                    _ => throw new NotImplementedException(),
                };
                var thread = new Thread(() =>
                {
                    Thread.Sleep(rand.Next(0, 1001));
                    queue.Enqueue(curI, nextRole, "");
                });
                thread.Start();
                threads.Add(thread);
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            var slots = queue.GetAllSlots().ToList();

            slots.Sort((a, b) => (int)a.Id - (int)b.Id);
            for (ulong i = 0; i < 1000; i++)
            {
                Assert.That(slots[(int)i].Id == i);
            }
        }
Beispiel #13
0
        public void ExpireEvent_Works_Event()
        {
            var rand  = new Random(1234);
            var queue = new TestQueue();

            for (ulong i = 0; i < 1000; i++)
            {
                var nextRole = rand.Next(0, 3) switch
                {
                    0 => FFXIVRole.DPS,
                    1 => FFXIVRole.Healer,
                    2 => FFXIVRole.Tank,
                    _ => throw new NotImplementedException(),
                };
                queue.Enqueue(i, nextRole, EventId);
            }

            queue.ExpireEvent(EventId);

            var slots = queue.GetAllSlots();

            Assert.That(!slots.Any());
        }
Beispiel #14
0
 void LogMessage(string message)
 {
     Debug.WriteLine($"[tid:{Thread.CurrentThread.ManagedThreadId}] {message}");
     TestQueue.Enqueue($"[tid:{Thread.CurrentThread.ManagedThreadId}] {message}");
 }