Esempio n. 1
0
        private static async Task Dequeue(UnitTestPersistentQueue queue, int elements)
        {
            var result = await queue.DequeueAsync(1, elements);

            result.Items.Count.ShouldBe(elements);
            result.Commit();
        }
Esempio n. 2
0
        public async Task WithCommit_NewElementsAreReturned()
        {
            // Arrange
            using var queue = new UnitTestPersistentQueue();
            queue.EnqueueMany(10);

            // Act
            var results1 = await queue.DequeueAsync(1, 2);

            results1.Commit();

            var results2 = await queue.DequeueAsync(1, 2);

            // Assert
            results1.Items.Count.ShouldBe(2);
            results2.Items.Count.ShouldBe(2);

            CollectionAssert.AreNotEqual(results1.Items[0].ToArray(), results2.Items[0].ToArray());
        }
Esempio n. 3
0
        public async Task LessThanMaxItemsInQueue_ReturnsAvailable()
        {
            // Arrange
            using var queue = new UnitTestPersistentQueue();
            queue.EnqueueMany(2);

            // Act
            var result = await queue.DequeueAsync(1, 10);

            // Assert
            result.Items.Count.ShouldBe(2);
        }
Esempio n. 4
0
        public void ItemsInQueue_ReturnsSynchronous()
        {
            // Arrange
            using var queue = new UnitTestPersistentQueue();
            queue.EnqueueMany(2);

            // Act
            var resultTask = queue.DequeueAsync(1, 2);

            // Assert
            resultTask.IsCompleted.ShouldBeTrue();
        }
Esempio n. 5
0
        public void Cancel_ShouldThrowException()
        {
            // Arrange
            using var queue = new UnitTestPersistentQueue();

            var cts = new CancellationTokenSource();

            // Act & Assert
            var resultTask = queue.DequeueAsync(10, 12, cts.Token);

            cts.Cancel();
            Should.ThrowAsync <OperationCanceledException>(async() => await resultTask);
        }
Esempio n. 6
0
        public async Task EmptyQueue_WaitForNextItem()
        {
            // Arrange
            using var queue = new UnitTestPersistentQueue();

            // Act & Assert
            var resultTask = queue.DequeueAsync(1, 2);

            resultTask.IsCompleted.ShouldBeFalse();

            queue.Enqueue(1);
            var result = await resultTask;

            result.Items.Count.ShouldBe(1);
        }
Esempio n. 7
0
        public void WaitAndCancel()
        {
            // Arrange
            using var queue = new UnitTestPersistentQueue();

            var cts = new CancellationTokenSource();

            // Act & Assert
            var resultTask = queue.DequeueAsync(10, 12, cts.Token);

            resultTask.IsCompleted.ShouldBeFalse();
            resultTask.IsCanceled.ShouldBeFalse();

            cts.Cancel();
            resultTask.IsCanceled.ShouldBeTrue();
        }
Esempio n. 8
0
        public async Task EnqueueAndDequeue10_HasItemsFalse()
        {
            // Arrange
            using var queue = new UnitTestPersistentQueue();
            queue.EnqueueMany(10);

            // Act
            for (var i = 0; i < 5; i++)
            {
                var result = await queue.DequeueAsync(1, 2);

                result.Commit();
            }

            // Assert
            queue.HasItems.ShouldBeFalse();
        }
Esempio n. 9
0
        public void WaitForMinElements()
        {
            // Arrange
            using var queue = new UnitTestPersistentQueue();

            // Act & Assert
            var resultTask = queue.DequeueAsync(10, 12);

            for (var i = 0; i < 4; i++)
            {
                queue.EnqueueMany(2);
                resultTask.IsCompleted.ShouldBeFalse();
            }

            queue.EnqueueMany(2);
            resultTask.IsCompleted.ShouldBeTrue();
        }
Esempio n. 10
0
        public async Task IndexFiles_ManyAreDeletedAfterCommit()
        {
            // Arrange
            var config = new UnitTestQueueConfiguration
            {
                IndexItemsPerPage = 2
            };

            using var queue = new UnitTestPersistentQueue(config);


            // Act & Assert
            queue.EnqueueMany(20);
            Directory.GetFiles(config.GetIndexPath()).Length.ShouldBe(10);

            var result = await queue.DequeueAsync(1, 10);

            result.Commit();
            Directory.GetFiles(config.GetIndexPath()).Length.ShouldBe(6);
        }
Esempio n. 11
0
        public async Task EnqueueAndDequeue10()
        {
            // Arrange
            using var queue = new UnitTestPersistentQueue();
            queue.EnqueueMany(10);

            for (var i = 0; i < 5; i++)
            {
                var result = await queue.DequeueAsync(1, 2);

                result.Commit();
            }

            // Act
            var statistics = queue.GetStatistics();

            // Assert
            statistics.ShouldDeepEqual(new QueueStatistics()
            {
                QueueLength           = 0,
                QueueDataSizeEstimate = 0,
                TotalEnqueuedItems    = 10
            });
        }