public async Task IndexFiles_CreateAndDelete()
        {
            // Arrange
            var config = new UnitTestQueueConfiguration
            {
                IndexItemsPerPage = 2
            };

            using var queue = new UnitTestPersistentQueue(config);


            // Act & Assert
            queue.EnqueueMany(2);
            await Dequeue(queue, 2);

            Directory.GetFiles(config.GetIndexPath()).Length.ShouldBe(1);
            PrintFiles(config.GetIndexPath());

            queue.EnqueueMany(2);
            await Dequeue(queue, 2);

            Directory.GetFiles(config.GetIndexPath()).Length.ShouldBe(1);
            PrintFiles(config.GetIndexPath());

            queue.EnqueueMany(2);
            await Dequeue(queue, 2);

            Directory.GetFiles(config.GetIndexPath()).Length.ShouldBe(1);
            PrintFiles(config.GetIndexPath());
        }
Beispiel #2
0
        public async Task ReloadWithData(int firstDequeue, int secondDequeue, int indexItemsPerPage = 30, int dataPageSize = 32 * 10)
        {
            var config = new UnitTestQueueConfiguration
            {
                IndexItemsPerPage = indexItemsPerPage,
                DataPageSize      = dataPageSize
            };

            try
            {
                using (var q1 = new Persistent.Queue.PersistentQueue(config))
                {
                    q1.EnqueueManySized(10, 32);
                    var result = await q1.DequeueAsync(1, firstDequeue);

                    result.Commit();
                }

                using (var q2 = new Persistent.Queue.PersistentQueue(config))
                {
                    q2.EnqueueManySized(10, 32);
                    var result = await q2.DequeueAsync(1, secondDequeue);

                    result.Commit();
                    q2.HasItems.ShouldBeFalse();
                }
            }
            finally
            {
                Directory.Delete(config.QueuePath, true);
            }
        }
        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);
        }
        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);
        }
        public async Task IndexFiles_OneRemainsAfterAllItemsAreCommitted()
        {
            // 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);

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

            Directory.GetFiles(config.GetIndexPath()).Length.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 IndexFiles_OneIsDeletedAfterCommit()
        {
            // 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);

            await Dequeue(queue, 3);

            Directory.GetFiles(config.GetIndexPath()).Length.ShouldBe(9);

            await Dequeue(queue, 4);

            Directory.GetFiles(config.GetIndexPath()).Length.ShouldBe(7);
        }
        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);
        }