Ejemplo n.º 1
0
        public void PurgeAllItems_QueueContainsThreeItems_ResultIsArrayHasTheSameOrderAsTheQueue()
        {
            // Arrange
            var queue = new SystemInformationMessageQueue();

            var items = new[]
            {
                new SystemInformation {
                    MachineName = "1", Timestamp = DateTime.UtcNow
                },
                new SystemInformation {
                    MachineName = "2", Timestamp = DateTime.UtcNow
                },
                new SystemInformation {
                    MachineName = "3", Timestamp = DateTime.UtcNow
                }
            };

            foreach (var item in items)
            {
                queue.Enqueue(new SystemInformationQueueItem(item));
            }

            // Act
            var result = queue.PurgeAllItems();

            // Assert
            for (int i = 0; i < result.Length; i++)
            {
                Assert.AreEqual(items[i], result[i].Item);
            }
        }
Ejemplo n.º 2
0
        public void PurgeAllItems_QueueContainsThreeItems_ResultIsArrayWithThreeItems()
        {
            // Arrange
            var queue = new SystemInformationMessageQueue();

            var items = new[]
            {
                new SystemInformation {
                    MachineName = "1", Timestamp = DateTime.UtcNow
                },
                new SystemInformation {
                    MachineName = "2", Timestamp = DateTime.UtcNow
                },
                new SystemInformation {
                    MachineName = "3", Timestamp = DateTime.UtcNow
                }
            };

            foreach (var item in items)
            {
                queue.Enqueue(new SystemInformationQueueItem(item));
            }

            // Act
            var result = queue.PurgeAllItems();

            // Assert
            Assert.AreEqual(items.Length, result.Length);
        }
Ejemplo n.º 3
0
        public void PurgeAllItems_OnEmptyQueue_ResultIsEmptyArray()
        {
            // Arrange
            var queue = new SystemInformationMessageQueue();

            // Act
            var results = queue.PurgeAllItems();

            // Assert
            Assert.IsEmpty(results);
        }
        public void PurgeQueueWhileEnqueuing_AllItemsThatAreEnqueuedAreAlsoDequeued()
        {
            // Arrange
            var itemPoolSize = 10000000;
            var itemPool     = TestUtilities.GetSystemInformationObjects(itemPoolSize);
            var queue        = new SystemInformationMessageQueue();

            // Act
            var purgeCount        = 0;
            var dequeuedItemCount = 0;
            var enqueuedItemCount = 0;

            var thread1 = new Task(
                () =>
            {
                foreach (var item in itemPool)
                {
                    queue.Enqueue(new SystemInformationQueueItem(item));
                    enqueuedItemCount++;
                }
            });

            var thread2 = new Task(
                () =>
            {
                while (!queue.IsEmpty())
                {
                    purgeCount++;
                    dequeuedItemCount += queue.PurgeAllItems().Count();
                    int millisecondsToWaitBeforeNextItemIsQueued = TestUtilities.GetRandNumber(50, 100);
                    Thread.Sleep(millisecondsToWaitBeforeNextItemIsQueued);
                }
            });

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            thread1.Start();
            thread2.Start();
            Task.WaitAll(thread1, thread2);

            stopWatch.Stop();

            // Assert
            Console.WriteLine(
                "Enqueuing {0} items while another thread purged the queue took {1} milliseconds. The queue has been purged {2} time(s) during this time.",
                enqueuedItemCount,
                stopWatch.ElapsedMilliseconds,
                purgeCount);

            Assert.AreEqual(enqueuedItemCount, dequeuedItemCount);
            Assert.IsTrue(queue.IsEmpty());
        }
