public async Task When_a_group_is_forwarded_the_status_is_Completed() { var domainEvents = new FakeDomainEvents(); var retryManager = new RetryingManager(domainEvents); using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { await CreateAFailedMessageAndMarkAsPartOfRetryBatch(documentStore, retryManager, "Test-group", true, 1); var sender = new TestSender(); var bodyStorage = new RavenAttachmentsBodyStorage { DocumentStore = documentStore }; var returnToSender = new TestReturnToSenderDequeuer(new ReturnToSender(bodyStorage), documentStore, domainEvents, "TestEndpoint"); var processor = new RetryProcessor(sender, domainEvents, returnToSender, retryManager); using (var session = documentStore.OpenAsyncSession()) { await processor.ProcessBatches(session, CancellationToken.None); // mark ready await session.SaveChangesAsync(); await processor.ProcessBatches(session, CancellationToken.None); await session.SaveChangesAsync(); } var status = retryManager.GetStatusForRetryOperation("Test-group", RetryType.FailureGroup); Assert.AreEqual(RetryState.Completed, status.RetryState); } }
public async Task When_there_is_one_poison_message_it_is_removed_from_batch_and_the_status_is_Complete() { var domainEvents = new FakeDomainEvents(); var retryManager = new RetryingManager(domainEvents); using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { await CreateAFailedMessageAndMarkAsPartOfRetryBatch(documentStore, retryManager, "Test-group", true, "A", "B", "C"); var sender = new TestSender(); sender.Callback = operation => { //Always fails staging message B if (operation.Message.MessageId == "FailedMessages/B") { throw new Exception("Simulated"); } }; var bodyStorage = new RavenAttachmentsBodyStorage { DocumentStore = documentStore }; var returnToSender = new TestReturnToSenderDequeuer(new ReturnToSender(bodyStorage), documentStore, domainEvents, "TestEndpoint"); var processor = new RetryProcessor(documentStore, sender, domainEvents, returnToSender, retryManager); bool c; do { try { using (var session = documentStore.OpenAsyncSession()) { c = await processor.ProcessBatches(session, CancellationToken.None); await session.SaveChangesAsync(); } } catch (Exception) { //Continue trying until there is no exception -> poison message is removed from the batch c = true; } } while (c); var status = retryManager.GetStatusForRetryOperation("Test-group", RetryType.FailureGroup); Assert.AreEqual(RetryState.Completed, status.RetryState); Assert.AreEqual(3, status.NumberOfMessagesPrepared); Assert.AreEqual(2, status.NumberOfMessagesForwarded); Assert.AreEqual(1, status.NumberOfMessagesSkipped); } }
public async Task When_a_group_is_forwarded_the_status_is_Completed() { var domainEvents = new FakeDomainEvents(); var retryManager = new RetryingManager(domainEvents); RetryingManager.RetryOperations = new Dictionary <string, InMemoryRetry>(); using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { CreateAFailedMessageAndMarkAsPartOfRetryBatch(documentStore, retryManager, "Test-group", true, 1); var sender = new TestSender(); var bodyStorage = new RavenAttachmentsBodyStorage { DocumentStore = documentStore }; var settingsHolder = new NServiceBus.Settings.SettingsHolder(); settingsHolder.Set("EndpointName", "TestEndpoint"); var configure = new Configure(settingsHolder, new TestContainer(), new List <Action <NServiceBus.ObjectBuilder.IConfigureComponents> >(), new NServiceBus.Pipeline.PipelineSettings(new BusConfiguration())); var returnToSender = new TestReturnToSenderDequeuer(bodyStorage, sender, documentStore, domainEvents, configure); var processor = new RetryProcessor(sender, domainEvents, returnToSender, retryManager); using (var session = documentStore.OpenAsyncSession()) { await processor.ProcessBatches(session, CancellationToken.None); // mark ready await session.SaveChangesAsync(); await processor.ProcessBatches(session, CancellationToken.None); await session.SaveChangesAsync(); } var status = retryManager.GetStatusForRetryOperation("Test-group", RetryType.FailureGroup); Assert.AreEqual(RetryState.Completed, status.RetryState); } }