public void DataFiles_AreCreated()
        {
            // Arrange
            var config = new UnitTestQueueConfiguration
            {
                DataPageSize = 64
            };

            using var queue = new UnitTestPersistentQueue(config);


            // Act & Assert
            queue.Enqueue(new byte[32]);
            Directory.GetFiles(config.GetDataPath()).Length.ShouldBe(1);
            queue.Enqueue(new byte[32]);
            Directory.GetFiles(config.GetDataPath()).Length.ShouldBe(1);
            queue.Enqueue(new byte[32]);
            Directory.GetFiles(config.GetDataPath()).Length.ShouldBe(2);
            queue.Enqueue(new byte[32]);
            Directory.GetFiles(config.GetDataPath()).Length.ShouldBe(2);
        }
        public void IndexFiles_AreCreated()
        {
            // Arrange
            var config = new UnitTestQueueConfiguration
            {
                IndexItemsPerPage = 2
            };

            using var queue = new UnitTestPersistentQueue(config);


            // Act & Assert
            queue.Enqueue(1);
            Directory.GetFiles(config.GetIndexPath()).Length.ShouldBe(1);
            queue.Enqueue(1);
            Directory.GetFiles(config.GetIndexPath()).Length.ShouldBe(1);
            queue.Enqueue(1);
            Directory.GetFiles(config.GetIndexPath()).Length.ShouldBe(2);
            queue.Enqueue(1);
            Directory.GetFiles(config.GetIndexPath()).Length.ShouldBe(2);
        }
Exemple #3
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);
        }
        public async Task DataFiles_OneIsDeletedAfterCommit()
        {
            // Arrange
            var config = new UnitTestQueueConfiguration
            {
                DataPageSize = 64
            };

            using var queue = new UnitTestPersistentQueue(config);


            // Act & Assert
            for (var i = 0; i < 20; i++)
            {
                queue.Enqueue(new byte[32]);
            }

            Directory.GetFiles(config.GetDataPath()).Length.ShouldBe(10);

            await Dequeue(queue, 3);

            Directory.GetFiles(config.GetDataPath()).Length.ShouldBe(9);
        }
        public async Task DataFiles_OneRemainsAfterAllItemsAreCommitted()
        {
            // Arrange
            var config = new UnitTestQueueConfiguration
            {
                DataPageSize = 64
            };

            using var queue = new UnitTestPersistentQueue(config);


            // Act & Assert
            for (var i = 0; i < 20; i++)
            {
                queue.Enqueue(new byte[32]);
            }

            while (queue.HasItems)
            {
                await Dequeue(queue, 2);
            }

            Directory.GetFiles(config.GetDataPath()).Length.ShouldBe(1);
        }