public void Old_documents_are_being_expired() { using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var expiredDate = DateTime.UtcNow.AddDays(-3); var thresholdDate = DateTime.UtcNow.AddDays(-2); var processedMessage = new ProcessedMessage { Id = "1", ProcessedAt = expiredDate }; using (var session = documentStore.OpenSession()) { session.Store(processedMessage); session.SaveChanges(); } RunExpiry(documentStore, thresholdDate); using (var session = documentStore.OpenSession()) { Assert.IsEmpty(session.Query <ProcessedMessage>()); } } }
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 void Old_documents_are_being_expired() { using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var expiredDate = DateTime.UtcNow.AddDays(-3); var thresholdDate = DateTime.UtcNow.AddDays(-2); var sagaHistoryId = Guid.NewGuid(); var sagaHistory = new SagaSnapshot { Id = sagaHistoryId, }; using (new RavenLastModifiedScope(expiredDate)) using (var session = documentStore.OpenSession()) { session.Store(sagaHistory); session.SaveChanges(); } RunExpiry(documentStore, thresholdDate); using (var session = documentStore.OpenSession()) { Assert.IsEmpty(session.Query <SagaSnapshot>()); } } }
public async Task Attachments_with_ids_that_contain_backslash_should_be_readable() { using (var store = InMemoryStoreBuilder.GetInMemoryStore()) { var bodyStore = new RavenAttachmentsBodyStorage { DocumentStore = store }; var messageId = "messagebodies/3f0240a7-9b2e-4e2a-ab39-6114932adad1\\2055783"; var contentType = "NotImportant"; var body = new byte[] { 1, 2, 3 }; await bodyStore.Store(messageId, contentType, body.Length, new MemoryStream(body)); var retrieved = await bodyStore.TryFetch(messageId); Assert.True(retrieved.HasResult); Assert.AreEqual(contentType, retrieved.ContentType); var buffer = new byte[retrieved.BodySize]; retrieved.Stream.Read(buffer, 0, retrieved.BodySize); Assert.AreEqual(body, buffer); } }
public void Recent_processed_messages_are_not_being_expired() { using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var thresholdDate = DateTime.UtcNow.AddDays(-2); var recentDate = DateTime.UtcNow.AddDays(-1); var sagaHistory = new SagaSnapshot { Id = Guid.NewGuid() }; using (new RavenLastModifiedScope(recentDate)) using (var session = documentStore.OpenSession()) { session.Store(sagaHistory); session.SaveChanges(); } RunExpiry(documentStore, thresholdDate); using (var session = documentStore.OpenSession()) { Assert.AreEqual(1, session.Query <SagaSnapshot>().Count()); } } }
public void RunMapReduce() { using (var store = InMemoryStoreBuilder.GetInMemoryStore()) { store.ExecuteIndex(new SagaListIndex()); using (var session = store.OpenSession()) { foreach (var sagaHistory in GetFakeHistory()) { session.Store(sagaHistory); } session.SaveChanges(); } store.WaitForIndexing(); using (var session = store.OpenSession()) { var mapReduceResults = session.Query <SagaListIndex.Result, SagaListIndex>() .ToList(); Approver.Verify(mapReduceResults); } } }
public async Task Should_migrate_idempotently() { Guid sendHostId = Guid.NewGuid(); Guid receiverHostId = Guid.NewGuid(); using (var store = InMemoryStoreBuilder.GetInMemoryStore()) { store.ExecuteIndex(new EndpointsIndex()); using (var session = store.OpenAsyncSession()) { await session.StoreAsync(new ProcessedMessage { Id = "1", ProcessedAt = DateTime.Now, UniqueMessageId = "xyz", MessageMetadata = new System.Collections.Generic.Dictionary <string, object> { { "SendingEndpoint", new EndpointDetails { Host = "SendHost", HostId = sendHostId, Name = "SendHostName" } }, { "ReceivingEndpoint", new EndpointDetails { Host = "ReceivingHost", HostId = receiverHostId, Name = "ReceivingHostName" } }, } }); await session.SaveChangesAsync(); } store.WaitForIndexing(); var migrator = new MigrateKnownEndpoints(store); await migrator.MigrateEndpoints().ConfigureAwait(false); store.ExecuteIndex(new EndpointsIndex()); store.WaitForIndexing(); await migrator.MigrateEndpoints().ConfigureAwait(false); await migrator.MigrateEndpoints().ConfigureAwait(false); await migrator.MigrateEndpoints().ConfigureAwait(false); await migrator.MigrateEndpoints().ConfigureAwait(false); await migrator.MigrateEndpoints().ConfigureAwait(false); using (var session = store.OpenAsyncSession()) { var loadedSenderEndpoint = await session.LoadAsync <KnownEndpoint>(KnownEndpoint.MakeDocumentId("SendHostName", sendHostId)).ConfigureAwait(false); var loadedReceiverEndpoint = await session.LoadAsync <KnownEndpoint>(KnownEndpoint.MakeDocumentId("ReceivingHostName", receiverHostId)).ConfigureAwait(false); Assert.NotNull(loadedReceiverEndpoint); Assert.NotNull(loadedSenderEndpoint); } } }
public void Errors_are_not_being_expired() { using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var failedMsg = new FailedMessage { Id = "1", }; using (var session = documentStore.OpenSession()) { session.Store(failedMsg); session.SaveChanges(); Debug.WriteLine(session.Advanced.GetMetadataFor(failedMsg)["Last-Modified"]); } Thread.Sleep(100); RunExpiry(documentStore, DateTime.UtcNow); using (var session = documentStore.OpenSession()) { Assert.NotNull(session.Load <FailedMessage>(failedMsg.Id)); } } }
public async Task When_a_group_is_prepared_and_SC_is_started_the_group_is_marked_as_failed() { var domainEvents = new FakeDomainEvents(); var retryManager = new RetryingManager(domainEvents); using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { await CreateAFailedMessageAndMarkAsPartOfRetryBatch(documentStore, retryManager, "Test-group", false, 1); new RetryBatches_ByStatusAndSession().Execute(documentStore); new FailedMessageRetries_ByBatch().Execute(documentStore); documentStore.WaitForIndexing(); var documentManager = new CustomRetryDocumentManager(false, documentStore) { OperationManager = retryManager }; var orphanage = new FailedMessageRetries.AdoptOrphanBatchesFromPreviousSession(documentManager, null, documentStore); await orphanage.AdoptOrphanedBatchesAsync(); var status = retryManager.GetStatusForRetryOperation("Test-group", RetryType.FailureGroup); Assert.True(status.Failed); } }
public async Task ArchiveGroup_skips_over_empty_batches_but_still_completes() { // Arrange using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var groupId = "TestGroup"; var previousArchiveBatchId = ArchiveBatch.MakeId(groupId, ArchiveType.FailureGroup, 1); using (var session = documentStore.OpenAsyncSession()) { var previousArchiveBatch = new ArchiveBatch { Id = previousArchiveBatchId }; await session.StoreAsync(previousArchiveBatch) .ConfigureAwait(false); var previousArchiveOperation = new ArchiveOperation { Id = ArchiveOperation.MakeId(groupId, ArchiveType.FailureGroup), RequestId = groupId, ArchiveType = ArchiveType.FailureGroup, TotalNumberOfMessages = 2, NumberOfMessagesArchived = 0, Started = DateTime.Now, GroupName = "Test Group", NumberOfBatches = 3, CurrentBatch = 0 }; await session.StoreAsync(previousArchiveOperation) .ConfigureAwait(false); await session.SaveChangesAsync() .ConfigureAwait(false); } var domainEvents = new DomainEvents(); var handler = new ArchiveAllInGroupHandler(documentStore, new FakeDomainEvents(), new ArchiveDocumentManager(), new ArchivingManager(domainEvents), new RetryingManager(domainEvents)); var context = new TestableMessageHandlerContext(); var message = new ArchiveAllInGroup { GroupId = groupId }; // Act await handler.Handle(message, context) .ConfigureAwait(false); // Assert using (var session = documentStore.OpenSession()) { var loadedBatch = session.Load <ArchiveBatch>(previousArchiveBatchId); Assert.IsNull(loadedBatch); } } }
public void SetUp() { documentStore = InMemoryStoreBuilder.GetInMemoryStore(withExpiration: true); var customIndex = new ExpiryProcessedMessageIndex(); customIndex.Execute(documentStore); }
public async Task Stored_bodies_are_being_removed_when_message_expires() { using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var expiredDate = DateTime.UtcNow.AddDays(-3); var thresholdDate = DateTime.UtcNow.AddDays(-2); // Store expired message with associated body var messageId = "21"; var processedMessage = new ProcessedMessage { Id = "1", ProcessedAt = expiredDate, MessageMetadata = new Dictionary <string, object> { { "MessageId", messageId } } }; using (var session = documentStore.OpenSession()) { session.Store(processedMessage); session.SaveChanges(); } var body = new byte[] { 1, 2, 3, 4, 5 }; var bodyStorage = new RavenAttachmentsBodyStorage { DocumentStore = documentStore }; using (var stream = new MemoryStream(body)) { await bodyStorage.Store(messageId, "binary", 5, stream); } RunExpiry(documentStore, thresholdDate); // Verify message expired using (var session = documentStore.OpenSession()) { Assert.Null(session.Load <ProcessedMessage>(processedMessage.Id)); } // Verify body expired Assert.False((await bodyStorage.TryFetch(messageId)).HasResult, "Audit document body should be deleted"); } }
public async Task When_a_group_is_prepared_with_three_batches_and_SC_is_restarted_while_the_first_group_is_being_forwarded_then_the_count_still_matches() { 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, 2001); new RetryBatches_ByStatus_ReduceInitialBatchSize().Execute(documentStore); 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 processor = new RetryProcessor(sender, domainEvents, new TestReturnToSenderDequeuer(bodyStorage, sender, documentStore, domainEvents, configure), retryManager); documentStore.WaitForIndexing(); using (var session = documentStore.OpenAsyncSession()) { await processor.ProcessBatches(session, CancellationToken.None); // mark ready await session.SaveChangesAsync(); // Simulate SC restart retryManager = new RetryingManager(domainEvents); RetryingManager.RetryOperations = new Dictionary <string, InMemoryRetry>(); var documentManager = new CustomRetryDocumentManager(false, documentStore) { OperationManager = retryManager }; await documentManager.RebuildRetryOperationState(session); processor = new RetryProcessor(sender, domainEvents, new TestReturnToSenderDequeuer(bodyStorage, sender, documentStore, domainEvents, configure), retryManager); await processor.ProcessBatches(session, CancellationToken.None); await session.SaveChangesAsync(); } var status = retryManager.GetStatusForRetryOperation("Test-group", RetryType.FailureGroup); Assert.AreEqual(2001, status.TotalNumberOfMessages); } }
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 void SetUp() { documentStore = InMemoryStoreBuilder.GetInMemoryStore(); var customIndex = new FailedMessageViewIndex(); customIndex.Execute(documentStore); var transformer = new FailedMessageViewTransformer(); transformer.Execute(documentStore); }
public void ArchiveGroup_skips_over_empty_batches_but_still_completes() { // Arrange using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var groupId = "TestGroup"; var previousArchiveBatchId = ArchiveBatch.MakeId(groupId, ArchiveType.FailureGroup, 1); using (var session = documentStore.OpenSession()) { var previousAchiveBatch = new ArchiveBatch { Id = previousArchiveBatchId }; session.Store(previousAchiveBatch); var previousArchiveOperation = new ArchiveOperation { Id = ArchiveOperation.MakeId(groupId, ArchiveType.FailureGroup), RequestId = groupId, ArchiveType = ArchiveType.FailureGroup, TotalNumberOfMessages = 2, NumberOfMessagesArchived = 0, Started = DateTime.Now, GroupName = "Test Group", NumberOfBatches = 3, CurrentBatch = 0 }; session.Store(previousArchiveOperation); session.SaveChanges(); } var documentManager = new ArchiveDocumentManager(); var domainEvents = new FakeDomainEvents(); var archivingManager = new ArchivingManager(domainEvents); var retryingManager = new RetryingManager(domainEvents); var handler = new ArchiveAllInGroupHandler(documentStore, domainEvents, documentManager, archivingManager, retryingManager); var message = new ArchiveAllInGroup { GroupId = groupId }; // Act handler.Handle(message); // Assert using (var session = documentStore.OpenSession()) { var loadedBatch = session.Load <ArchiveBatch>(previousArchiveBatchId); Assert.IsNull(loadedBatch); } } }
public async Task Pass_if_no_failed_imports() { using (var store = InMemoryStoreBuilder.GetInMemoryStore()) { store.ExecuteIndex(new FailedAuditImportIndex()); var customCheck = new FailedAuditImportCustomCheck(store); var result = await customCheck.PerformCheck(); Assert.AreEqual(CheckResult.Pass, result); } }
public void When_a_group_is_processed_it_is_set_to_the_Preparing_state() { var retryManager = new RetryingManager(); RetryingManager.RetryOperations = new Dictionary <string, InMemoryRetry>(); using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { CreateAFailedMessageAndMarkAsPartOfRetryBatch(documentStore, retryManager, "Test-group", true, 1); var status = retryManager.GetStatusForRetryOperation("Test-group", RetryType.FailureGroup); Assert.AreEqual(RetryState.Preparing, status.RetryState); } }
public async Task When_a_group_is_processed_it_is_set_to_the_Preparing_state() { var domainEvents = new FakeDomainEvents(); var retryManager = new RetryingManager(domainEvents); using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { await CreateAFailedMessageAndMarkAsPartOfRetryBatch(documentStore, retryManager, "Test-group", true, 1); var status = retryManager.GetStatusForRetryOperation("Test-group", RetryType.FailureGroup); Assert.AreEqual(RetryState.Preparing, status.RetryState); } }
public void Many_documents_are_being_expired() { using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var expiredDate = DateTime.UtcNow.AddDays(-3); var thresholdDate = DateTime.UtcNow.AddDays(-2); var recentDate = DateTime.UtcNow.AddDays(-1); var expiredMessages = BuildExpiredMessaged(expiredDate).ToList(); using (var session = documentStore.OpenSession()) { foreach (var message in expiredMessages) { session.Store(message); } session.SaveChanges(); } using (var session = documentStore.OpenSession()) { var recentMessage = new ProcessedMessage { Id = "recentMessageId", ProcessedAt = recentDate }; session.Store(recentMessage); session.SaveChanges(); } RunExpiry(documentStore, thresholdDate); foreach (dynamic message in expiredMessages) { using (var session = documentStore.OpenSession()) { Assert.Null(session.Load <ProcessedMessage>(message.Id)); } } using (var session = documentStore.OpenSession()) { Assert.AreEqual(1, session.Query <ProcessedMessage>().Count()); } } }
public async Task Should_delete_index_after_second_migration() { Guid sendHostId = Guid.NewGuid(); Guid receiverHostId = Guid.NewGuid(); using (var store = InMemoryStoreBuilder.GetInMemoryStore()) { store.ExecuteIndex(new EndpointsIndex()); using (var session = store.OpenAsyncSession()) { await session.StoreAsync(new ProcessedMessage { Id = "1", ProcessedAt = DateTime.Now, UniqueMessageId = "xyz", MessageMetadata = new System.Collections.Generic.Dictionary <string, object> { { "SendingEndpoint", new EndpointDetails { Host = "SendHost", HostId = sendHostId, Name = "SendHostName" } }, { "ReceivingEndpoint", new EndpointDetails { Host = "ReceivingHost", HostId = receiverHostId, Name = "ReceivingHostName" } }, } }); await session.SaveChangesAsync(); } store.WaitForIndexing(); var migrator = new MigrateKnownEndpoints(store); await migrator.MigrateEndpoints().ConfigureAwait(false); await migrator.MigrateEndpoints().ConfigureAwait(false); var knownEndpointsIndex = await store.AsyncDatabaseCommands.GetIndexAsync("EndpointsIndex").ConfigureAwait(false); Assert.IsNull(knownEndpointsIndex); } }
public async Task Should_disable_index_after_first_migration() { Guid sendHostId = Guid.NewGuid(); Guid receiverHostId = Guid.NewGuid(); using (var store = InMemoryStoreBuilder.GetInMemoryStore()) { store.ExecuteIndex(new EndpointsIndex()); using (var session = store.OpenAsyncSession()) { await session.StoreAsync(new ProcessedMessage { Id = "1", ProcessedAt = DateTime.Now, UniqueMessageId = "xyz", MessageMetadata = new System.Collections.Generic.Dictionary <string, object> { { "SendingEndpoint", new EndpointDetails { Host = "SendHost", HostId = sendHostId, Name = "SendHostName" } }, { "ReceivingEndpoint", new EndpointDetails { Host = "ReceivingHost", HostId = receiverHostId, Name = "ReceivingHostName" } }, } }); await session.SaveChangesAsync(); } store.WaitForIndexing(); var migrator = new MigrateKnownEndpoints(store); await migrator.MigrateEndpoints().ConfigureAwait(false); var dbStatistics = await store.AsyncDatabaseCommands.GetStatisticsAsync().ConfigureAwait(false); var indexStats = dbStatistics.Indexes.First(index => index.Name == "EndpointsIndex"); Assert.AreEqual(IndexingPriority.Disabled, indexStats.Priority); } }
public async Task When_a_group_has_one_batch_out_of_two_forwarded_the_status_is_Forwarding() { 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, 1001); var bodyStorage = new RavenAttachmentsBodyStorage { DocumentStore = documentStore }; var sender = new TestSender(); 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 processor = new RetryProcessor(sender, domainEvents, new TestReturnToSenderDequeuer(bodyStorage, sender, documentStore, domainEvents, configure), retryManager); documentStore.WaitForIndexing(); 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.Forwarding, status.RetryState); } }
public async Task Should_clean_expired_endpoints() { using (var store = InMemoryStoreBuilder.GetInMemoryStore()) { new ExpiryKnownEndpointsIndex().Execute(store.DatabaseCommands, new DocumentConvention()); using (var bulkInsert = store.BulkInsert()) { for (var i = 0; i < 50; i++) { bulkInsert.Store(new KnownEndpoint { LastSeen = DateTime.UtcNow }); } for (var i = 0; i < 50; i++) { bulkInsert.Store(new KnownEndpoint { LastSeen = DateTime.UtcNow.Subtract(TimeSpan.FromDays(1)) }); } await bulkInsert.DisposeAsync(); } store.WaitForIndexing(); KnownEndpointsCleaner.Clean(25, store.DocumentDatabase, DateTime.UtcNow.Subtract(TimeSpan.FromHours(5)), CancellationToken.None); store.WaitForIndexing(); KnownEndpointsCleaner.Clean(25, store.DocumentDatabase, DateTime.UtcNow.Subtract(TimeSpan.FromHours(5)), CancellationToken.None); store.WaitForIndexing(); using (var session = store.OpenAsyncSession()) { var foundEndpoints = await session.Query <KnownEndpoint>().CountAsync(); Assert.AreEqual(50, foundEndpoints); } } }
public void Only_expired_being_deleted() { using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var expiredDate = DateTime.UtcNow.AddDays(-3); var thresholdDate = DateTime.UtcNow.AddDays(-2); var recentDate = DateTime.UtcNow.AddDays(-1); var expiredSagaHistory = new SagaSnapshot { Id = Guid.NewGuid() }; using (new RavenLastModifiedScope(expiredDate)) using (var session = documentStore.OpenSession()) { session.Store(expiredSagaHistory); session.SaveChanges(); } var recentSagaHistory = new SagaSnapshot { Id = Guid.NewGuid() }; using (new RavenLastModifiedScope(recentDate)) using (var session = documentStore.OpenSession()) { session.Store(recentSagaHistory); session.SaveChanges(); } RunExpiry(documentStore, thresholdDate); using (var session = documentStore.OpenSession()) { Assert.Null(session.Load <SagaSnapshot>(expiredSagaHistory.Id)); Assert.NotNull(session.Load <SagaSnapshot>(recentSagaHistory.Id)); } } }
public void Many_documents_are_being_expired() { using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var expiredDate = DateTime.UtcNow.AddDays(-3); var thresholdDate = DateTime.UtcNow.AddDays(-2); var recentDate = DateTime.UtcNow.AddDays(-1); var expiredMessages = BuilExpiredMessaged().ToList(); using (new RavenLastModifiedScope(expiredDate)) { using (var session = documentStore.OpenSession()) { foreach (var message in expiredMessages) { session.Store(message); } session.SaveChanges(); } } using (new RavenLastModifiedScope(recentDate)) using (var session = documentStore.OpenSession()) { var recentSagaHistory = new SagaSnapshot { Id = Guid.NewGuid() }; session.Store(recentSagaHistory); session.SaveChanges(); } RunExpiry(documentStore, thresholdDate); using (var session = documentStore.OpenSession()) { Assert.AreEqual(1, session.Query <SagaSnapshot>().Count()); } } }
public void When_a_group_is_forwarded_the_status_is_Completed() { var retryManager = new RetryingManager(); RetryingManager.RetryOperations = new Dictionary <string, InMemoryRetry>(); using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { CreateAFailedMessageAndMarkAsPartOfRetryBatch(documentStore, retryManager, "Test-group", true, 1); var testBus = new TestBus(); 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, testBus, configure); var processor = new RetryProcessor(sender, testBus, returnToSender, retryManager); using (var session = documentStore.OpenSession()) { processor.ProcessBatches(session, CancellationToken.None); // mark ready session.SaveChanges(); processor.ProcessBatches(session, CancellationToken.None); session.SaveChanges(); } var status = retryManager.GetStatusForRetryOperation("Test-group", RetryType.FailureGroup); Assert.AreEqual(RetryState.Completed, status.RetryState); } }
public void Only_processed_messages_are_being_expired() { using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var expiredDate = DateTime.UtcNow.AddDays(-3); var thresholdDate = DateTime.UtcNow.AddDays(-2); var recentDate = DateTime.UtcNow.AddDays(-1); var expiredMessage = new ProcessedMessage { Id = "1", ProcessedAt = expiredDate }; using (var session = documentStore.OpenSession()) { session.Store(expiredMessage); session.SaveChanges(); } var recentMessage = new ProcessedMessage { Id = "2", ProcessedAt = recentDate }; using (var session = documentStore.OpenSession()) { session.Store(recentMessage); session.SaveChanges(); } RunExpiry(documentStore, thresholdDate); using (var session = documentStore.OpenSession()) { Assert.Null(session.Load <ProcessedMessage>(expiredMessage.Id)); Assert.NotNull(session.Load <ProcessedMessage>(recentMessage.Id)); } } }
public void Recent_processed_messages_are_not_being_expired() { using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore()) { var thresholdDate = DateTime.UtcNow.AddDays(-2); var recentDate = DateTime.UtcNow.AddDays(-1); var message = new ProcessedMessage { Id = "1", ProcessedAt = recentDate }; using (var session = documentStore.OpenSession()) { session.Store(message); session.SaveChanges(); } RunExpiry(documentStore, thresholdDate); using (var session = documentStore.OpenSession()) { Assert.AreEqual(1, session.Query <ProcessedMessage>().Count()); } } }
public async Task Fail_if_failed_imports() { using (var store = InMemoryStoreBuilder.GetInMemoryStore()) { store.ExecuteIndex(new FailedAuditImportIndex()); using (var session = store.OpenAsyncSession()) { await session.StoreAsync(new FailedAuditImport()); await session.SaveChangesAsync(); } store.WaitForIndexing(); var customCheck = new FailedAuditImportCustomCheck(store); var result = await customCheck.PerformCheck(); Assert.IsTrue(result.HasFailed); StringAssert.StartsWith("One or more audit messages have failed to import properly into ServiceControl and have been stored in the ServiceControl database.", result.FailureReason); } }