public async Task Dequeue_EmptyQueue_ReturnsNull() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); var queue = CreateQueue(connection); var item = await queue.DequeueAsync(); Assert.IsNull(item); } }
public async Task Dequeue_EmptyQueue_ReturnsEmpty() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); var queue = new DefaultBulkQueue <string>(connection, bulkSize: 2); var items = await queue.DequeueAsync(); Assert.IsEmpty(items); } }
public async Task Dequeue_PendingItem_ReturnsItem() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) VALUES(@StatusId, @Payload)", new StringItem(QueueItemStatus.Pending, "An item")); var queue = CreateQueue(connection); var item = await queue.DequeueAsync(); Assert.IsNotNull(item); } }
public async Task Update_ProcessingItemAndAnyException_UpdatesEventToFailed() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); var pending = await connection.InsertSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) OUTPUT Inserted.Id VALUES(@StatusId, @Payload)", new StringItem(QueueItemStatus.Processing, "An Item")); var queue = CreateQueue(connection); await queue.UpdateAsync(pending, new Exception("Any Exception")); var updatedEvent = await connection.SingleSqlAsync <StringItem>("SELECT * FROM Kiukie.Queue WHERE Id = @Id", new { pending.Id }); Assert.AreEqual((int)QueueItemStatus.Failed, updatedEvent.StatusId); } }
public async Task Dequeue_PendingAndAlreadyProcessedItem_ReturnsPendingItem(QueueItemStatus status) { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) OUTPUT Inserted.Id VALUES(@StatusId, @Payload)", new StringItem(status, "Processed")); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) OUTPUT Inserted.Id VALUES(@StatusId, @Payload)", new StringItem(QueueItemStatus.Pending, "Pending")); var queue = CreateQueue(connection); var item = await queue.DequeueAsync(); Assert.IsNotNull(item); Assert.AreEqual("Pending", item.Payload); } }
public async Task Dequeue_NotEmptyQueue_DequeueItemsInOrder() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("Item1")); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("Item2")); var queue = new DefaultBulkQueue <string>(connection, bulkSize: 2); var items = await queue.DequeueAsync(); Assert.AreEqual(2, items.Count()); } }
public async Task ProcessAsync_SinglePendingItemInQueueAndExceptionWhileProcessingIt_UpdatesItem() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) VALUES(@StatusId, @Payload)", new StringItem(QueueItemStatus.Pending, "An item")); var queue = new StatefulQueue <string>(connection); var handler = new ThrowExceptionPayloadHandler(new Exception("Any exception")); var queueProcessor = new StatefulQueueProcessor <string>(queue, handler); Assert.ThrowsAsync <Exception>(() => queueProcessor.ProcessAsync()); var item = await connection.SingleSqlAsync <StringItem>("SELECT TOP 1 * FROM Kiukie.Queue"); Assert.IsNotNull(item); Assert.AreEqual((int)QueueItemStatus.Failed, item.StatusId); } }
public async Task Dequeue_TwoPendingItemsInConcurrentCall_DequeueItemsInOrder() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) VALUES(@StatusId, @Payload)", new StringItem(QueueItemStatus.Pending, "Item1")); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) VALUES(@StatusId, @Payload)", new StringItem(QueueItemStatus.Pending, "Item2")); var queue1 = CreateQueue(connection); var queue2 = CreateQueue(connection); var t1 = queue1.DequeueAsync(); var t2 = queue2.DequeueAsync(); var items = await Task.WhenAll(t1, t2); Assert.IsTrue(items.First().Payload != items.Last().Payload); } }
public async Task ProcessAsync_SinglePendingItemInQueue_ProcessesAndEmptiesQueue() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) VALUES(@StatusId, @Payload)", new StringItem(QueueItemStatus.Pending, "An item")); var queue = new StatefulQueue <string>(connection); var handler = new FakePayloadHandler(); var queueProcessor = new StatefulQueueProcessor <string>(queue, handler); var processed = await queueProcessor.ProcessAsync(); Assert.IsTrue(processed); processed = await queueProcessor.ProcessAsync(); Assert.IsFalse(processed); } }
public async Task Dequeue_TwoConcurrentCalls_DequeueDifferentItems() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("An item")); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("Another item")); var queue1 = new DefaultQueue <string>(connection); var queue2 = new DefaultQueue <string>(connection); var t1 = queue1.DequeueAsync(); var t2 = queue2.DequeueAsync(); var items = await Task.WhenAll(t1, t2); Assert.IsTrue(items.First().Payload != items.Last().Payload); } }
public async Task Dequeue_TwoPendingItems_DequeueItemsInOrder() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) VALUES(@StatusId, @Payload)", new StringItem(QueueItemStatus.Pending, "Item1")); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) VALUES(@StatusId, @Payload)", new StringItem(QueueItemStatus.Pending, "Item2")); var queue = CreateQueue(connection); var item1 = await queue.DequeueAsync(); Assert.IsNotNull(item1); Assert.AreEqual("Item1", item1.Payload); var item2 = await queue.DequeueAsync(); Assert.IsNotNull(item2); Assert.AreEqual("Item2", item2.Payload); } }
public async Task ProcessAsync_NotEmptyQueue_ProcessesAndEmptiesQueue() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("Item1")); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("Item2")); var queue = new DefaultBulkQueue <string>(connection, bulkSize: 2); var handler = new FakePayloadHandler(); var queueProcessor = new DefaultBulkQueueProcessor <string>(queue, handler); var processed = await queueProcessor.ProcessAsync(); Assert.IsTrue(processed); processed = await queueProcessor.ProcessAsync(); Assert.IsFalse(processed); } }