public void Dequeue_ShouldFetchAJob_FromTheSpecifiedQueue() { // Arrange UseStorage(storage => { var queue = CreateJobQueue(storage); var jobQueue = new JobQueue { Id = storage.Repository.GetId(typeof(JobQueue), "default", "1"), JobId = "1", Queue = "default" }; using (var session = storage.Repository.OpenSession()) { session.Store(jobQueue); session.SaveChanges(); } // Act RavenFetchedJob payload = (RavenFetchedJob)queue.Dequeue(DefaultQueues, CreateTimingOutCancellationToken()); // Assert var id = jobQueue.Id; Assert.Equal(id, payload.Id); Assert.Equal("1", payload.JobId); Assert.Equal("default", payload.Queue); }); }
public void Ctor_CorrectlySets_AllInstanceProperties() { UseStorage(storage => { var fetchedJob = new RavenFetchedJob(storage, new JobQueue { Id = "1", JobId = JobId, Queue = Queue }); Assert.Equal("1", fetchedJob.Id); Assert.Equal(JobId, fetchedJob.JobId); Assert.Equal(Queue, fetchedJob.Queue); }); }
public void RemoveFromQueue_ReallyDeletesTheJobFromTheQueue() { UseStorage(storage => { // Arrange var id = CreateJobQueueRecord(storage, "1", "default"); var processingJob = new RavenFetchedJob(storage, new JobQueue { Id = id, JobId = "1", Queue = "default" }); // Act processingJob.RemoveFromQueue(); // Assert using (var session = storage.Repository.OpenSession()) { var count = session.Query <JobQueue>().Count(); Assert.Equal(0, count); } }); }
public void Dispose_SetsFetchedAtValueToNull_IfThereWereNoCallsToComplete() { UseStorage(storage => { // Arrange var id = CreateJobQueueRecord(storage, "1", "default"); var processingJob = new RavenFetchedJob(storage, new JobQueue { Id = id, JobId = "1", Queue = "default" }); // Act processingJob.Dispose(); // Assert using (var session = storage.Repository.OpenSession()) { var record = session.Query <JobQueue>().Single(); Assert.Null(record.FetchedAt); } }); }
public void RemoveFromQueue_DoesNotDelete_UnrelatedJobs() { UseStorage(storage => { // Arrange CreateJobQueueRecord(storage, "1", "default"); CreateJobQueueRecord(storage, "1", "critical"); CreateJobQueueRecord(storage, "2", "default"); var fetchedJob = new RavenFetchedJob(storage, new JobQueue { Id = "999", JobId = "1", Queue = "default" }); // Act fetchedJob.RemoveFromQueue(); // Assert using (var session = storage.Repository.OpenSession()) { var count = session.Query <JobQueue>().Count(); Assert.Equal(3, count); } }); }