public void Dequeue_ReturnsFetchedJob_FromOtherQueues_IfFirstAreEmpty() { RabbitMqUtils.EnqueueJobId("queue-2", "job-id"); using (var queue = CleanRabbitMqQueueAttribute.GetMessageQueue("queue-1", "queue-2")) { var fetchedJob = queue.Dequeue(new[] { "queue-1", "queue-2" }, _token); Assert.Equal("job-id", fetchedJob.JobId); } }
public void Dequeue_ReturnsFetchedJob_WithJobId() { RabbitMqUtils.EnqueueJobId("my-queue", "job-id"); using (var queue = CleanRabbitMqQueueAttribute.GetMessageQueue("my-queue")) { var fetchedJob = queue.Dequeue(new[] { "my-queue" }, _token); fetchedJob.RemoveFromQueue(); Assert.Equal("job-id", fetchedJob.JobId); } }
public void GetEnqueuedAndFetchedCount_ReturnsCorrectCounters() { RabbitMqUtils.EnqueueJobId("my-queue", "1"); RabbitMqUtils.EnqueueJobId("my-queue", "2"); RabbitMqUtils.EnqueueJobId("my-queue", "3"); var api = CreateMonitoringApi(); var result = api.GetEnqueuedAndFetchedCount("my-queue"); Assert.Equal(3, result.EnqueuedCount); Assert.Null(result.FetchedCount); }
public void GetEnqueuedJobIds_ReturnsCorrectResult() { for (var i = 1; i <= 10; i++) { RabbitMqUtils.EnqueueJobId("my-queue", i.ToString()); } var api = CreateMonitoringApi(); var result = api.GetEnqueuedJobIds("my-queue", 3, 2).ToArray(); Assert.Equal(2, result.Length); Assert.Equal(4, result[0]); Assert.Equal(5, result[1]); }
public void DisposeWithoutRemoval_OnFetchedJob_ReturnsTheJobToTheQueue() { // Arrange RabbitMqUtils.EnqueueJobId("my-queue", "job-id"); using (var queue = CleanRabbitMqQueueAttribute.GetMessageQueue("my-queue")) { // Act var fetchedJob = queue.Dequeue(new[] { "my-queue" }, _token); fetchedJob.Dispose(); // Assert var jobId = RabbitMqUtils.DequeueJobId("my-queue", TimeSpan.FromSeconds(5)); Assert.Equal("job-id", jobId); } }
public void DisposeWithoutRemoval_OnFetchedJob_CanBeDequeuedAgain() { // Arrange RabbitMqUtils.EnqueueJobId("my-queue", "job-id"); using (var queue = CleanRabbitMqQueueAttribute.GetMessageQueue("my-queue")) { // Act var fetchedJob = queue.Dequeue(new[] { "my-queue" }, _token); fetchedJob.Dispose(); // Assert var newFetchedJob = queue.Dequeue(new[] { "my-queue" }, _token); Assert.Equal("job-id", newFetchedJob.JobId); } }
public void RemoveFromQueue_OnFetchedJob_RemovesTheJobCompletely() { // Arrange RabbitMqUtils.EnqueueJobId("my-queue", "job-id"); using (var queue = CleanRabbitMqQueueAttribute.GetMessageQueue("my-queue")) { // Act using (var fetchedJob = queue.Dequeue(new[] { "my-queue" }, _token)) { fetchedJob.RemoveFromQueue(); } // Assert var exception = Assert.Throws <TimeoutException>( () => RabbitMqUtils.DequeueJobId("my-queue", TimeSpan.FromSeconds(1))); Assert.Equal(exception.Message, "my-queue"); } }
public void Dequeue_MakesJobInvisibleForOtherFetchers() { // Arrange RabbitMqUtils.EnqueueJobId("my-queue", "job-id9"); using (var queue = CleanRabbitMqQueueAttribute.GetMessageQueue("my-queue")) { // Act var fetchedJob = queue.Dequeue(new[] { "my-queue" }, _token); // Assert Assert.NotNull(fetchedJob); var exception = Assert.Throws <TimeoutException>( () => RabbitMqUtils.DequeueJobId("my-queue", TimeSpan.FromSeconds(1))); Assert.Equal(exception.Message, "my-queue"); } }