Ejemplo n.º 1
0
        public virtual async Task CanRunQueueJobWithLockFailAsync()
        {
            const int workItemCount    = 10;
            const int allowedLockCount = 5;

            using (var queue = GetSampleWorkItemQueue(retries: 3, retryDelay: TimeSpan.Zero)) {
                await queue.DeleteQueueAsync();

                var enqueueTask = Run.InParallelAsync(workItemCount, index => queue.EnqueueAsync(new SampleQueueWorkItem {
                    Created = SystemClock.UtcNow,
                    Path    = "somepath" + index
                }));

                var lockProvider = new ThrottlingLockProvider(new InMemoryCacheClient(new InMemoryCacheClientOptions()), allowedLockCount, TimeSpan.FromDays(1), Log);
                var job          = new SampleQueueJobWithLocking(queue, null, lockProvider, Log);
                await SystemClock.SleepAsync(10);

                await Task.WhenAll(job.RunUntilEmptyAsync(), enqueueTask);

                var stats = await queue.GetQueueStatsAsync();

                Assert.Equal(0, stats.Queued);
                Assert.Equal(workItemCount, stats.Enqueued);
                Assert.Equal(allowedLockCount, stats.Completed);
                Assert.Equal(allowedLockCount * 4, stats.Abandoned);
                Assert.Equal(allowedLockCount, stats.Deadletter);
            }
        }
Ejemplo n.º 2
0
        public virtual async Task CanRunQueueJobWithLockFail()
        {
            const int workItemCount    = 10;
            const int allowedLockCount = 5;
            var       queue            = GetSampleWorkItemQueue(retries: 3, retryDelay: TimeSpan.Zero);
            await queue.DeleteQueueAsync();

            Log.MinimumLevel = LogLevel.Trace;

            var enqueueTask = Run.InParallel(workItemCount, async index => {
                await queue.EnqueueAsync(new SampleQueueWorkItem {
                    Created = DateTime.Now,
                    Path    = "somepath" + index
                });
            });

            var lockProvider = new ThrottlingLockProvider(new InMemoryCacheClient(), allowedLockCount, TimeSpan.FromDays(1), Log);
            var job          = new SampleQueueJobWithLocking(queue, null, lockProvider, Log);
            await Task.Delay(10);

            await Task.WhenAll(job.RunUntilEmptyAsync(), enqueueTask);

            var stats = await queue.GetQueueStatsAsync();

            Assert.Equal(0, stats.Queued);
            Assert.Equal(workItemCount, stats.Enqueued);
            Assert.Equal(allowedLockCount, stats.Completed);
            Assert.Equal(allowedLockCount * 4, stats.Abandoned);
            Assert.Equal(allowedLockCount, stats.Deadletter);
        }