public void Dequeue_ShouldDeleteAJob()
        {
            // Arrange
            _storage.UseStatelessSession(session =>
            {
                session.DeleteAll <_JobQueue>();
                session.DeleteAll <_Job>();
                var newjob = FluentNHibernateWriteOnlyTransactionTests.InsertNewJob(session);
                session.Insert(new _JobQueue {
                    Job = newjob, Queue = "default"
                });
                //does nothing
                var queue = CreateJobQueue(_storage);

                // Act
                var payload = queue.Dequeue(
                    DefaultQueues,
                    CreateTimingOutCancellationToken());

                payload.RemoveFromQueue();

                // Assert
                Assert.NotNull(payload);

                var jobInQueue = session.Query <_JobQueue>().SingleOrDefault();
                Assert.Null(jobInQueue);
            });
        }
        public void Dequeue_ShouldSetFetchedAt_OnlyForTheFetchedJob()
        {
            _storage.UseStatelessSession(session =>
            {
                // Arrange
                session.DeleteAll <_JobQueue>();
                session.DeleteAll <_Job>();
                for (var i = 0; i < 2; i++)
                {
                    var newJob = FluentNHibernateWriteOnlyTransactionTests.InsertNewJob(session);
                    session.Insert(new _JobQueue
                    {
                        Job   = newJob,
                        Queue = "default"
                    });
                }

                //does nothing

                var queue = CreateJobQueue(_storage);

                // Act
                var payload = queue.Dequeue(
                    DefaultQueues,
                    CreateTimingOutCancellationToken());

                // Assert
                var otherJobFetchedAt = session.Query <_JobQueue>()
                                        .Where(i => i.Job.Id != long.Parse(payload.JobId))
                                        .Select(i => i.FetchedAt)
                                        .Single();

                Assert.Null(otherJobFetchedAt);
            });
        }
        public void GetEnqueuedJobIds_ReturnsCorrectResult()
        {
            long[] result = null;
            var    jobs   = new List <_Job>();

            _storage.UseStatelessSession(session =>
            {
                for (var i = 1; i <= 10; i++)
                {
                    var newJob = FluentNHibernateWriteOnlyTransactionTests.InsertNewJob(session);
                    jobs.Add(newJob);
                    session.Insert(new _JobQueue {
                        Job = newJob, Queue = _queue
                    });
                }

                //does nothing
                result = _sut.GetEnqueuedJobIds(_queue, 3, 2).ToArray();

                session.DeleteAll <_JobQueue>();
            });

            Assert.Equal(2, result.Length);
            Assert.Equal(jobs[3].Id, result[0]);
            Assert.Equal(jobs[4].Id, result[1]);
        }
        public void Dequeue_ShouldFetchAJob_FromTheSpecifiedQueue()
        {
            // Arrange
            _storage.UseSession(session =>
            {
                var newJob      = FluentNHibernateWriteOnlyTransactionTests.InsertNewJob(session);
                var newJobQueue = new _JobQueue {
                    Job = newJob, Queue = "default"
                };
                session.Insert(newJobQueue);
                session.Flush();
                session.Clear();

                var queue = CreateJobQueue(_storage);

                // Act
                var payload = (FluentNHibernateFetchedJob)queue.Dequeue(
                    DefaultQueues,
                    CreateTimingOutCancellationToken());

                // Assert
                Assert.Equal(newJob.Id.ToString(), payload.JobId);
                Assert.Equal("default", payload.Queue);
            });
        }
        public void Dequeue_ShouldFetchJobs_FromMultipleQueues()
        {
            _storage.UseSession(session =>
            {
                var queueNames = new[] { "critical", "default" };
                foreach (var queueName in queueNames)
                {
                    var newJob = FluentNHibernateWriteOnlyTransactionTests.InsertNewJob(session);
                    session.Insert(new _JobQueue
                    {
                        Job   = newJob,
                        Queue = queueName
                    });
                }
                session.Flush();


                var queue = CreateJobQueue(_storage);


                var critical = (FluentNHibernateFetchedJob)queue.Dequeue(
                    queueNames,
                    CreateTimingOutCancellationToken());

                Assert.NotNull(critical.JobId);
                Assert.Equal("critical", critical.Queue);

                var @default = (FluentNHibernateFetchedJob)queue.Dequeue(
                    queueNames,
                    CreateTimingOutCancellationToken());

                Assert.NotNull(@default.JobId);
                Assert.Equal("default", @default.Queue);
            });
        }
示例#6
0
        public void GetEnqueuedAndFetchedCount_ReturnsEqueuedCount_WhenExists()
        {
            EnqueuedAndFetchedCountDto result = null;

            _storage.UseSession(session =>
            {
                var newJob = FluentNHibernateWriteOnlyTransactionTests.InsertNewJob(session);
                session.Insert(new _JobQueue {
                    Job = newJob, Queue = _queue
                });
                session.Flush();
                result = _sut.GetEnqueuedAndFetchedCount(_queue);

                session.DeleteAll <_JobQueue>();
            });

            Assert.Equal(1, result.EnqueuedCount);
        }
        public void Enqueue_AddsAJobToTheQueue()
        {
            _storage.UseStatelessSession(session =>
            {
                session.DeleteAll <_JobQueue>();
                //does nothing

                var newJob = FluentNHibernateWriteOnlyTransactionTests.InsertNewJob(session);

                var queue = CreateJobQueue(_storage);

                queue.Enqueue(session, "default", newJob.Id.ToString());

                var record = session.Query <_JobQueue>().Single();
                Assert.Equal(newJob.Id, record.Job.Id);
                Assert.Equal("default", record.Queue);
                Assert.Null(record.FetchedAt);
            });
        }
        public void Dequeue_ShouldFetchJobs_OnlyFromSpecifiedQueues()
        {
            _storage.UseStatelessSession(session =>
            {
                session.DeleteAll <_JobQueue>();
                session.DeleteAll <_Job>();
                var newJob = FluentNHibernateWriteOnlyTransactionTests.InsertNewJob(session);
                session.Insert(new _JobQueue
                {
                    Job   = newJob,
                    Queue = "critical"
                });
                //does nothing

                var queue = CreateJobQueue(_storage);

                Assert.Throws <OperationCanceledException>(
                    () => queue.Dequeue(
                        DefaultQueues,
                        CreateTimingOutCancellationToken()));
            });
        }
        public void Dequeue_ShouldFetchATimedOutJobs_FromTheSpecifiedQueue()
        {
            // Arrange
            _storage.UseStatelessSession(session =>
            {
                var newJob = FluentNHibernateWriteOnlyTransactionTests.InsertNewJob(session);
                session.Insert(new _JobQueue
                {
                    Job       = newJob,
                    FetchedAt = _storage.UtcNow.AddDays(-1),
                    Queue     = "default"
                });
                //does nothing
                var queue = CreateJobQueue(_storage);

                // Act
                var payload = queue.Dequeue(
                    DefaultQueues,
                    CreateTimingOutCancellationToken());

                // Assert
                Assert.NotEmpty(payload.JobId);
            });
        }