Ejemplo n.º 5
0
        public void PurgeAllItems_OnNonEmptyQueue_QueueIsEmptyAfterwards()
        {
            // Arrange
            var queue = new SystemInformationMessageQueue();

            queue.Enqueue(new SystemInformationQueueItem(new SystemInformation()));

            // Act
            queue.PurgeAllItems();

            // Assert
            Assert.IsTrue(queue.IsEmpty());
        }
        public void PurgeAllItems_QueueContainsThreeItems_ResultIsArrayWithThreeItems()
        {
            // Arrange
            var queue = new SystemInformationMessageQueue();

            var items = new[]
                {
                    new SystemInformation { MachineName = "1", Timestamp = DateTime.UtcNow },
                    new SystemInformation { MachineName = "2", Timestamp = DateTime.UtcNow },
                    new SystemInformation { MachineName = "3", Timestamp = DateTime.UtcNow }
                };

            foreach (var item in items)
            {
                queue.Enqueue(new SystemInformationQueueItem(item));
            }

            // Act
            var result = queue.PurgeAllItems();

            // Assert
            Assert.AreEqual(items.Length, result.Length);
        }
        public void PurgeAllItems_QueueContainsThreeItems_ResultIsArrayHasTheSameOrderAsTheQueue()
        {
            // Arrange
            var queue = new SystemInformationMessageQueue();

            var items = new[]
                {
                    new SystemInformation { MachineName = "1", Timestamp = DateTime.UtcNow },
                    new SystemInformation { MachineName = "2", Timestamp = DateTime.UtcNow },
                    new SystemInformation { MachineName = "3", Timestamp = DateTime.UtcNow }
                };

            foreach (var item in items)
            {
                queue.Enqueue(new SystemInformationQueueItem(item));
            }

            // Act
            var result = queue.PurgeAllItems();

            // Assert
            for (int i = 0; i < result.Length; i++)
            {
                Assert.AreEqual(items[i], result[i].Item);
            }
        }
        public void PurgeAllItems_OnNonEmptyQueue_QueueIsEmptyAfterwards()
        {
            // Arrange
            var queue = new SystemInformationMessageQueue();
            queue.Enqueue(new SystemInformationQueueItem(new SystemInformation()));

            // Act
            queue.PurgeAllItems();

            // Assert
            Assert.IsTrue(queue.IsEmpty());
        }
        public void PurgeAllItems_OnEmptyQueue_ResultIsEmptyArray()
        {
            // Arrange
            var queue = new SystemInformationMessageQueue();

            // Act
            var results = queue.PurgeAllItems();

            // Assert
            Assert.IsEmpty(results);
        }
        public void PurgeQueueWhileEnqueuing_AllItemsThatAreEnqueuedAreAlsoDequeued()
        {
            // Arrange
            var itemPoolSize = 10000000;
            var itemPool = TestUtilities.GetSystemInformationObjects(itemPoolSize);
            var queue = new SystemInformationMessageQueue();

            // Act
            var purgeCount = 0;
            var dequeuedItemCount = 0;
            var enqueuedItemCount = 0;

            var thread1 = new Task(
                () =>
                {
                    foreach (var item in itemPool)
                    {
                        queue.Enqueue(new SystemInformationQueueItem(item));
                        enqueuedItemCount++;
                    }
                });

            var thread2 = new Task(
                () =>
                {
                    while (!queue.IsEmpty())
                    {
                        purgeCount++;
                        dequeuedItemCount += queue.PurgeAllItems().Count();
                        int millisecondsToWaitBeforeNextItemIsQueued = TestUtilities.GetRandNumber(50, 100);
                        Thread.Sleep(millisecondsToWaitBeforeNextItemIsQueued);
                    }
                });

            var stopWatch = new Stopwatch();
            stopWatch.Start();

            thread1.Start();
            thread2.Start();
            Task.WaitAll(thread1, thread2);

            stopWatch.Stop();

            // Assert
            Console.WriteLine(
                "Enqueuing {0} items while another thread purged the queue took {1} milliseconds. The queue has been purged {2} time(s) during this time.",
                enqueuedItemCount,
                stopWatch.ElapsedMilliseconds,
                purgeCount);

            Assert.AreEqual(enqueuedItemCount, dequeuedItemCount);
            Assert.IsTrue(queue.IsEmpty());
        }