diff --git a/src/Extensions/Wolverine.MemoryPack.Tests/end_to_end.cs b/src/Extensions/Wolverine.MemoryPack.Tests/end_to_end.cs index a24dee77e..5214a21dc 100644 --- a/src/Extensions/Wolverine.MemoryPack.Tests/end_to_end.cs +++ b/src/Extensions/Wolverine.MemoryPack.Tests/end_to_end.cs @@ -55,6 +55,8 @@ public async Task DisposeAsync() { await _receivingHost.StopAsync(); await _publishingHost.StopAsync(); + _receivingHost.Dispose(); + _publishingHost.Dispose(); } #endregion diff --git a/src/Extensions/Wolverine.MessagePack.Tests/end_to_end.cs b/src/Extensions/Wolverine.MessagePack.Tests/end_to_end.cs index a827e0798..49e692e7b 100644 --- a/src/Extensions/Wolverine.MessagePack.Tests/end_to_end.cs +++ b/src/Extensions/Wolverine.MessagePack.Tests/end_to_end.cs @@ -96,6 +96,8 @@ public async Task DisposeAsync() { await _receivingHost.StopAsync(); await _publishingHost.StopAsync(); + _receivingHost.Dispose(); + _publishingHost.Dispose(); } #endregion diff --git a/src/Extensions/Wolverine.Protobuf.Tests/end_to_end.cs b/src/Extensions/Wolverine.Protobuf.Tests/end_to_end.cs index 3e2a5dc70..0640609ad 100644 --- a/src/Extensions/Wolverine.Protobuf.Tests/end_to_end.cs +++ b/src/Extensions/Wolverine.Protobuf.Tests/end_to_end.cs @@ -59,6 +59,8 @@ public async Task DisposeAsync() { await _receivingHost.StopAsync(); await _publishingHost.StopAsync(); + _receivingHost.Dispose(); + _publishingHost.Dispose(); } #endregion diff --git a/src/Http/Wolverine.Http.Tests/Transport/CloudEventsHttpTransportTests.cs b/src/Http/Wolverine.Http.Tests/Transport/CloudEventsHttpTransportTests.cs index d01622262..dd5b1932a 100644 --- a/src/Http/Wolverine.Http.Tests/Transport/CloudEventsHttpTransportTests.cs +++ b/src/Http/Wolverine.Http.Tests/Transport/CloudEventsHttpTransportTests.cs @@ -9,7 +9,7 @@ namespace Wolverine.Http.Tests.Transport; -public class CloudEventsHttpTransportTests +public class CloudEventsHttpTransportTests : IDisposable { private readonly IHttpClientFactory _clientFactory; private readonly MockHttpMessageHandler _handler; @@ -145,6 +145,12 @@ public async Task cloud_events_with_null_options_uses_default() _handler.LastRequest.ShouldNotBeNull(); _handler.LastRequest.Content!.Headers.ContentType!.MediaType.ShouldBe(HttpTransport.CloudEventsContentType); } + + public void Dispose() + { + _httpClient.Dispose(); + _handler.Dispose(); + } } public class TestMessage diff --git a/src/Http/Wolverine.Http.Tests/Transport/WolverineHttpTransportClientTests.cs b/src/Http/Wolverine.Http.Tests/Transport/WolverineHttpTransportClientTests.cs index dc4a377a9..417ff7918 100644 --- a/src/Http/Wolverine.Http.Tests/Transport/WolverineHttpTransportClientTests.cs +++ b/src/Http/Wolverine.Http.Tests/Transport/WolverineHttpTransportClientTests.cs @@ -10,7 +10,7 @@ namespace Wolverine.Http.Tests.Transport; -public class WolverineHttpTransportClientTests +public class WolverineHttpTransportClientTests : IDisposable { private readonly IHttpClientFactory _clientFactory; private readonly MockHttpMessageHandler _handler; @@ -74,6 +74,12 @@ public async Task send_batch_async() var expectedData = EnvelopeSerializer.Serialize(envelopes); _handler.LastContent.ShouldBe(expectedData); } + + public void Dispose() + { + _httpClient.Dispose(); + _handler.Dispose(); + } } public class MockHttpMessageHandler : HttpMessageHandler diff --git a/src/Http/Wolverine.Http.Tests/posting_json.cs b/src/Http/Wolverine.Http.Tests/posting_json.cs index dae1f9ce3..0d46b8876 100644 --- a/src/Http/Wolverine.Http.Tests/posting_json.cs +++ b/src/Http/Wolverine.Http.Tests/posting_json.cs @@ -115,7 +115,7 @@ public async Task post_json_but_accept_text_get_406() [Fact] public async Task reading_json_from_canceled_request_gets_204() { - var cts = new CancellationTokenSource(); + using var cts = new CancellationTokenSource(); cts.Cancel(); var response = await Scenario(x => diff --git a/src/Persistence/MartenTests/AggregateHandlerWorkflow/aggregate_handler_workflow.cs b/src/Persistence/MartenTests/AggregateHandlerWorkflow/aggregate_handler_workflow.cs index 0bb3402b6..e440f43d4 100644 --- a/src/Persistence/MartenTests/AggregateHandlerWorkflow/aggregate_handler_workflow.cs +++ b/src/Persistence/MartenTests/AggregateHandlerWorkflow/aggregate_handler_workflow.cs @@ -46,6 +46,10 @@ public async Task InitializeAsync() .UseLightweightSessions() .IntegrateWithWolverine(); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(RaiseIfValidatedHandler)) + .IncludeType(typeof(ResponseHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); diff --git a/src/Persistence/MartenTests/AggregateHandlerWorkflow/aggregate_handler_workflow_with_ievent.cs b/src/Persistence/MartenTests/AggregateHandlerWorkflow/aggregate_handler_workflow_with_ievent.cs index 0ac4b845d..b477feabb 100644 --- a/src/Persistence/MartenTests/AggregateHandlerWorkflow/aggregate_handler_workflow_with_ievent.cs +++ b/src/Persistence/MartenTests/AggregateHandlerWorkflow/aggregate_handler_workflow_with_ievent.cs @@ -33,7 +33,9 @@ public async Task use_ievent_as_Guid_id() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { - opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(AEventHandler)).IncludeType(typeof(RaiseLetterHandler)); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(AEventHandler)) + .IncludeType(typeof(RaiseLetterHandler)); opts.Services.AddMarten(m => { @@ -49,8 +51,7 @@ public async Task use_ievent_as_Guid_id() }); opts.Policies.AutoApplyTransactions(); - - + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); @@ -76,7 +77,8 @@ public async Task using_string_as_stream_key() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { - opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(StringIdentifiedHandler)); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(StringIdentifiedHandler)); opts.Services.AddMarten(m => { diff --git a/src/Persistence/MartenTests/AggregateHandlerWorkflow/always_enforce_consistency_workflow.cs b/src/Persistence/MartenTests/AggregateHandlerWorkflow/always_enforce_consistency_workflow.cs index fb174e4bc..7d786b37d 100644 --- a/src/Persistence/MartenTests/AggregateHandlerWorkflow/always_enforce_consistency_workflow.cs +++ b/src/Persistence/MartenTests/AggregateHandlerWorkflow/always_enforce_consistency_workflow.cs @@ -37,7 +37,11 @@ public async Task InitializeAsync() .IntegrateWithWolverine(); opts.Services.AddResourceSetupOnStartup(); - opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto; + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(ConsistentPropertyHandler)) + .IncludeType(typeof(ConsistentAggregateHandlerUsage)) + .IncludeType(typeof(ConsistentParamHandler)); + opts.Durability.Mode = DurabilityMode.Solo; }).StartAsync(); theStore = theHost.Services.GetRequiredService(); diff --git a/src/Persistence/MartenTests/AggregateHandlerWorkflow/marten_command_workflow_middleware.cs b/src/Persistence/MartenTests/AggregateHandlerWorkflow/marten_command_workflow_middleware.cs index e34bea33e..020f94bd7 100644 --- a/src/Persistence/MartenTests/AggregateHandlerWorkflow/marten_command_workflow_middleware.cs +++ b/src/Persistence/MartenTests/AggregateHandlerWorkflow/marten_command_workflow_middleware.cs @@ -16,10 +16,11 @@ using Wolverine.ComplianceTests; using Wolverine.Marten; using Wolverine.Tracking; +using Wolverine; namespace MartenTests.AggregateHandlerWorkflow; -public class marten_command_workflow_middleware : PostgresqlContext, IAsyncLifetime, IDisposable +public class marten_command_workflow_middleware : PostgresqlContext, IAsyncLifetime { private IHost theHost = null!; private IDocumentStore theStore = null!; @@ -40,16 +41,20 @@ public async Task InitializeAsync() opts.Services.AddResourceSetupOnStartup(); opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto; + + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(SpecialLetterHandler)) + .IncludeType(typeof(LetterAggregateHandler)); + opts.Durability.Mode = DurabilityMode.Solo; }); theStore = theHost.Services.GetRequiredService(); } - Task IAsyncLifetime.DisposeAsync() => Task.CompletedTask; - - public void Dispose() + public async Task DisposeAsync() { - theHost?.Dispose(); + await theHost.StopAsync(); + theHost.Dispose(); } internal async Task GivenAggregate() diff --git a/src/Persistence/MartenTests/AggregateHandlerWorkflow/mixed_aggregate_handler_with_multiple_streams.cs b/src/Persistence/MartenTests/AggregateHandlerWorkflow/mixed_aggregate_handler_with_multiple_streams.cs index 515662ebd..854298b68 100644 --- a/src/Persistence/MartenTests/AggregateHandlerWorkflow/mixed_aggregate_handler_with_multiple_streams.cs +++ b/src/Persistence/MartenTests/AggregateHandlerWorkflow/mixed_aggregate_handler_with_multiple_streams.cs @@ -20,6 +20,8 @@ public async Task get_the_correct_aggregate_back_out() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(MakePurchaseHandler)); + opts.Durability.Mode = DurabilityMode.Solo; MartenServiceCollectionExtensions.AddMarten(opts.Services, m => { m.Connection(Servers.PostgresConnectionString); diff --git a/src/Persistence/MartenTests/AggregateHandlerWorkflow/multi_stream_version_and_consistency.cs b/src/Persistence/MartenTests/AggregateHandlerWorkflow/multi_stream_version_and_consistency.cs index d3d0e523e..300e10aa8 100644 --- a/src/Persistence/MartenTests/AggregateHandlerWorkflow/multi_stream_version_and_consistency.cs +++ b/src/Persistence/MartenTests/AggregateHandlerWorkflow/multi_stream_version_and_consistency.cs @@ -28,6 +28,12 @@ public async Task InitializeAsync() theHost = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(TransferFundsWithDualVersionHandler)) + .IncludeType(typeof(TransferWithConsistencyCheckHandler)) + .IncludeType(typeof(TransferWithConsistencyCheckNoConcurrentModificationHandler)) + .IncludeType(typeof(TransferFundsHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); diff --git a/src/Persistence/MartenTests/AggregateHandlerWorkflow/natural_key_aggregate_handler_workflow.cs b/src/Persistence/MartenTests/AggregateHandlerWorkflow/natural_key_aggregate_handler_workflow.cs index 01923f329..bb0680f6f 100644 --- a/src/Persistence/MartenTests/AggregateHandlerWorkflow/natural_key_aggregate_handler_workflow.cs +++ b/src/Persistence/MartenTests/AggregateHandlerWorkflow/natural_key_aggregate_handler_workflow.cs @@ -18,7 +18,7 @@ namespace MartenTests.AggregateHandlerWorkflow; -public class natural_key_aggregate_handler_workflow : PostgresqlContext, IAsyncLifetime, IAsyncDisposable +public class natural_key_aggregate_handler_workflow : PostgresqlContext, IAsyncLifetime { private IHost _host = null!; private IDocumentStore _store = null!; @@ -36,6 +36,10 @@ public async Task InitializeAsync() .UseLightweightSessions() .IntegrateWithWolverine(); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(NkOrderHandler)); + opts.Durability.Mode = DurabilityMode.Solo; + opts.Services.AddResourceSetupOnStartup(); opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto; }); @@ -43,15 +47,10 @@ public async Task InitializeAsync() _store = _host.Services.GetRequiredService(); } - Task IAsyncLifetime.DisposeAsync() => DisposeAsync().AsTask(); - - public async ValueTask DisposeAsync() + public async Task DisposeAsync() { - if (_host != null) - { - await _host.StopAsync(); - _host.Dispose(); - } + await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/AggregateHandlerWorkflow/override_of_event_metadata.cs b/src/Persistence/MartenTests/AggregateHandlerWorkflow/override_of_event_metadata.cs index 9cbedda8c..ca34cc804 100644 --- a/src/Persistence/MartenTests/AggregateHandlerWorkflow/override_of_event_metadata.cs +++ b/src/Persistence/MartenTests/AggregateHandlerWorkflow/override_of_event_metadata.cs @@ -20,6 +20,7 @@ public async Task return_event_with_metadata_from_aggregate_handler() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(AEventHandler)) .IncludeType(typeof(EmitEventsWithMetadataHandler)); diff --git a/src/Persistence/MartenTests/AggregateHandlerWorkflow/strong_named_identifiers.cs b/src/Persistence/MartenTests/AggregateHandlerWorkflow/strong_named_identifiers.cs index eca074298..12daa4452 100644 --- a/src/Persistence/MartenTests/AggregateHandlerWorkflow/strong_named_identifiers.cs +++ b/src/Persistence/MartenTests/AggregateHandlerWorkflow/strong_named_identifiers.cs @@ -22,6 +22,8 @@ public async Task InitializeAsync() theHost = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(StrongLetterHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); @@ -33,6 +35,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await theHost.StopAsync(); + theHost.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/AggregateHandlerWorkflow/version_source_override.cs b/src/Persistence/MartenTests/AggregateHandlerWorkflow/version_source_override.cs index 98e22114e..19c3ab977 100644 --- a/src/Persistence/MartenTests/AggregateHandlerWorkflow/version_source_override.cs +++ b/src/Persistence/MartenTests/AggregateHandlerWorkflow/version_source_override.cs @@ -26,6 +26,10 @@ public async Task InitializeAsync() theHost = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(ParamVersionSourceHandler)) + .IncludeType(typeof(CustomVersionSourceHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); diff --git a/src/Persistence/MartenTests/AncillaryStores/ancillary_store_subject_uri_uniqueness.cs b/src/Persistence/MartenTests/AncillaryStores/ancillary_store_subject_uri_uniqueness.cs index 60a7df988..4eeee5983 100644 --- a/src/Persistence/MartenTests/AncillaryStores/ancillary_store_subject_uri_uniqueness.cs +++ b/src/Persistence/MartenTests/AncillaryStores/ancillary_store_subject_uri_uniqueness.cs @@ -45,7 +45,9 @@ public async Task InitializeAsync() m.DatabaseSchemaName = "things"; }).IntegrateWithWolverine(); + opts.Discovery.DisableConventionalDiscovery(); opts.Durability.Mode = DurabilityMode.Solo; + }).StartAsync(); } diff --git a/src/Persistence/MartenTests/AncillaryStores/ancillary_stores_use_different_databases.cs b/src/Persistence/MartenTests/AncillaryStores/ancillary_stores_use_different_databases.cs index c43c6f0e0..aa9307a01 100644 --- a/src/Persistence/MartenTests/AncillaryStores/ancillary_stores_use_different_databases.cs +++ b/src/Persistence/MartenTests/AncillaryStores/ancillary_stores_use_different_databases.cs @@ -63,6 +63,9 @@ public async Task InitializeAsync() m.Connection(thingsConnectionString); }).IntegrateWithWolverine(x => x.MainConnectionString = Servers.PostgresConnectionString); + opts.Discovery.DisableConventionalDiscovery(); + opts.Durability.Mode = DurabilityMode.Solo; + opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); diff --git a/src/Persistence/MartenTests/AncillaryStores/bootstrapping_ancillary_marten_stores_with_wolverine.cs b/src/Persistence/MartenTests/AncillaryStores/bootstrapping_ancillary_marten_stores_with_wolverine.cs index 880cfaa8f..21bfb9432 100644 --- a/src/Persistence/MartenTests/AncillaryStores/bootstrapping_ancillary_marten_stores_with_wolverine.cs +++ b/src/Persistence/MartenTests/AncillaryStores/bootstrapping_ancillary_marten_stores_with_wolverine.cs @@ -98,7 +98,8 @@ public async Task InitializeAsync() { x.MainConnectionString = Servers.PostgresConnectionString; }); - + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(PlayerMessageHandler)); opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_1175_schema_name_with_queues.cs b/src/Persistence/MartenTests/Bugs/Bug_1175_schema_name_with_queues.cs index b61a9cda7..b9511b510 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_1175_schema_name_with_queues.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_1175_schema_name_with_queues.cs @@ -4,13 +4,10 @@ using JasperFx.Core; using JasperFx.MultiTenancy; using Marten; -using Marten.Storage; using Microsoft.Extensions.Hosting; using JasperFx.Resources; using Shouldly; -using Weasel.Core; using Wolverine; -using Wolverine.Configuration; using Wolverine.Marten; using Wolverine.Postgresql; using Wolverine.Tracking; @@ -42,6 +39,9 @@ public async Task send_messages_with_postgresql_queueing() options.MessageStorageSchemaName = "sender"; }); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(ColorResponseHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); @@ -69,6 +69,9 @@ public async Task send_messages_with_postgresql_queueing() options.MessageStorageSchemaName = "listener"; }); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(ColorRequestHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_1427_no_endpoint_error_on_retries.cs b/src/Persistence/MartenTests/Bugs/Bug_1427_no_endpoint_error_on_retries.cs index 63b4fe026..1c7125abb 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_1427_no_endpoint_error_on_retries.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_1427_no_endpoint_error_on_retries.cs @@ -19,7 +19,7 @@ public class Bug_1427_no_endpoint_error_on_retries : IAsyncLifetime { private IHost _host = null!; - public Task InitializeAsync() + public async Task InitializeAsync() { var builder = Host.CreateApplicationBuilder(); builder.Services.AddMarten(o => @@ -45,14 +45,13 @@ public Task InitializeAsync() options.Policies.LogMessageStarting(LogLevel.Information); - options.MultipleHandlerBehavior = MultipleHandlerBehavior.Separated; - - if (builder.Environment.IsDevelopment()) - { - options.Durability.Mode = DurabilityMode.Solo; - } - - // ISSUE: this attempt to retry the failed messages leads to the "Wolverine.Runtime.Handlers.NoHandlerForEndpointException" + options.MultipleHandlerBehavior = MultipleHandlerBehavior.Separated; + + options.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(StartBatchHandler)); + options.Durability.Mode = DurabilityMode.Solo; + + // ISSUE: this attempt to retry the failed messages leads to the "Wolverine.Runtime.Handlers.NoHandlerForEndpointException" options .OnException() .RetryWithCooldown(2.Seconds(), 4.Seconds(), 8.Seconds()); @@ -60,12 +59,13 @@ public Task InitializeAsync() }); _host = builder.Build(); - return _host.StartAsync(); + await _host.StartAsync(); } - public Task DisposeAsync() + public async Task DisposeAsync() { - return _host.StopAsync(); + await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/Bugs/Bug_191_marten_aggregate_handler_command_should_not_require_version.cs b/src/Persistence/MartenTests/Bugs/Bug_191_marten_aggregate_handler_command_should_not_require_version.cs index a703b7740..b45119a73 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_191_marten_aggregate_handler_command_should_not_require_version.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_191_marten_aggregate_handler_command_should_not_require_version.cs @@ -20,7 +20,8 @@ public async Task InitializeAsync() .UseWolverine(opts => { opts.Discovery.DisableConventionalDiscovery() - .IncludeType(typeof(UpdateThingAggregateHandler)); + .IncludeType(typeof(UpdateThingAggregateHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(marten => { diff --git a/src/Persistence/MartenTests/Bugs/Bug_2026_scheduled_messages_with_partitioning.cs b/src/Persistence/MartenTests/Bugs/Bug_2026_scheduled_messages_with_partitioning.cs index 474282928..a4e512a9f 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_2026_scheduled_messages_with_partitioning.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_2026_scheduled_messages_with_partitioning.cs @@ -23,6 +23,7 @@ public async Task send_messages_with_delay() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(ReproduceBugHandler)); opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => diff --git a/src/Persistence/MartenTests/Bugs/Bug_215_erroneous_failure_ack_on_invoke_async_of_t.cs b/src/Persistence/MartenTests/Bugs/Bug_215_erroneous_failure_ack_on_invoke_async_of_t.cs index f96510984..313cf4a79 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_215_erroneous_failure_ack_on_invoke_async_of_t.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_215_erroneous_failure_ack_on_invoke_async_of_t.cs @@ -24,7 +24,9 @@ public async Task no_failure_ack_on_invoke_async() }).IntegrateWithWolverine(); opts.Policies.AutoApplyTransactions(); - + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(LookupHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_218_auto_transaction_when_session_is_dependency_of_a_dependency.cs b/src/Persistence/MartenTests/Bugs/Bug_218_auto_transaction_when_session_is_dependency_of_a_dependency.cs index 3cc50d9a3..9cc78098c 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_218_auto_transaction_when_session_is_dependency_of_a_dependency.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_218_auto_transaction_when_session_is_dependency_of_a_dependency.cs @@ -22,7 +22,11 @@ public async Task should_apply_transaction() opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); - opts.Services.AddScoped(); + opts.Services.AddScoped(); + + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(); + opts.Durability.Mode = DurabilityMode.Solo; }).StartAsync(); var id = Guid.NewGuid(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_225_compound_handlers_and_marten_event_streams.cs b/src/Persistence/MartenTests/Bugs/Bug_225_compound_handlers_and_marten_event_streams.cs index 4a1ff1c5a..b8f2e1ec1 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_225_compound_handlers_and_marten_event_streams.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_225_compound_handlers_and_marten_event_streams.cs @@ -22,7 +22,13 @@ public async Task should_apply_transaction() services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); }) - .UseWolverine(opts => { opts.Policies.AutoApplyTransactions(); }) + .UseWolverine(opts => + { + opts.Policies.AutoApplyTransactions(); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(); + opts.Durability.Mode = DurabilityMode.Solo; + }) .StartAsync(); var id = Guid.NewGuid(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_226_disambiguate_loggers.cs b/src/Persistence/MartenTests/Bugs/Bug_226_disambiguate_loggers.cs index 153dd59fd..a3f4a6cc7 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_226_disambiguate_loggers.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_226_disambiguate_loggers.cs @@ -9,7 +9,6 @@ using Wolverine; using Wolverine.Configuration; using Wolverine.Marten; -using Wolverine.Runtime; using Wolverine.Runtime.Handlers; using Wolverine.Tracking; @@ -29,7 +28,13 @@ public async Task should_find_handler() services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); }) - .UseWolverine(opts => { opts.Policies.Add(); }) + .UseWolverine(opts => + { + opts.Policies.Add(); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(); + opts.Durability.Mode = DurabilityMode.Solo; + }) .StartAsync(); var id = Guid.NewGuid(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_2318_ancillary_dlq_replay.cs b/src/Persistence/MartenTests/Bugs/Bug_2318_ancillary_dlq_replay.cs index f71664d48..e5cb7af45 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_2318_ancillary_dlq_replay.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_2318_ancillary_dlq_replay.cs @@ -110,6 +110,10 @@ public async Task InitializeAsync() .ProcessEventsWithWolverineHandlersInStrictOrder("bug2318_sub", o => o.IncludeType()); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(SomeMessage2318Handler)) + .IncludeType(typeof(AncillaryEvent2318Handler)) + .IncludeType(typeof(AncillaryCommand2318Handler)); opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_2382_ancillary_store_inbox.cs b/src/Persistence/MartenTests/Bugs/Bug_2382_ancillary_store_inbox.cs index c63b85351..7b17c1561 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_2382_ancillary_store_inbox.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_2382_ancillary_store_inbox.cs @@ -104,7 +104,11 @@ public async Task InitializeAsync() opts.PublishMessage().ToLocalQueue("main"); opts.Policies.AutoApplyTransactions(); - opts.Services.AddResourceSetupOnStartup(); + opts.Services.AddResourceSetupOnStartup(); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(AncillaryMessage2382Handler)) + .IncludeType(typeof(MainStoreMessage2382Handler)); + }).StartAsync(); await _host.ResetResourceState(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_2387_write_aggregate_throw_exception_codegen.cs b/src/Persistence/MartenTests/Bugs/Bug_2387_write_aggregate_throw_exception_codegen.cs index c9908ba7c..8dd4d1ec5 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_2387_write_aggregate_throw_exception_codegen.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_2387_write_aggregate_throw_exception_codegen.cs @@ -36,7 +36,9 @@ public async Task InitializeAsync() }) .UseLightweightSessions() .IntegrateWithWolverine(); - + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(Bug2387DeleteHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_2576_ancillary_scheduled_message_stuck_incoming.cs b/src/Persistence/MartenTests/Bugs/Bug_2576_ancillary_scheduled_message_stuck_incoming.cs index 398d44813..ae392ba03 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_2576_ancillary_scheduled_message_stuck_incoming.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_2576_ancillary_scheduled_message_stuck_incoming.cs @@ -84,6 +84,10 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(AncillaryCommand2576Handler)) + .IncludeType(typeof(AncillaryEvent2576Handler)) + .IncludeType(typeof(SomeMessage2576Handler)); opts.Durability.Mode = DurabilityMode.Solo; opts.Durability.MessageIdentity = MessageIdentity.IdAndDestination; opts.Durability.KeepAfterMessageHandling = 1.Hours(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_2595_explicit_delivery_options_sagaid_should_win.cs b/src/Persistence/MartenTests/Bugs/Bug_2595_explicit_delivery_options_sagaid_should_win.cs index 95c65ddbc..79e1f6c75 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_2595_explicit_delivery_options_sagaid_should_win.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_2595_explicit_delivery_options_sagaid_should_win.cs @@ -32,6 +32,7 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_262_test_does_not_complete_with_timeout_message.cs b/src/Persistence/MartenTests/Bugs/Bug_262_test_does_not_complete_with_timeout_message.cs index de4321d4c..5de8e14e9 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_262_test_does_not_complete_with_timeout_message.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_262_test_does_not_complete_with_timeout_message.cs @@ -29,6 +29,10 @@ public async Task should_work_but_doesnt() }) .UseWolverine(w => { + w.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(SomeSaga)) + .IncludeType(typeof(Handler)); + w.Durability.Mode = DurabilityMode.Solo; w.Policies.AutoApplyTransactions(); // Uncommenting this makes the test hang and probably turn red. diff --git a/src/Persistence/MartenTests/Bugs/Bug_305_invoke_async_with_return_not_publishing_with_tuple_return_value.cs b/src/Persistence/MartenTests/Bugs/Bug_305_invoke_async_with_return_not_publishing_with_tuple_return_value.cs index 50f3b9153..718cbb9f4 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_305_invoke_async_with_return_not_publishing_with_tuple_return_value.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_305_invoke_async_with_return_not_publishing_with_tuple_return_value.cs @@ -17,6 +17,12 @@ public async Task should_publish_the_return_value() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(CreateItemCommandHandler)) + .IncludeType(typeof(AlwaysMessageHandler)) + .IncludeType(typeof(ItemCreatedHandler)) + .IncludeType(typeof(SecondItemCreatedHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString).IntegrateWithWolverine(); // Add the auto transaction middleware attachment policy opts.Policies.AutoApplyTransactions(); @@ -36,6 +42,12 @@ public async Task honor_the_attribute() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(CreateItemCommandHandler)) + .IncludeType(typeof(AlwaysMessageHandler)) + .IncludeType(typeof(Message2Handler)) + .IncludeType(typeof(Message3Handler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString).IntegrateWithWolverine(); // Add the auto transaction middleware attachment policy opts.Policies.AutoApplyTransactions(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_309_service_dependencies_should_be_deep_on_injected_arguments.cs b/src/Persistence/MartenTests/Bugs/Bug_309_service_dependencies_should_be_deep_on_injected_arguments.cs index c319af945..41e9dbf77 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_309_service_dependencies_should_be_deep_on_injected_arguments.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_309_service_dependencies_should_be_deep_on_injected_arguments.cs @@ -17,6 +17,7 @@ public async Task discover_session_is_required_by_constructor_argument_of_handle using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_310_saga_handler_that_returns_another_saga.cs b/src/Persistence/MartenTests/Bugs/Bug_310_saga_handler_that_returns_another_saga.cs index 5c07f6fc5..6a5bc0d69 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_310_saga_handler_that_returns_another_saga.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_310_saga_handler_that_returns_another_saga.cs @@ -20,6 +20,7 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_581_complex_dependency_graph_transactional_middleware_application.cs b/src/Persistence/MartenTests/Bugs/Bug_581_complex_dependency_graph_transactional_middleware_application.cs index b2c8ccf3c..8fc979deb 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_581_complex_dependency_graph_transactional_middleware_application.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_581_complex_dependency_graph_transactional_middleware_application.cs @@ -31,6 +31,10 @@ public async Task apply_transactional_middleware_when_session_is_used_internally using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(CreateUserHandler)) + .IncludeType(typeof(CreateUser2Handler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); diff --git a/src/Persistence/MartenTests/Bugs/Bug_756_composite_handler_on_saga.cs b/src/Persistence/MartenTests/Bugs/Bug_756_composite_handler_on_saga.cs index e5bcedeef..f8c72f6e7 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_756_composite_handler_on_saga.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_756_composite_handler_on_saga.cs @@ -16,6 +16,8 @@ public async Task compile_successfully() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery(); + opts.Durability.Mode = DurabilityMode.Solo; opts.Discovery.IncludeType(); opts.Services.AddMarten(Servers.PostgresConnectionString).IntegrateWithWolverine(); diff --git a/src/Persistence/MartenTests/Bugs/Bug_778_multiple_marten_ops_in_tuple.cs b/src/Persistence/MartenTests/Bugs/Bug_778_multiple_marten_ops_in_tuple.cs index f6bc2ee94..375f7660c 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_778_multiple_marten_ops_in_tuple.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_778_multiple_marten_ops_in_tuple.cs @@ -17,6 +17,7 @@ public async Task call_both_side_effects() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(SpawnHandler)); opts.Services.AddMarten(m => diff --git a/src/Persistence/MartenTests/Bugs/Bug_826_issue_with_paused_listener.cs b/src/Persistence/MartenTests/Bugs/Bug_826_issue_with_paused_listener.cs index 837a60786..39aa89885 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_826_issue_with_paused_listener.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_826_issue_with_paused_listener.cs @@ -32,6 +32,7 @@ public async Task can_resume_listening() builder.UseWolverine(options => { + options.Discovery.DisableConventionalDiscovery().IncludeType(typeof(UnreliableHandler)); options.LocalQueueFor().Sequential(); options.OnException() .Requeue().AndPauseProcessing(5.Seconds()); diff --git a/src/Persistence/MartenTests/Bugs/Bug_971_replay_dead_letter_queue_of_event_wrapper.cs b/src/Persistence/MartenTests/Bugs/Bug_971_replay_dead_letter_queue_of_event_wrapper.cs index bb23b7f9d..8126890d4 100644 --- a/src/Persistence/MartenTests/Bugs/Bug_971_replay_dead_letter_queue_of_event_wrapper.cs +++ b/src/Persistence/MartenTests/Bugs/Bug_971_replay_dead_letter_queue_of_event_wrapper.cs @@ -25,6 +25,7 @@ public async Task can_replay_dead_letter_event() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(ErrorCausingEventHandler)); opts.ApplicationAssembly = GetType().Assembly; opts.Durability.Mode = DurabilityMode.Solo; opts.Durability.ScheduledJobPollingTime = 250.Milliseconds(); diff --git a/src/Persistence/MartenTests/Bugs/bug_369_reply_to_local_message_tries_to_be_Outgoing.cs b/src/Persistence/MartenTests/Bugs/bug_369_reply_to_local_message_tries_to_be_Outgoing.cs index 41365766e..e84e79046 100644 --- a/src/Persistence/MartenTests/Bugs/bug_369_reply_to_local_message_tries_to_be_Outgoing.cs +++ b/src/Persistence/MartenTests/Bugs/bug_369_reply_to_local_message_tries_to_be_Outgoing.cs @@ -17,6 +17,10 @@ public async Task why_are_we_going_as_outgoing() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(PingHandler)) + .IncludeType(typeof(PongHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); diff --git a/src/Persistence/MartenTests/Bugs/event_forwarding_bug.cs b/src/Persistence/MartenTests/Bugs/event_forwarding_bug.cs index 69dc75b0b..dcdd76d5d 100644 --- a/src/Persistence/MartenTests/Bugs/event_forwarding_bug.cs +++ b/src/Persistence/MartenTests/Bugs/event_forwarding_bug.cs @@ -20,6 +20,10 @@ public async Task publish_ievent_of_t() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(AddShoppingListItemHandler)) + .IncludeType(typeof(CreateShoppingListHandler)) + .IncludeType(typeof(IntegrationHandler)); opts.Policies.AutoApplyTransactions(); opts.Durability.Mode = DurabilityMode.Solo; diff --git a/src/Persistence/MartenTests/Bugs/event_forwarding_routing_bug.cs b/src/Persistence/MartenTests/Bugs/event_forwarding_routing_bug.cs index 5d83ad75c..80ebccd93 100644 --- a/src/Persistence/MartenTests/Bugs/event_forwarding_routing_bug.cs +++ b/src/Persistence/MartenTests/Bugs/event_forwarding_routing_bug.cs @@ -21,6 +21,8 @@ public async Task forwarded_events_respects_routing_rules() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(SomeEventHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.PublishAllMessages().ToLocalQueue("forwarded-events"); opts.Services.AddMarten(m => { @@ -46,6 +48,8 @@ public async Task subscription_events_respects_routing_rules() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(SomeEventHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.PublishAllMessages().ToLocalQueue("forwarded-events"); opts.Services.AddMarten(m => { diff --git a/src/Persistence/MartenTests/Bugs/report_critical_error_pauses_subscription.cs b/src/Persistence/MartenTests/Bugs/report_critical_error_pauses_subscription.cs index 5c3b43417..96b019efa 100644 --- a/src/Persistence/MartenTests/Bugs/report_critical_error_pauses_subscription.cs +++ b/src/Persistence/MartenTests/Bugs/report_critical_error_pauses_subscription.cs @@ -19,6 +19,8 @@ public async Task try_it_out() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(S3Handler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); diff --git a/src/Persistence/MartenTests/Dcb/boundary_model_workflow_tests.cs b/src/Persistence/MartenTests/Dcb/boundary_model_workflow_tests.cs index e7ac8f762..e0a1d9ac6 100644 --- a/src/Persistence/MartenTests/Dcb/boundary_model_workflow_tests.cs +++ b/src/Persistence/MartenTests/Dcb/boundary_model_workflow_tests.cs @@ -4,6 +4,7 @@ using JasperFx.Resources; using Marten; using Marten.Events; +using MartenTests.AncillaryStores; using MartenTests.Dcb.University; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -66,8 +67,11 @@ public async Task InitializeAsync() m.DisableNpgsqlLogging = true; }) .UseLightweightSessions() - .IntegrateWithWolverine(); - + .IntegrateWithWolverine(); + + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(BoundaryModelSubscribeStudentHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); diff --git a/src/Persistence/MartenTests/Distribution/Support/MultiTenantContext.cs b/src/Persistence/MartenTests/Distribution/Support/MultiTenantContext.cs index 05549574a..2dbcab5ef 100644 --- a/src/Persistence/MartenTests/Distribution/Support/MultiTenantContext.cs +++ b/src/Persistence/MartenTests/Distribution/Support/MultiTenantContext.cs @@ -1,59 +1,40 @@ using IntegrationTests; -using JasperFx.CodeGeneration; using JasperFx.Core; -using JasperFx.Events.Projections; using Marten; using Marten.Storage; -using MartenTests.Distribution.TripDomain; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Npgsql; +using System.Collections.Concurrent; using Weasel.Postgresql; using Weasel.Postgresql.Migrations; using Wolverine; using Wolverine.Marten; using Wolverine.Marten.Distribution; -using Wolverine.Runtime; using Wolverine.Runtime.Agents; using Wolverine.Tracking; using Xunit.Abstractions; namespace MartenTests.Distribution.Support; -public abstract class MultiTenantContext : IAsyncLifetime +public abstract class MultiTenantContext(ITestOutputHelper output) : IAsyncLifetime { - private readonly List _hosts = new(); - private readonly ITestOutputHelper _output; - + private readonly ConcurrentBag _hosts = []; + private readonly ConcurrentBag _observers = []; + private readonly ConcurrentDictionary _tenantConnectionStrings = []; private DocumentStore _tenancyStore = null!; - protected MasterTableTenancy tenancy = null!; - protected string tenant1ConnectionString = null!; - protected string tenant2ConnectionString = null!; - protected string tenant3ConnectionString = null!; - protected string tenant4ConnectionString = null!; + protected MasterTableTenancy _tenancy = null!; protected IHost theOriginalHost = null!; - internal EventSubscriptionAgentFamily theDistributor = null!; - - protected MultiTenantContext(ITestOutputHelper output) - { - _output = output; - } public async Task InitializeAsync() { - await using var conn = new NpgsqlConnection(Servers.PostgresConnectionString); - await conn.OpenAsync(); - - await conn.DropSchemaAsync("tenants"); - - - tenant1ConnectionString = await CreateDatabaseIfNotExists(conn, "tenant1"); - tenant2ConnectionString = await CreateDatabaseIfNotExists(conn, "tenant2"); - tenant3ConnectionString = await CreateDatabaseIfNotExists(conn, "tenant3"); - tenant4ConnectionString = await CreateDatabaseIfNotExists(conn, "tenant4"); - - await dropSchema(); + await DropSchemasAsync("tenants", "multiple", "csp"); + await Task.WhenAll([ + CreateDatabaseIfNotExists("tenant1"), + CreateDatabaseIfNotExists("tenant2"), + CreateDatabaseIfNotExists("tenant3"), + ]); _tenancyStore = DocumentStore.For(opts => { @@ -62,41 +43,40 @@ public async Task InitializeAsync() }); await _tenancyStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync(); - tenancy = (MasterTableTenancy)_tenancyStore.Options.Tenancy; - await tenancy.ClearAllDatabaseRecordsAsync(); + _tenancy = (MasterTableTenancy)_tenancyStore.Options.Tenancy; + await _tenancy.ClearAllDatabaseRecordsAsync(); theOriginalHost = await startHostAsync(); - - theDistributor = theOriginalHost.Services.GetServices().OfType().Single(); } public async Task DisposeAsync() { + _observers.Each(x => x.Dispose()); await _tenancyStore.DisposeAsync(); - _hosts.Reverse(); - foreach (var host in _hosts.ToArray()) await shutdownHostAsync(host); + await Task.WhenAll(_hosts.Select(ShutdownHostAsync)); + _hosts.Clear(); } - private async Task CreateDatabaseIfNotExists(NpgsqlConnection conn, string databaseName) + private async Task CreateDatabaseIfNotExists(string databaseName) { + using var conn = new NpgsqlConnection(Servers.PostgresConnectionString); var builder = new NpgsqlConnectionStringBuilder(Servers.PostgresConnectionString); - + await conn.OpenAsync(); var exists = await conn.DatabaseExists(databaseName); if (!exists) - { await new DatabaseSpecification().BuildDatabase(conn, databaseName); - } builder.Database = databaseName; - return builder.ConnectionString; + _tenantConnectionStrings.TryAdd(databaseName, builder.ConnectionString); } - private static async Task dropSchema() + private static async Task DropSchemasAsync(params string[] names) { using var conn = new NpgsqlConnection(Servers.PostgresConnectionString); await conn.OpenAsync(); - await conn.DropSchemaAsync("csp"); + foreach (var name in names) + await conn.DropSchemaAsync(name); await conn.CloseAsync(); } @@ -123,14 +103,11 @@ protected async Task startHostAsync() m.MainDatabaseConnectionString = Servers.PostgresConnectionString; m.UseWolverineManagedEventSubscriptionDistribution = true; }); - - opts.Services.AddSingleton(new OutputLoggerProvider(_output)); - - opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto; + opts.Discovery.DisableConventionalDiscovery(); + opts.Services.AddSingleton(new OutputLoggerProvider(output)); }).StartAsync(); - new XUnitEventObserver(host, _output); - + _observers.Add(new XUnitEventObserver(host, output)); _hosts.Add(host); return host; @@ -138,51 +115,25 @@ protected async Task startHostAsync() protected abstract void SetupProjections(StoreOptions storeOptions); - protected async Task startGreenHostAsync() - { - var host = await Host.CreateDefaultBuilder() - .UseWolverine(opts => - { - opts.Services.AddMarten(m => - { - m.DisableNpgsqlLogging = true; - - m.MultiTenantedDatabasesWithMasterDatabaseTable(Servers.PostgresConnectionString, "tenants"); - m.DatabaseSchemaName = "csp"; - - m.Projections.Add(ProjectionLifecycle.Async); - m.Projections.Add(ProjectionLifecycle.Async); - m.Projections.Add(ProjectionLifecycle.Async); - m.Projections.Add(ProjectionLifecycle.Async); - m.Projections.Add(ProjectionLifecycle.Async); - }) - .IntegrateWithWolverine(m => m.MainDatabaseConnectionString = Servers.PostgresConnectionString); - - // TODO --derive this from Marten Tenancy - - opts.Services.AddSingleton(new OutputLoggerProvider(_output)); - - opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto; - }).StartAsync(); - - new XUnitEventObserver(host, _output); - - _hosts.Add(host); - - return host; - } - - private async Task shutdownHostAsync(IHost host) + private async Task ShutdownHostAsync(IHost host) { host.GetRuntime().Agents.DisableHealthChecks(); await host.StopAsync(); host.Dispose(); - _hosts.Remove(host); } - protected Uri[] runningSubscriptions(IHost host) + protected static async Task GetAgentUrisAsync(IHost host) + { + var agentsFamily = host.Services.GetServices() + .OfType().Single(); + var agents = await agentsFamily.AllKnownAgentsAsync(); + return [.. agents.Select(x => x.AbsoluteUri)]; + } + + protected async Task AddTenantsAsync(params string[] tenants) { - var runtime = host.Services.GetRequiredService(); - return runtime.Agents.AllRunningAgentUris().Where(x => x.Scheme == EventSubscriptionAgentFamily.SchemeName).ToArray(); + var records = tenants.Select(x => + _tenancy.AddDatabaseRecordAsync(x, _tenantConnectionStrings[x])); + await Task.WhenAll(records); } } \ No newline at end of file diff --git a/src/Persistence/MartenTests/Distribution/Support/SingleTenantContext.cs b/src/Persistence/MartenTests/Distribution/Support/SingleTenantContext.cs index 5fcc4d604..a2c0f41db 100644 --- a/src/Persistence/MartenTests/Distribution/Support/SingleTenantContext.cs +++ b/src/Persistence/MartenTests/Distribution/Support/SingleTenantContext.cs @@ -3,15 +3,13 @@ using JasperFx.Core; using JasperFx.Events.Projections; using Marten; -using Marten.Events.Projections; using MartenTests.Distribution.TripDomain; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Npgsql; -using Weasel.Core; +using System.Collections.Concurrent; using Weasel.Postgresql; -using Weasel.Postgresql.Tables; using Wolverine; using Wolverine.Marten; using Wolverine.Marten.Distribution; @@ -22,40 +20,31 @@ namespace MartenTests.Distribution.Support; -public abstract class SingleTenantContext : IAsyncLifetime +public abstract class SingleTenantContext(ITestOutputHelper output) : IAsyncLifetime { - private readonly List _hosts = new(); - private readonly ITestOutputHelper _output; + private readonly ConcurrentBag _hosts = []; + private readonly ConcurrentBag _observers = []; protected IHost theOriginalHost = null!; - internal EventSubscriptionAgentFamily theProjectionAgents = null!; - - public SingleTenantContext(ITestOutputHelper output) - { - _output = output; - } public async Task InitializeAsync() { - await dropSchema(); + await DropSchemasAsync("csp"); theOriginalHost = await startHostAsync(); } public async Task DisposeAsync() { - _hosts.Reverse(); - foreach (var host in _hosts.ToArray()) - { - await shutdownHostAsync(host); - } + _observers.Each(x => x.Dispose()); + await Task.WhenAll(_hosts.Select(ShutdownHostAsync)); + _hosts.Clear(); } - private async Task shutdownHostAsync(IHost host) + private async Task ShutdownHostAsync(IHost host) { host.GetRuntime().Agents.DisableHealthChecks(); await host.StopAsync(); host.Dispose(); - _hosts.Remove(host); } protected async Task startHostAsync() @@ -89,17 +78,14 @@ protected async Task startHostAsync() #endregion - opts.Services.AddSingleton(new OutputLoggerProvider(_output)); - + opts.Services.AddSingleton(new OutputLoggerProvider(output)); + opts.Discovery.DisableConventionalDiscovery(); opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto; }).StartAsync(); - new XUnitEventObserver(host, _output); - + _observers.Add(new XUnitEventObserver(host, output)); _hosts.Add(host); - theProjectionAgents ??= host.Services.GetServices().OfType().Single(); - return host; } @@ -123,29 +109,31 @@ protected async Task startGreenHostAsync() }) .IntegrateWithWolverine(m => m.UseWolverineManagedEventSubscriptionDistribution = true); - opts.Services.AddSingleton(new OutputLoggerProvider(_output)); + opts.Services.AddSingleton(new OutputLoggerProvider(output)); opts.UseMessagePackSerialization(); - - opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto; }).StartAsync(); - new XUnitEventObserver(host, _output); - + _observers.Add(new XUnitEventObserver(host, output)); _hosts.Add(host); - theProjectionAgents ??= host.Services.GetServices().OfType().Single(); - return host; } - private static async Task dropSchema() + private static async Task DropSchemasAsync(params string[] names) { using var conn = new NpgsqlConnection(Servers.PostgresConnectionString); await conn.OpenAsync(); - await new Table(new DbObjectName("csp", "wolverine_node_records")).DropAsync(conn); - await new Table(new DbObjectName("csp", "wolverine_nodes")).DropAsync(conn); - await new Table(new DbObjectName("csp", "wolverine_node_assignments")).DropAsync(conn); + foreach (var name in names) + await conn.DropSchemaAsync(name); await conn.CloseAsync(); } + + protected static async Task GetAgentUrisAsync(IHost host) + { + var agentsFamily = host.Services.GetServices() + .OfType().Single(); + var agents = await agentsFamily.AllKnownAgentsAsync(); + return [.. agents.Select(x => x.AbsoluteUri)]; + } } \ No newline at end of file diff --git a/src/Persistence/MartenTests/Distribution/Support/XUnitEventObserver.cs b/src/Persistence/MartenTests/Distribution/Support/XUnitEventObserver.cs index 0ba6ea5ec..44b4fda43 100644 --- a/src/Persistence/MartenTests/Distribution/Support/XUnitEventObserver.cs +++ b/src/Persistence/MartenTests/Distribution/Support/XUnitEventObserver.cs @@ -8,11 +8,12 @@ namespace MartenTests.Distribution.Support; -public class XUnitEventObserver : IObserver +public class XUnitEventObserver : IObserver, IDisposable { private readonly ITestOutputHelper _output; - private readonly int _assignedId; - + private readonly int _assignedId; + private readonly IDisposable _subsriber; + public XUnitEventObserver(IHost host, ITestOutputHelper output) { _output = output; @@ -20,9 +21,15 @@ public XUnitEventObserver(IHost host, ITestOutputHelper output) _assignedId = runtime.Options.Durability.AssignedNodeNumber; - runtime.Tracker.Subscribe(this); - } - + _subsriber = runtime.Tracker.Subscribe(this); + } + + public void Dispose() + { + _subsriber?.Dispose(); + GC.SuppressFinalize(this); + } + public void OnCompleted() { diff --git a/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_multiple_tenants.cs b/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_multiple_tenants.cs index 778e32861..8c17b22e7 100644 --- a/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_multiple_tenants.cs +++ b/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_multiple_tenants.cs @@ -3,62 +3,71 @@ using Marten; using MartenTests.Distribution.Support; using MartenTests.Distribution.TripDomain; +using Microsoft.Extensions.Hosting; +using Shouldly; using Wolverine; +using Wolverine.Marten.Distribution; using Xunit.Abstractions; namespace MartenTests.Distribution; -public class basic_agent_mechanics_multiple_tenants(ITestOutputHelper output) : MultiTenantContext(output) +public class basic_agent_mechanics_multiple_tenants(ITestOutputHelper output) + : MultiTenantContext(output) { [Fact] public async Task start_with_multiple_databases_on_one_single_node() { - await tenancy.AddDatabaseRecordAsync("tenant1", tenant1ConnectionString); - await tenancy.AddDatabaseRecordAsync("tenant2", tenant2ConnectionString); + string[] tenants = ["tenant1", "tenant2"]; + await AddTenantsAsync(tenants); await theOriginalHost.WaitUntilAssignmentsChangeTo(w => { - w.AgentScheme = theDistributor.Scheme; - + w.AgentScheme = EventSubscriptionAgentFamily.SchemeName; // 3 projections x 2 databases = 6 total w.ExpectRunningAgents(theOriginalHost, 6); }, 60.Seconds()); + await AssertAgentsUrisAsync(theOriginalHost, tenants); } - + [Fact] public async Task spread_databases_out_via_host() { - await tenancy.AddDatabaseRecordAsync("tenant1", tenant1ConnectionString); - await tenancy.AddDatabaseRecordAsync("tenant2", tenant2ConnectionString); - await tenancy.AddDatabaseRecordAsync("tenant3", tenant3ConnectionString); - await tenancy.AddDatabaseRecordAsync("tenant4", tenant4ConnectionString); - + string[] tenants = ["tenant1", "tenant2", "tenant3"]; + await AddTenantsAsync(tenants); + await theOriginalHost.WaitUntilAssignmentsChangeTo(w => { - w.AgentScheme = theDistributor.Scheme; - - // 3 projections x 2 databases = 6 total - w.ExpectRunningAgents(theOriginalHost, 12); + w.AgentScheme = EventSubscriptionAgentFamily.SchemeName; + // 3 projections x 3 databases = 9 total + w.ExpectRunningAgents(theOriginalHost, 9); }, 60.Seconds()); + await AssertAgentsUrisAsync(theOriginalHost, tenants); - var host2 = await startHostAsync(); - - - var host3 = await startHostAsync(); - var host4 = await startHostAsync(); - + var extraHosts = await Task.WhenAll([startHostAsync(), startHostAsync()]); await theOriginalHost.WaitUntilAssignmentsChangeTo(w => { - w.AgentScheme = theDistributor.Scheme; - - // 3 projections x 2 databases = 6 total + w.AgentScheme = EventSubscriptionAgentFamily.SchemeName; + // 3 projections x 3 databases = 9 total w.ExpectRunningAgents(theOriginalHost, 3); - w.ExpectRunningAgents(host2, 3); - w.ExpectRunningAgents(host3, 3); - w.ExpectRunningAgents(host4, 3); + w.ExpectRunningAgents(extraHosts[0], 3); + w.ExpectRunningAgents(extraHosts[1], 3); }, 60.Seconds()); + await AssertAgentsUrisAsync(theOriginalHost, tenants); + await AssertAgentsUrisAsync(extraHosts[0], tenants); + await AssertAgentsUrisAsync(extraHosts[1], tenants); } + private static async Task AssertAgentsUrisAsync(IHost host, params string[] tenants) + { + var uris = await GetAgentUrisAsync(host); + var expectedUris = tenants.SelectMany(tenant => new[] + { + $"event-subscriptions://marten/main/localhost.{tenant}/trip/all", + $"event-subscriptions://marten/main/localhost.{tenant}/day/all", + $"event-subscriptions://marten/main/localhost.{tenant}/distance/all" + }); + uris.ShouldBe(expectedUris, ignoreOrder: true); + } protected override void SetupProjections(StoreOptions storeOptions) { diff --git a/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_single_tenant.cs b/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_single_tenant.cs index 59dbb5417..5b2f599aa 100644 --- a/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_single_tenant.cs +++ b/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_single_tenant.cs @@ -1,6 +1,7 @@ using JasperFx.Core; using Marten; using MartenTests.Distribution.Support; +using Microsoft.Extensions.Hosting; using Shouldly; using Wolverine; using Wolverine.Marten.Distribution; @@ -8,12 +9,9 @@ namespace MartenTests.Distribution; -public class basic_agent_mechanics_single_tenant : SingleTenantContext +public class basic_agent_mechanics_single_tenant(ITestOutputHelper output) + : SingleTenantContext(output) { - public basic_agent_mechanics_single_tenant(ITestOutputHelper output) : base(output) - { - } - [Fact] public async Task can_do_the_full_marten_reset_all_data_call() { @@ -21,22 +19,6 @@ public async Task can_do_the_full_marten_reset_all_data_call() await theOriginalHost.ResetAllMartenDataAsync(); } - [Fact] - public async Task find_all_known_agents() - { - var uris = await theProjectionAgents.AllKnownAgentsAsync(); - - uris.Count.ShouldBe(3); - - uris.OrderBy(x => x.ToString()).ShouldBe([ - new Uri("event-subscriptions://marten/main/localhost.postgres/day/all"), - new Uri("event-subscriptions://marten/main/localhost.postgres/distance/all"), - new Uri("event-subscriptions://marten/main/localhost.postgres/trip/all"), - - ]); - - } - [Fact] public async Task everything_is_started_up_on_one_node() { @@ -47,6 +29,7 @@ await theOriginalHost.WaitUntilAssignmentsChangeTo(w => w.AgentScheme = EventSubscriptionAgentFamily.SchemeName; w.ExpectRunningAgents(theOriginalHost, 3); }, 30.Seconds()); + await AssertAgentUrisAsync(theOriginalHost); } [Fact] @@ -54,16 +37,27 @@ public async Task spread_out_over_multiple_hosts() { await theOriginalHost.WaitUntilAssumesLeadershipAsync(5.Seconds()); - var host2 = await startHostAsync(); - var host3 = await startHostAsync(); - + var hosts = await Task.WhenAll([startHostAsync(), startHostAsync()]); // Now, let's check that the load is redistributed! await theOriginalHost.WaitUntilAssignmentsChangeTo(w => { w.AgentScheme = EventSubscriptionAgentFamily.SchemeName; w.ExpectRunningAgents(theOriginalHost, 1); - w.ExpectRunningAgents(host2, 1); - w.ExpectRunningAgents(host3, 1); + w.ExpectRunningAgents(hosts[0], 1); + w.ExpectRunningAgents(hosts[1], 1); }, 30.Seconds()); + await AssertAgentUrisAsync(theOriginalHost); + await AssertAgentUrisAsync(hosts[0]); + await AssertAgentUrisAsync(hosts[1]); + } + + private async static Task AssertAgentUrisAsync(IHost host) + { + var uris = await GetAgentUrisAsync(host); + uris.ShouldBe([ + "event-subscriptions://marten/main/localhost.postgres/day/all", + "event-subscriptions://marten/main/localhost.postgres/distance/all", + "event-subscriptions://marten/main/localhost.postgres/trip/all", + ], ignoreOrder: true); } } \ No newline at end of file diff --git a/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_versioned_composition.cs b/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_versioned_composition.cs index b44d9000f..41d382892 100644 --- a/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_versioned_composition.cs +++ b/src/Persistence/MartenTests/Distribution/basic_agent_mechanics_versioned_composition.cs @@ -1,65 +1,68 @@ using JasperFx.Core; -using JasperFx.Events.Projections; using Marten; using MartenTests.Distribution.Support; using MartenTests.Distribution.TripDomain; +using Microsoft.Extensions.Hosting; +using Shouldly; using Wolverine; +using Wolverine.Marten.Distribution; using Xunit.Abstractions; namespace MartenTests.Distribution; -[Trait("Category", "Flaky")] -public class basic_agent_mechanics_versioned_composition(ITestOutputHelper output) : MultiTenantContext(output) +public class basic_agent_mechanics_versioned_composition(ITestOutputHelper output) + : MultiTenantContext(output) { [Fact] public async Task start_with_multiple_databases_on_one_single_node() { - await tenancy.AddDatabaseRecordAsync("tenant1", tenant1ConnectionString); - await tenancy.AddDatabaseRecordAsync("tenant2", tenant2ConnectionString); + string[] tenants = ["tenant1", "tenant2"]; + await AddTenantsAsync(tenants); await theOriginalHost.WaitUntilAssignmentsChangeTo(w => { - w.AgentScheme = theDistributor.Scheme; - - // 3 projections x 2 databases = 6 total - w.ExpectRunningAgents(theOriginalHost, 6); + w.AgentScheme = EventSubscriptionAgentFamily.SchemeName; + // 1 composite projection x 2 databases = 2 total + w.ExpectRunningAgents(theOriginalHost, 2); }, 30.Seconds()); + await AssertAgentsUrisAsync(theOriginalHost, tenants); } - + [Fact] public async Task spread_databases_out_via_host() { - await tenancy.AddDatabaseRecordAsync("tenant1", tenant1ConnectionString); - await tenancy.AddDatabaseRecordAsync("tenant2", tenant2ConnectionString); - await tenancy.AddDatabaseRecordAsync("tenant3", tenant3ConnectionString); - await tenancy.AddDatabaseRecordAsync("tenant4", tenant4ConnectionString); - + string[] tenants = ["tenant1", "tenant2", "tenant3"]; + await AddTenantsAsync(tenants); + await theOriginalHost.WaitUntilAssignmentsChangeTo(w => { - w.AgentScheme = theDistributor.Scheme; - - // 3 projections x 2 databases = 6 total - w.ExpectRunningAgents(theOriginalHost, 12); + w.AgentScheme = EventSubscriptionAgentFamily.SchemeName; + // 1 composite projection x 3 databases = 3 total + w.ExpectRunningAgents(theOriginalHost, 3); }, 30.Seconds()); + await AssertAgentsUrisAsync(theOriginalHost, tenants); - var host2 = await startHostAsync(); - - - var host3 = await startHostAsync(); - var host4 = await startHostAsync(); - + var extraHosts = await Task.WhenAll([startHostAsync(), startHostAsync()]); await theOriginalHost.WaitUntilAssignmentsChangeTo(w => { - w.AgentScheme = theDistributor.Scheme; - - // 3 projections x 2 databases = 6 total - w.ExpectRunningAgents(theOriginalHost, 3); - w.ExpectRunningAgents(host2, 3); - w.ExpectRunningAgents(host3, 3); - w.ExpectRunningAgents(host4, 3); + w.AgentScheme = EventSubscriptionAgentFamily.SchemeName; + // 1 composite projection x 3 databases = 3 total + w.ExpectRunningAgents(theOriginalHost, 1); + w.ExpectRunningAgents(extraHosts[0], 1); + w.ExpectRunningAgents(extraHosts[1], 1); }, 30.Seconds()); + await AssertAgentsUrisAsync(theOriginalHost, tenants); + await AssertAgentsUrisAsync(extraHosts[0], tenants); + await AssertAgentsUrisAsync(extraHosts[1], tenants); } + private static async Task AssertAgentsUrisAsync(IHost host, params string[] tenants) + { + var uris = await GetAgentUrisAsync(host); + var expectedUris = tenants.Select(tenant => + $"event-subscriptions://marten/main/localhost.{tenant}/trips/all/v2"); + uris.ShouldBe(expectedUris, ignoreOrder: true); + } protected override void SetupProjections(StoreOptions storeOptions) { @@ -71,4 +74,4 @@ protected override void SetupProjections(StoreOptions storeOptions) x.Add(); }); } -} \ No newline at end of file +} diff --git a/src/Persistence/MartenTests/Distribution/blue_green_deployment_with_single_tenant.cs b/src/Persistence/MartenTests/Distribution/blue_green_deployment_with_single_tenant.cs index 0b241c6e8..c8ca05081 100644 --- a/src/Persistence/MartenTests/Distribution/blue_green_deployment_with_single_tenant.cs +++ b/src/Persistence/MartenTests/Distribution/blue_green_deployment_with_single_tenant.cs @@ -1,17 +1,15 @@ using JasperFx.Core; using MartenTests.Distribution.Support; +using Shouldly; using Wolverine; using Wolverine.Marten.Distribution; using Xunit.Abstractions; namespace MartenTests.Distribution; -public class blue_green_deployment_with_single_tenant : SingleTenantContext +public class blue_green_deployment_with_single_tenant(ITestOutputHelper output) + : SingleTenantContext(output) { - public blue_green_deployment_with_single_tenant(ITestOutputHelper output) : base(output) - { - } - [Fact] public async Task spin_up_single_blue_and_single_green_host() { @@ -23,7 +21,20 @@ await theOriginalHost.WaitUntilAssignmentsChangeTo(w => w.ExpectRunningAgents(theOriginalHost, 3); w.ExpectRunningAgents(greenHost, 3); }, 30.Seconds()); - - // TODO -- tighten the assertions here! + + var originalUris = await GetAgentUrisAsync(theOriginalHost); + originalUris.ShouldBe([ + "event-subscriptions://marten/main/localhost.postgres/day/all", + "event-subscriptions://marten/main/localhost.postgres/distance/all", + "event-subscriptions://marten/main/localhost.postgres/trip/all" + ], ignoreOrder: true); + var greenUris = await GetAgentUrisAsync(greenHost); + greenUris.ShouldBe([ + "event-subscriptions://marten/main/localhost.postgres/day/all", + "event-subscriptions://marten/main/localhost.postgres/distance/all", + "event-subscriptions://marten/main/localhost.postgres/ending/all", + "event-subscriptions://marten/main/localhost.postgres/starting/all", + "event-subscriptions://marten/main/localhost.postgres/trip/all/v2" + ], ignoreOrder: true); } } \ No newline at end of file diff --git a/src/Persistence/MartenTests/Distribution/event_subscription_agent_rebuild.cs b/src/Persistence/MartenTests/Distribution/event_subscription_agent_rebuild.cs index 52834022c..81ca5ab18 100644 --- a/src/Persistence/MartenTests/Distribution/event_subscription_agent_rebuild.cs +++ b/src/Persistence/MartenTests/Distribution/event_subscription_agent_rebuild.cs @@ -1,7 +1,6 @@ using JasperFx.Events.Daemon; using JasperFx.Events.Projections; using NSubstitute; -using Shouldly; using Wolverine.Marten.Distribution; namespace MartenTests.Distribution; diff --git a/src/Persistence/MartenTests/Distribution/with_ancillary_stores.cs b/src/Persistence/MartenTests/Distribution/with_ancillary_stores.cs index a8800f1ea..cd0354ee8 100644 --- a/src/Persistence/MartenTests/Distribution/with_ancillary_stores.cs +++ b/src/Persistence/MartenTests/Distribution/with_ancillary_stores.cs @@ -1,5 +1,4 @@ using IntegrationTests; -using JasperFx.CodeGeneration; using JasperFx.Core; using JasperFx.Events.Projections; using Marten; @@ -11,9 +10,8 @@ using Microsoft.Extensions.Logging; using Npgsql; using Shouldly; -using Weasel.Core; +using System.Collections.Concurrent; using Weasel.Postgresql; -using Weasel.Postgresql.Tables; using Wolverine; using Wolverine.Marten; using Wolverine.Marten.Distribution; @@ -25,52 +23,37 @@ namespace MartenTests.Distribution; -public class with_ancillary_stores : IAsyncLifetime +public class with_ancillary_stores(ITestOutputHelper output) : IAsyncLifetime { - private readonly List _hosts = new(); - private readonly ITestOutputHelper _output; + private readonly ConcurrentBag _hosts = []; + private readonly ConcurrentBag _observers = []; protected IHost theOriginalHost = null!; - internal EventSubscriptionAgentFamily theProjectionAgents = null!; - public with_ancillary_stores(ITestOutputHelper output) - { - _output = output; - } - - private static async Task dropSchema() + public async Task InitializeAsync() { using var conn = new NpgsqlConnection(Servers.PostgresConnectionString); await conn.OpenAsync(); - await new Table(new DbObjectName("csp2", "wolverine_node_records")).DropAsync(conn); - await new Table(new DbObjectName("csp2", "wolverine_nodes")).DropAsync(conn); - await new Table(new DbObjectName("csp2", "wolverine_node_assignments")).DropAsync(conn); + await conn.DropSchemaAsync("csp2"); + await conn.DropSchemaAsync("csp3"); await conn.CloseAsync(); - } - - public async Task InitializeAsync() - { - await dropSchema(); theOriginalHost = await startHostAsync(); } public async Task DisposeAsync() { - _hosts.Reverse(); - foreach (var host in _hosts.ToArray()) - { - await shutdownHostAsync(host); - } + _observers.Each(x => x.Dispose()); + await Task.WhenAll(_hosts.Select(ShutdownHostAsync)); + _hosts.Clear(); } - - private async Task shutdownHostAsync(IHost host) + + private async Task ShutdownHostAsync(IHost host) { host.GetRuntime().Agents.DisableHealthChecks(); await host.StopAsync(); host.Dispose(); - _hosts.Remove(host); } - + protected async Task startHostAsync() { #region sample_using_distributed_projections_with_ancillary_stores @@ -79,11 +62,11 @@ protected async Task startHostAsync() { opts.Durability.HealthCheckPollingTime = 1.Seconds(); opts.Durability.CheckAssignmentPeriod = 1.Seconds(); - + opts.UseMessagePackSerialization(); - + opts.UseSharedMemoryQueueing(); - + opts.Services.AddMarten(m => { m.DisableNpgsqlLogging = true; @@ -101,8 +84,8 @@ protected async Task startHostAsync() // cluster m.UseWolverineManagedEventSubscriptionDistribution = true; }); - - opts.Services.AddSingleton(new OutputLoggerProvider(_output)); + + opts.Services.AddSingleton(new OutputLoggerProvider(output)); opts.Services.AddMartenStore(m => { @@ -115,17 +98,13 @@ protected async Task startHostAsync() m.Projections.Add(ProjectionLifecycle.Async); }).IntegrateWithWolverine(); - opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto; }).StartAsync(); #endregion - new XUnitEventObserver(host, _output); - + _observers.Add(new XUnitEventObserver(host, output)); _hosts.Add(host); - theProjectionAgents ??= host.Services.GetServices().OfType().Single(); - return host; } @@ -135,7 +114,7 @@ public void projection_coordinators_for_ancillary_stores_are_wolverine_versions( theOriginalHost.Services.GetRequiredService>() .ShouldBeOfType>(); } - + [Fact] public async Task can_do_the_full_marten_reset_all_data_call() { @@ -145,45 +124,43 @@ public async Task can_do_the_full_marten_reset_all_data_call() await theOriginalHost.ResetAllMartenDataAsync(); } - [Fact] - public async Task find_all_known_agents() - { - var uris = await theProjectionAgents.AllKnownAgentsAsync(); - - uris.Count.ShouldBe(6); - - uris.OrderBy(x => x.ToString()).ShouldBe([ - new Uri("event-subscriptions://marten/itripstore/localhost.postgres/day/all"), - new Uri("event-subscriptions://marten/itripstore/localhost.postgres/distance/all"), - new Uri("event-subscriptions://marten/itripstore/localhost.postgres/trip/all"), - new Uri("event-subscriptions://marten/main/localhost.postgres/day/all"), - new Uri("event-subscriptions://marten/main/localhost.postgres/distance/all"), - new Uri("event-subscriptions://marten/main/localhost.postgres/trip/all"), - - - ]); - - } - - [Fact] public async Task spread_out_over_multiple_hosts() { await theOriginalHost.WaitUntilAssumesLeadershipAsync(5.Seconds()); + await AssertAgentUrisAsync(theOriginalHost); + + var extraHosts = await Task.WhenAll([startHostAsync(), startHostAsync()]); - var host2 = await startHostAsync(); - var host3 = await startHostAsync(); - // Now, let's check that the load is redistributed! await theOriginalHost.WaitUntilAssignmentsChangeTo(w => { w.AgentScheme = EventSubscriptionAgentFamily.SchemeName; w.ExpectRunningAgents(theOriginalHost, 2); - w.ExpectRunningAgents(host2, 2); - w.ExpectRunningAgents(host3, 2); + w.ExpectRunningAgents(extraHosts[0], 2); + w.ExpectRunningAgents(extraHosts[1], 2); }, 30.Seconds()); + + await AssertAgentUrisAsync(theOriginalHost); + await AssertAgentUrisAsync(extraHosts[0]); + await AssertAgentUrisAsync(extraHosts[1]); } + private async static Task AssertAgentUrisAsync(IHost host) + { + var agentsFamily = host.Services.GetServices() + .OfType().Single(); + var agents = await agentsFamily.AllKnownAgentsAsync(); + var uris = agents.Select(x => x.AbsoluteUri); + uris.ShouldBe([ + "event-subscriptions://marten/itripstore/localhost.postgres/day/all", + "event-subscriptions://marten/itripstore/localhost.postgres/distance/all", + "event-subscriptions://marten/itripstore/localhost.postgres/trip/all", + "event-subscriptions://marten/main/localhost.postgres/day/all", + "event-subscriptions://marten/main/localhost.postgres/distance/all", + "event-subscriptions://marten/main/localhost.postgres/trip/all" + ], ignoreOrder: true); + } } public interface ITripStore : IDocumentStore; \ No newline at end of file diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Event3Handler1609469393.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Event3Handler1609469393.cs deleted file mode 100644 index 90d61d153..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Event3Handler1609469393.cs +++ /dev/null @@ -1,49 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: Event3Handler1609469393 - public class Event3Handler1609469393 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public Event3Handler1609469393(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var event3 = (Event3)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = event3.AggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - var outgoing1 = FooHandler.Handle(event3, eventStream.Aggregate); - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing1).ConfigureAwait(false); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: Event3Handler1609469393 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Event3Handler1940643383.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Event3Handler1940643383.cs deleted file mode 100644 index 79e0ca051..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Event3Handler1940643383.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: Event3Handler1940643383 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class Event3Handler1940643383 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public Event3Handler1940643383(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var event3 = (MartenTests.AggregateHandlerWorkflow.Event3)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.FooHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = event3.AggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - var outgoing1 = MartenTests.AggregateHandlerWorkflow.FooHandler.Handle(event3, eventStream.Aggregate); - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing1).ConfigureAwait(false); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: Event3Handler1940643383 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementA2Handler79726078.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementA2Handler79726078.cs deleted file mode 100644 index e2ffcae04..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementA2Handler79726078.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -#pragma warning disable -using Microsoft.Extensions.Logging; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementA2Handler79726078 - public class IncrementA2Handler79726078 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - private readonly Microsoft.Extensions.Logging.ILogger _logger; - - public IncrementA2Handler79726078(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory, Microsoft.Extensions.Logging.ILogger logger) - { - _outboxedSessionFactory = outboxedSessionFactory; - _logger = logger; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementA2 = (MartenTests.IncrementA2)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementA2.SelfLetteredAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - if (eventStream.Aggregate == null) throw new Wolverine.Marten.UnknownAggregateException(typeof(MartenTests.SelfLetteredAggregate), incrementA2.SelfLetteredAggregateId); - var selfLetteredAggregate = new MartenTests.SelfLetteredAggregate(); - - // The actual message execution - var outgoing1 = eventStream.Aggregate.Handle(incrementA2, _logger); - - eventStream.AppendOne(outgoing1); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementA2Handler79726078 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementABHandler294362820.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementABHandler294362820.cs deleted file mode 100644 index f0f32cafb..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementABHandler294362820.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementABHandler294362820 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class IncrementABHandler294362820 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementABHandler294362820(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementAB = (MartenTests.AggregateHandlerWorkflow.IncrementAB)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.SpecialLetterHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = incrementAB.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForExclusiveWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - var outgoing1 = MartenTests.AggregateHandlerWorkflow.SpecialLetterHandler.Handle(incrementAB, eventStream.Aggregate); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementABHandler294362820 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementABHandler79726094.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementABHandler79726094.cs deleted file mode 100644 index d8e5c2829..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementABHandler79726094.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementABHandler79726094 - public class IncrementABHandler79726094 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementABHandler79726094(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementAB = (IncrementAB)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementAB.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForExclusiveWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - var outgoing1 = SpecialLetterHandler.Handle(incrementAB, eventStream.Aggregate); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementABHandler79726094 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementAHandler1658474384.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementAHandler1658474384.cs deleted file mode 100644 index 92aa8accf..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementAHandler1658474384.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementAHandler1658474384 - public class IncrementAHandler1658474384 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementAHandler1658474384(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementA = (IncrementA)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementA.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new LetterAggregateHandler(); - - // The actual message execution - var outgoing1 = letterAggregateHandler.Handle(incrementA, eventStream.Aggregate, documentSession); - - eventStream.AppendOne(outgoing1); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementAHandler1658474384 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementAHandler17491962.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementAHandler17491962.cs deleted file mode 100644 index ac1843b4d..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementAHandler17491962.cs +++ /dev/null @@ -1,48 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementAHandler17491962 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class IncrementAHandler17491962 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementAHandler17491962(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementA = (MartenTests.AggregateHandlerWorkflow.IncrementA)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = incrementA.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler(); - - // The actual message execution - var outgoing1 = letterAggregateHandler.Handle(incrementA, eventStream.Aggregate, documentSession); - - eventStream.AppendOne(outgoing1); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementAHandler17491962 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementB2Handler483010605.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementB2Handler483010605.cs deleted file mode 100644 index 275277997..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementB2Handler483010605.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementB2Handler483010605 - public class IncrementB2Handler483010605 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementB2Handler483010605(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementB2 = (MartenTests.IncrementB2)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementB2.SelfLetteredAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - if (eventStream.Aggregate == null) throw new Wolverine.Marten.UnknownAggregateException(typeof(MartenTests.SelfLetteredAggregate), incrementB2.SelfLetteredAggregateId); - var selfLetteredAggregate = new MartenTests.SelfLetteredAggregate(); - - // The actual message execution - var outgoing1 = await eventStream.Aggregate.Handle(incrementB2).ConfigureAwait(false); - - eventStream.AppendOne(outgoing1); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementB2Handler483010605 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBCHandler1271721124.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBCHandler1271721124.cs deleted file mode 100644 index c7f0e141e..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBCHandler1271721124.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementBCHandler1271721124 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class IncrementBCHandler1271721124 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementBCHandler1271721124(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementBC = (MartenTests.AggregateHandlerWorkflow.IncrementBC)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = incrementBC.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, incrementBC.Version, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler(); - - // The actual message execution - var outgoing1 = letterAggregateHandler.Handle(incrementBC, eventStream.Aggregate); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementBCHandler1271721124 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBCHandler483010622.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBCHandler483010622.cs deleted file mode 100644 index 06785bc8e..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBCHandler483010622.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementBCHandler483010622 - public class IncrementBCHandler483010622 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementBCHandler483010622(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementBC = (IncrementBC)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementBC.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, incrementBC.Version, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new LetterAggregateHandler(); - - // The actual message execution - var outgoing1 = letterAggregateHandler.Handle(incrementBC, eventStream.Aggregate); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementBCHandler483010622 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBHandler1255189857.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBHandler1255189857.cs deleted file mode 100644 index 1533d8d9c..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBHandler1255189857.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Microsoft.Extensions.Logging; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementBHandler1255189857 - public class IncrementBHandler1255189857 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - private readonly Microsoft.Extensions.Logging.ILogger _logger; - - public IncrementBHandler1255189857(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory, Microsoft.Extensions.Logging.ILogger logger) - { - _outboxedSessionFactory = outboxedSessionFactory; - _logger = logger; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementB = (IncrementB)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementB.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new LetterAggregateHandler(); - - // The actual message execution - var outgoing1 = await letterAggregateHandler.Handle(incrementB, eventStream.Aggregate, _logger).ConfigureAwait(false); - - eventStream.AppendOne(outgoing1); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementBHandler1255189857 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBHandler17491959.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBHandler17491959.cs deleted file mode 100644 index 86e60a5eb..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementBHandler17491959.cs +++ /dev/null @@ -1,51 +0,0 @@ -// -#pragma warning disable -using Microsoft.Extensions.Logging; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementBHandler17491959 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class IncrementBHandler17491959 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Microsoft.Extensions.Logging.ILogger _logger; - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementBHandler17491959(Microsoft.Extensions.Logging.ILogger logger, Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _logger = logger; - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementB = (MartenTests.AggregateHandlerWorkflow.IncrementB)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = incrementB.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler(); - - // The actual message execution - var outgoing1 = await letterAggregateHandler.Handle(incrementB, eventStream.Aggregate, _logger).ConfigureAwait(false); - - eventStream.AppendOne(outgoing1); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementBHandler17491959 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCDHandler1083073314.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCDHandler1083073314.cs deleted file mode 100644 index be29ff00b..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCDHandler1083073314.cs +++ /dev/null @@ -1,48 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementCDHandler1083073314 - public class IncrementCDHandler1083073314 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementCDHandler1083073314(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementCD = (IncrementCD)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementCD.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, incrementCD.Version, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new LetterAggregateHandler(); - - // The actual message execution - (var outgoing1, var outgoing2) = letterAggregateHandler.Handle(incrementCD, eventStream.Aggregate); - - eventStream.AppendOne(outgoing1); - eventStream.AppendOne(outgoing2); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementCDHandler1083073314 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCDHandler868436596.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCDHandler868436596.cs deleted file mode 100644 index adc8533c7..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCDHandler868436596.cs +++ /dev/null @@ -1,49 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementCDHandler868436596 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class IncrementCDHandler868436596 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementCDHandler868436596(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementCD = (MartenTests.AggregateHandlerWorkflow.IncrementCD)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = incrementCD.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, incrementCD.Version, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler(); - - // The actual message execution - (var outgoing1, var outgoing2) = letterAggregateHandler.Handle(incrementCD, eventStream.Aggregate); - - eventStream.AppendOne(outgoing1); - eventStream.AppendOne(outgoing2); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementCDHandler868436596 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCHandler1473693498.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCHandler1473693498.cs deleted file mode 100644 index 23ebebe4e..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCHandler1473693498.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementCHandler1473693498 - public class IncrementCHandler1473693498 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementCHandler1473693498(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementC = (IncrementC)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementC.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new LetterAggregateHandler(); - - // The actual message execution - letterAggregateHandler.Handle(incrementC, eventStream); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementCHandler1473693498 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCHandler17491960.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCHandler17491960.cs deleted file mode 100644 index c28fef021..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementCHandler17491960.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementCHandler17491960 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class IncrementCHandler17491960 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementCHandler17491960(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementC = (MartenTests.AggregateHandlerWorkflow.IncrementC)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = incrementC.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler(); - - // The actual message execution - letterAggregateHandler.Handle(incrementC, eventStream); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementCHandler17491960 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementDHandler17491957.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementDHandler17491957.cs deleted file mode 100644 index 1cf2d3de9..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementDHandler17491957.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementDHandler17491957 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class IncrementDHandler17491957 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementDHandler17491957(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementD = (MartenTests.AggregateHandlerWorkflow.IncrementD)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = incrementD.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler(); - - // The actual message execution - await letterAggregateHandler.Handle(incrementD, eventStream).ConfigureAwait(false); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementDHandler17491957 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementDHandler1876978025.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementDHandler1876978025.cs deleted file mode 100644 index 7ba0e8c60..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementDHandler1876978025.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementDHandler1876978025 - public class IncrementDHandler1876978025 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementDHandler1876978025(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementD = (IncrementD)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementD.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new LetterAggregateHandler(); - - // The actual message execution - await letterAggregateHandler.Handle(incrementD, eventStream).ConfigureAwait(false); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementDHandler1876978025 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementMany2Handler448896552.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementMany2Handler448896552.cs deleted file mode 100644 index 92053da1f..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementMany2Handler448896552.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementMany2Handler448896552 - public class IncrementMany2Handler448896552 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementMany2Handler448896552(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementMany2 = (MartenTests.IncrementMany2)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementMany2.SelfLetteredAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - if (eventStream.Aggregate == null) throw new Wolverine.Marten.UnknownAggregateException(typeof(MartenTests.SelfLetteredAggregate), incrementMany2.SelfLetteredAggregateId); - var selfLetteredAggregate = new MartenTests.SelfLetteredAggregate(); - - // The actual message execution - var outgoing1 = eventStream.Aggregate.Handle(incrementMany2); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementMany2Handler448896552 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyAsyncHandler1215209648.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyAsyncHandler1215209648.cs deleted file mode 100644 index 8c45e091a..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyAsyncHandler1215209648.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementManyAsyncHandler1215209648 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class IncrementManyAsyncHandler1215209648 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementManyAsyncHandler1215209648(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementManyAsync = (MartenTests.AggregateHandlerWorkflow.IncrementManyAsync)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = incrementManyAsync.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler(); - - // The actual message execution - var outgoing1 = await letterAggregateHandler.Handle(incrementManyAsync, eventStream.Aggregate, documentSession).ConfigureAwait(false); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementManyAsyncHandler1215209648 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyAsyncHandler2038967698.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyAsyncHandler2038967698.cs deleted file mode 100644 index 5f2fb8ab6..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyAsyncHandler2038967698.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementManyAsyncHandler2038967698 - public class IncrementManyAsyncHandler2038967698 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementManyAsyncHandler2038967698(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementManyAsync = (IncrementManyAsync)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementManyAsync.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new LetterAggregateHandler(); - - // The actual message execution - var outgoing1 = await letterAggregateHandler.Handle(incrementManyAsync, eventStream.Aggregate, documentSession).ConfigureAwait(false); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementManyAsyncHandler2038967698 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyHandler1449869648.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyHandler1449869648.cs deleted file mode 100644 index bce36ec8a..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyHandler1449869648.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementManyHandler1449869648 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class IncrementManyHandler1449869648 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementManyHandler1449869648(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementMany = (MartenTests.AggregateHandlerWorkflow.IncrementMany)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = incrementMany.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new MartenTests.AggregateHandlerWorkflow.LetterAggregateHandler(); - - // The actual message execution - var outgoing1 = letterAggregateHandler.Handle(incrementMany, eventStream.Aggregate, documentSession); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementManyHandler1449869648 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyHandler1569177634.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyHandler1569177634.cs deleted file mode 100644 index f1d2de734..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/IncrementManyHandler1569177634.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: IncrementManyHandler1569177634 - public class IncrementManyHandler1569177634 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public IncrementManyHandler1569177634(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var incrementMany = (IncrementMany)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = incrementMany.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var letterAggregateHandler = new LetterAggregateHandler(); - - // The actual message execution - var outgoing1 = letterAggregateHandler.Handle(incrementMany, eventStream.Aggregate, documentSession); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: IncrementManyHandler1569177634 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage1Handler689109168.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage1Handler689109168.cs deleted file mode 100644 index b69e3541e..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage1Handler689109168.cs +++ /dev/null @@ -1,31 +0,0 @@ -// -#pragma warning disable - -namespace Internal.Generated.WolverineHandlers -{ - // START: LetterMessage1Handler689109168 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class LetterMessage1Handler689109168 : Wolverine.Runtime.Handlers.MessageHandler - { - - - public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var letterMessage1 = (MartenTests.AggregateHandlerWorkflow.LetterMessage1)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.ResponseHandler"); - - // The actual message execution - MartenTests.AggregateHandlerWorkflow.ResponseHandler.Handle(letterMessage1); - - return System.Threading.Tasks.Task.CompletedTask; - } - - } - - // END: LetterMessage1Handler689109168 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage1Handler726704086.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage1Handler726704086.cs deleted file mode 100644 index c02307a80..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage1Handler726704086.cs +++ /dev/null @@ -1,32 +0,0 @@ -// - -using MartenTests.AggregateHandlerWorkflow; - -#pragma warning disable - -namespace Internal.Generated.WolverineHandlers -{ - // START: LetterMessage1Handler726704086 - public class LetterMessage1Handler726704086 : Wolverine.Runtime.Handlers.MessageHandler - { - - - public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var letterMessage1 = (LetterMessage1)context.Envelope.Message; - - - // The actual message execution - ResponseHandler.Handle(letterMessage1); - - return System.Threading.Tasks.Task.CompletedTask; - } - - } - - // END: LetterMessage1Handler726704086 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage2Handler689109169.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage2Handler689109169.cs deleted file mode 100644 index 50504fbfb..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage2Handler689109169.cs +++ /dev/null @@ -1,31 +0,0 @@ -// -#pragma warning disable - -namespace Internal.Generated.WolverineHandlers -{ - // START: LetterMessage2Handler689109169 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class LetterMessage2Handler689109169 : Wolverine.Runtime.Handlers.MessageHandler - { - - - public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var letterMessage2 = (MartenTests.AggregateHandlerWorkflow.LetterMessage2)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.ResponseHandler"); - - // The actual message execution - MartenTests.AggregateHandlerWorkflow.ResponseHandler.Handle(letterMessage2); - - return System.Threading.Tasks.Task.CompletedTask; - } - - } - - // END: LetterMessage2Handler689109169 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage2Handler839379855.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage2Handler839379855.cs deleted file mode 100644 index 6b9496b8f..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/LetterMessage2Handler839379855.cs +++ /dev/null @@ -1,32 +0,0 @@ -// - -using MartenTests.AggregateHandlerWorkflow; - -#pragma warning disable - -namespace Internal.Generated.WolverineHandlers -{ - // START: LetterMessage2Handler839379855 - public class LetterMessage2Handler839379855 : Wolverine.Runtime.Handlers.MessageHandler - { - - - public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var letterMessage2 = (LetterMessage2)context.Envelope.Message; - - - // The actual message execution - ResponseHandler.Handle(letterMessage2); - - return System.Threading.Tasks.Task.CompletedTask; - } - - } - - // END: LetterMessage2Handler839379855 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Outgoing1Handler1264108911.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Outgoing1Handler1264108911.cs deleted file mode 100644 index 4ab22de91..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Outgoing1Handler1264108911.cs +++ /dev/null @@ -1,32 +0,0 @@ -// - -using MartenTests.AggregateHandlerWorkflow; - -#pragma warning disable - -namespace Internal.Generated.WolverineHandlers -{ - // START: Outgoing1Handler1264108911 - public class Outgoing1Handler1264108911 : Wolverine.Runtime.Handlers.MessageHandler - { - - - public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var outgoing1 = (Outgoing1)context.Envelope.Message; - - - // The actual message execution - Outgoing1Handler.Handle(outgoing1); - - return System.Threading.Tasks.Task.CompletedTask; - } - - } - - // END: Outgoing1Handler1264108911 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Outgoing1Handler430475575.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Outgoing1Handler430475575.cs deleted file mode 100644 index 58b169fac..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/Outgoing1Handler430475575.cs +++ /dev/null @@ -1,31 +0,0 @@ -// -#pragma warning disable - -namespace Internal.Generated.WolverineHandlers -{ - // START: Outgoing1Handler430475575 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class Outgoing1Handler430475575 : Wolverine.Runtime.Handlers.MessageHandler - { - - - public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var outgoing1 = (MartenTests.AggregateHandlerWorkflow.Outgoing1)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.Outgoing1Handler"); - - // The actual message execution - MartenTests.AggregateHandlerWorkflow.Outgoing1Handler.Handle(outgoing1); - - return System.Threading.Tasks.Task.CompletedTask; - } - - } - - // END: Outgoing1Handler430475575 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAAAHandler1649029811.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAAAHandler1649029811.cs deleted file mode 100644 index 5ee007558..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAAAHandler1649029811.cs +++ /dev/null @@ -1,49 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseAAAHandler1649029811 - public class RaiseAAAHandler1649029811 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseAAAHandler1649029811(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseAAA = (RaiseAAA)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = raiseAAA.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - var outgoing1 = RaiseLetterHandler.Handle(raiseAAA, eventStream); - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing1).ConfigureAwait(false); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseAAAHandler1649029811 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAAAHandler2123707049.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAAAHandler2123707049.cs deleted file mode 100644 index d59d158c7..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAAAHandler2123707049.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseAAAHandler2123707049 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class RaiseAAAHandler2123707049 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseAAAHandler2123707049(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseAAA = (MartenTests.AggregateHandlerWorkflow.RaiseAAA)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = raiseAAA.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - var outgoing1 = MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler.Handle(raiseAAA, eventStream); - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing1).ConfigureAwait(false); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseAAAHandler2123707049 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAABCCHandler1413048758.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAABCCHandler1413048758.cs deleted file mode 100644 index 821738fb4..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAABCCHandler1413048758.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseAABCCHandler1413048758 - public class RaiseAABCCHandler1413048758 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseAABCCHandler1413048758(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseAABCC = (RaiseAABCC)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = raiseAABCC.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - (var outgoing1, var outgoing2) = RaiseLetterHandler.Handle(raiseAABCC, eventStream.Aggregate); - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing1).ConfigureAwait(false); - - if (outgoing2 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing2); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseAABCCHandler1413048758 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAABCCHandler321015832.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAABCCHandler321015832.cs deleted file mode 100644 index 63fd8dd93..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseAABCCHandler321015832.cs +++ /dev/null @@ -1,58 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseAABCCHandler321015832 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class RaiseAABCCHandler321015832 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseAABCCHandler321015832(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseAABCC = (MartenTests.AggregateHandlerWorkflow.RaiseAABCC)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = raiseAABCC.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - (var outgoing1, var outgoing2) = MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler.Handle(raiseAABCC, eventStream.Aggregate); - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing1).ConfigureAwait(false); - - if (outgoing2 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing2); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseAABCCHandler321015832 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseABCHandler1483138068.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseABCHandler1483138068.cs deleted file mode 100644 index 173028cd6..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseABCHandler1483138068.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseABCHandler1483138068 - public class RaiseABCHandler1483138068 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseABCHandler1483138068(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseABC = (RaiseABC)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = raiseABC.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - (var outgoing1, var outgoing2) = RaiseLetterHandler.Handle(raiseABC, eventStream.Aggregate); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing2).ConfigureAwait(false); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseABCHandler1483138068 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseABCHandler1767975722.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseABCHandler1767975722.cs deleted file mode 100644 index 06cc9c9e7..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseABCHandler1767975722.cs +++ /dev/null @@ -1,58 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseABCHandler1767975722 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class RaiseABCHandler1767975722 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseABCHandler1767975722(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseABC = (MartenTests.AggregateHandlerWorkflow.RaiseABC)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = raiseABC.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - (var outgoing1, var outgoing2) = MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler.Handle(raiseABC, eventStream.Aggregate); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing2).ConfigureAwait(false); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseABCHandler1767975722 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseBBCCCHandler1466785177.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseBBCCCHandler1466785177.cs deleted file mode 100644 index 3a374eb63..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseBBCCCHandler1466785177.cs +++ /dev/null @@ -1,62 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseBBCCCHandler1466785177 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class RaiseBBCCCHandler1466785177 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseBBCCCHandler1466785177(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseBBCCC = (MartenTests.AggregateHandlerWorkflow.RaiseBBCCC)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = raiseBBCCC.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - (var outgoing1, var outgoing2, var outgoing3) = MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler.Handle(raiseBBCCC, eventStream.Aggregate); - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing1).ConfigureAwait(false); - - if (outgoing2 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing2); - - } - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing3).ConfigureAwait(false); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseBBCCCHandler1466785177 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseBBCCCHandler1900945687.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseBBCCCHandler1900945687.cs deleted file mode 100644 index 816db5085..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseBBCCCHandler1900945687.cs +++ /dev/null @@ -1,61 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseBBCCCHandler1900945687 - public class RaiseBBCCCHandler1900945687 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseBBCCCHandler1900945687(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseBBCCC = (RaiseBBCCC)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = raiseBBCCC.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - (var outgoing1, var outgoing2, var outgoing3) = RaiseLetterHandler.Handle(raiseBBCCC, eventStream.Aggregate); - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing1).ConfigureAwait(false); - - if (outgoing2 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing2); - - } - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing3).ConfigureAwait(false); - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseBBCCCHandler1900945687 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseHandler488373842.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseHandler488373842.cs deleted file mode 100644 index 1f94ed669..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseHandler488373842.cs +++ /dev/null @@ -1,60 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseHandler488373842 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class RaiseHandler488373842 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseHandler488373842(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raise = (MartenTests.AggregateHandlerWorkflow.Raise)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = raise.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - (var outgoing1, var outgoing2) = MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler.Handle(raise, eventStream.Aggregate); - - // Wolverine.Marten.UpdatedAggregate generates special response handling - if (outgoing2 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing2); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - var response_of_letterAggregate = await eventStoreOperations.FetchLatest(aggregateId, cancellation); - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(response_of_letterAggregate).ConfigureAwait(false); - - } - - } - - // END: RaiseHandler488373842 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseHandler985277900.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseHandler985277900.cs deleted file mode 100644 index bece68216..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseHandler985277900.cs +++ /dev/null @@ -1,62 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseHandler985277900 - public class RaiseHandler985277900 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseHandler985277900(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raise = (Raise)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = raise.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - (var outgoing1, var outgoing2) = RaiseLetterHandler.Handle(raise, eventStream.Aggregate); - - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(outgoing1).ConfigureAwait(false); - - if (outgoing2 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing2); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - var response_of_letterAggregate = await eventStore.FetchLatest(aggregateId, cancellation); - - // Outgoing, cascaded message - await context.EnqueueCascadingAsync(response_of_letterAggregate).ConfigureAwait(false); - - } - - } - - // END: RaiseHandler985277900 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseIfValidatedHandler2071345539.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseIfValidatedHandler2071345539.cs deleted file mode 100644 index 419515e42..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseIfValidatedHandler2071345539.cs +++ /dev/null @@ -1,56 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseIfValidatedHandler2071345539 - public class RaiseIfValidatedHandler2071345539 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseIfValidatedHandler2071345539(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseIfValidated = (RaiseIfValidated)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = raiseIfValidated.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var result_of_Validate1 = RaiseIfValidatedHandler.Validate(eventStream.Aggregate); - // Evaluate whether or not the execution should stop based on the HandlerContinuation value - if (result_of_Validate1 == Wolverine.HandlerContinuation.Stop) return; - - // The actual message execution - var outgoing1 = RaiseIfValidatedHandler.Handle(raiseIfValidated, eventStream.Aggregate); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseIfValidatedHandler2071345539 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseIfValidatedHandler791852127.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseIfValidatedHandler791852127.cs deleted file mode 100644 index f07501a77..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseIfValidatedHandler791852127.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseIfValidatedHandler791852127 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class RaiseIfValidatedHandler791852127 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseIfValidatedHandler791852127(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseIfValidated = (MartenTests.AggregateHandlerWorkflow.RaiseIfValidated)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.RaiseIfValidatedHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = raiseIfValidated.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - var result_of_Validate97 = MartenTests.AggregateHandlerWorkflow.RaiseIfValidatedHandler.Validate(eventStream.Aggregate); - // Evaluate whether or not the execution should stop based on the HandlerContinuation value - if (result_of_Validate97 == Wolverine.HandlerContinuation.Stop) return; - - // The actual message execution - var outgoing1 = MartenTests.AggregateHandlerWorkflow.RaiseIfValidatedHandler.Handle(raiseIfValidated, eventStream.Aggregate); - - if (outgoing1 != null) - { - - // Capturing any possible events returned from the command handlers - eventStream.AppendMany(outgoing1); - - } - - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseIfValidatedHandler791852127 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseLotsAsyncHandler840624058.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseLotsAsyncHandler840624058.cs deleted file mode 100644 index 598fc18a8..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseLotsAsyncHandler840624058.cs +++ /dev/null @@ -1,48 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseLotsAsyncHandler840624058 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class RaiseLotsAsyncHandler840624058 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseLotsAsyncHandler840624058(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseLotsAsync = (MartenTests.AggregateHandlerWorkflow.RaiseLotsAsync)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = raiseLotsAsync.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - var outgoing1 = MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler.Handle(raiseLotsAsync, eventStream.Aggregate); - - // Apply events to Marten event stream - await foreach (var letterAggregateEvent in outgoing1) eventStream.AppendOne(letterAggregateEvent); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseLotsAsyncHandler840624058 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseLotsAsyncHandler89313884.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseLotsAsyncHandler89313884.cs deleted file mode 100644 index 6c842cbc1..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseLotsAsyncHandler89313884.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseLotsAsyncHandler89313884 - public class RaiseLotsAsyncHandler89313884 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseLotsAsyncHandler89313884(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseLotsAsync = (RaiseLotsAsync)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = raiseLotsAsync.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - var outgoing1 = RaiseLetterHandler.Handle(raiseLotsAsync, eventStream.Aggregate); - - // Apply events to Marten event stream - await foreach (var letterAggregateEvent in outgoing1) eventStream.AppendOne(letterAggregateEvent); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseLotsAsyncHandler89313884 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseOnlyDHandler1355962904.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseOnlyDHandler1355962904.cs deleted file mode 100644 index b8b1cee19..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseOnlyDHandler1355962904.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -#pragma warning disable -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseOnlyDHandler1355962904 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class RaiseOnlyDHandler1355962904 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseOnlyDHandler1355962904(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseOnlyD = (MartenTests.AggregateHandlerWorkflow.RaiseOnlyD)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler"); - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStoreOperations = documentSession.Events; - var aggregateId = raiseOnlyD.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStoreOperations.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - var outgoing1 = MartenTests.AggregateHandlerWorkflow.RaiseLetterHandler.Handle(raiseOnlyD, eventStream.Aggregate); - - eventStream.AppendOne(outgoing1); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseOnlyDHandler1355962904 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseOnlyDHandler1609388090.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseOnlyDHandler1609388090.cs deleted file mode 100644 index e1acb7669..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/RaiseOnlyDHandler1609388090.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -#pragma warning disable -using MartenTests.AggregateHandlerWorkflow; -using Wolverine.Marten.Publishing; - -namespace Internal.Generated.WolverineHandlers -{ - // START: RaiseOnlyDHandler1609388090 - public class RaiseOnlyDHandler1609388090 : Wolverine.Runtime.Handlers.MessageHandler - { - private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; - - public RaiseOnlyDHandler1609388090(Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) - { - _outboxedSessionFactory = outboxedSessionFactory; - } - - - - public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var raiseOnlyD = (RaiseOnlyD)context.Envelope.Message; - - await using var documentSession = _outboxedSessionFactory.OpenSession(context); - var eventStore = documentSession.Events; - var aggregateId = raiseOnlyD.LetterAggregateId; - - // Loading Marten aggregate - var eventStream = await eventStore.FetchForWriting(aggregateId, cancellation).ConfigureAwait(false); - - - // The actual message execution - var outgoing1 = RaiseLetterHandler.Handle(raiseOnlyD, eventStream.Aggregate); - - eventStream.AppendOne(outgoing1); - await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); - } - - } - - // END: RaiseOnlyDHandler1609388090 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/ResponseHandler2029358463.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/ResponseHandler2029358463.cs deleted file mode 100644 index 48255f271..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/ResponseHandler2029358463.cs +++ /dev/null @@ -1,31 +0,0 @@ -// -#pragma warning disable - -namespace Internal.Generated.WolverineHandlers -{ - // START: ResponseHandler2029358463 - [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] - public sealed class ResponseHandler2029358463 : Wolverine.Runtime.Handlers.MessageHandler - { - - - public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var response = (MartenTests.AggregateHandlerWorkflow.Response)context.Envelope.Message; - - System.Diagnostics.Activity.Current?.SetTag("message.handler", "MartenTests.AggregateHandlerWorkflow.ResponseHandler"); - - // The actual message execution - MartenTests.AggregateHandlerWorkflow.ResponseHandler.Handle(response); - - return System.Threading.Tasks.Task.CompletedTask; - } - - } - - // END: ResponseHandler2029358463 - - -} - diff --git a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/ResponseHandler2107844337.cs b/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/ResponseHandler2107844337.cs deleted file mode 100644 index 5f458b338..000000000 --- a/src/Persistence/MartenTests/Internal/Generated/WolverineHandlers/ResponseHandler2107844337.cs +++ /dev/null @@ -1,32 +0,0 @@ -// - -using MartenTests.AggregateHandlerWorkflow; - -#pragma warning disable - -namespace Internal.Generated.WolverineHandlers -{ - // START: ResponseHandler2107844337 - public class ResponseHandler2107844337 : Wolverine.Runtime.Handlers.MessageHandler - { - - - public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) - { - // The actual message body - var response = (Response)context.Envelope.Message; - - - // The actual message execution - ResponseHandler.Handle(response); - - return System.Threading.Tasks.Task.CompletedTask; - } - - } - - // END: ResponseHandler2107844337 - - -} - diff --git a/src/Persistence/MartenTests/MartenFaultPublishingTests.cs b/src/Persistence/MartenTests/MartenFaultPublishingTests.cs index 2adcba2f2..f636b4ee1 100644 --- a/src/Persistence/MartenTests/MartenFaultPublishingTests.cs +++ b/src/Persistence/MartenTests/MartenFaultPublishingTests.cs @@ -34,6 +34,7 @@ public override async Task BuildCleanHostAsync(Action? opts.Durability.Mode = DurabilityMode.Solo; opts.Durability.KeepAfterMessageHandling = 5.Minutes(); + opts.Discovery.DisableConventionalDiscovery(); opts.Discovery.IncludeType(); opts.Discovery.IncludeType(); opts.Services.AddSingleton(); diff --git a/src/Persistence/MartenTests/MartenOutbox_end_to_end.cs b/src/Persistence/MartenTests/MartenOutbox_end_to_end.cs index c0231afde..e8b2ad126 100644 --- a/src/Persistence/MartenTests/MartenOutbox_end_to_end.cs +++ b/src/Persistence/MartenTests/MartenOutbox_end_to_end.cs @@ -18,6 +18,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(OutboxedMessageHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); diff --git a/src/Persistence/MartenTests/MartenTests.csproj b/src/Persistence/MartenTests/MartenTests.csproj index 38654530a..fa02d7560 100644 --- a/src/Persistence/MartenTests/MartenTests.csproj +++ b/src/Persistence/MartenTests/MartenTests.csproj @@ -7,12 +7,12 @@ - + - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -27,9 +27,9 @@ - + - + diff --git a/src/Persistence/MartenTests/Marten_StorageCommand_Smoke_Tests.cs b/src/Persistence/MartenTests/Marten_StorageCommand_Smoke_Tests.cs index d5e3c214a..3171f26cb 100644 --- a/src/Persistence/MartenTests/Marten_StorageCommand_Smoke_Tests.cs +++ b/src/Persistence/MartenTests/Marten_StorageCommand_Smoke_Tests.cs @@ -20,6 +20,8 @@ public async Task smoke_test_calls(string commandLine) var exitCode = await Host.CreateDefaultBuilder().UseWolverine(registry => { + registry.Discovery.DisableConventionalDiscovery(); + registry.Durability.Mode = DurabilityMode.Solo; registry.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); }).RunWolverineAsync(args); diff --git a/src/Persistence/MartenTests/MultiTenancy/agent_mechanics.cs b/src/Persistence/MartenTests/MultiTenancy/agent_mechanics.cs index bcf7c06cf..c4ccfeb4f 100644 --- a/src/Persistence/MartenTests/MultiTenancy/agent_mechanics.cs +++ b/src/Persistence/MartenTests/MultiTenancy/agent_mechanics.cs @@ -21,9 +21,14 @@ public async Task all_agents_start() await using (var conn = new NpgsqlConnection(Servers.PostgresConnectionString)) { await conn.OpenAsync(); - await conn.CreateCommand($"delete from control.{DatabaseConstants.NodeAssignmentsTableName}") - .ExecuteNonQueryAsync(); - await conn.CreateCommand($"delete from control.{DatabaseConstants.NodeTableName}").ExecuteNonQueryAsync(); + + var sql = $@" + DELETE FROM control.{DatabaseConstants.NodeAssignmentsTableName}; + DELETE FROM control.{DatabaseConstants.NodeTableName}; + "; + await using var command = conn.CreateCommand(sql); + await command.ExecuteNonQueryAsync(); + await conn.CloseAsync(); } diff --git a/src/Persistence/MartenTests/MultiTenancy/basic_bootstrapping_and_database_configuration.cs b/src/Persistence/MartenTests/MultiTenancy/basic_bootstrapping_and_database_configuration.cs index 2077acde7..b1fb4987b 100644 --- a/src/Persistence/MartenTests/MultiTenancy/basic_bootstrapping_and_database_configuration.cs +++ b/src/Persistence/MartenTests/MultiTenancy/basic_bootstrapping_and_database_configuration.cs @@ -26,8 +26,9 @@ public void should_have_the_specified_master_database_as_master() { Stores.Main.Name.ShouldBe(StorageConstants.Main); Stores.Main.As().SchemaName.ShouldBe("control"); + using var connection = Stores.Main.As().DataSource.CreateConnection(); - new NpgsqlConnectionStringBuilder(Stores.Main.As().DataSource.CreateConnection().ConnectionString) + new NpgsqlConnectionStringBuilder(connection.ConnectionString) .Database.ShouldBe("postgres"); } diff --git a/src/Persistence/MartenTests/MultiTenancy/conjoined_tenancy.cs b/src/Persistence/MartenTests/MultiTenancy/conjoined_tenancy.cs index 678a64eb8..a3d7fa7bb 100644 --- a/src/Persistence/MartenTests/MultiTenancy/conjoined_tenancy.cs +++ b/src/Persistence/MartenTests/MultiTenancy/conjoined_tenancy.cs @@ -20,6 +20,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(CreateTenantDocumentHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine() .UseLightweightSessions(); diff --git a/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_durability_agents_for_new_tenant_databases.cs b/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_durability_agents_for_new_tenant_databases.cs index 639f8c05d..8b35a9518 100644 --- a/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_durability_agents_for_new_tenant_databases.cs +++ b/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_durability_agents_for_new_tenant_databases.cs @@ -59,6 +59,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(PeristDocHandler)); + opts.Durability.Mode = DurabilityMode.Solo; // This is too extreme for real usage, but helps tests to run faster opts.Durability.NodeReassignmentPollingTime = 1.Seconds(); opts.Durability.HealthCheckPollingTime = 1.Seconds(); @@ -151,6 +153,8 @@ public async Task ability_to_execute_commands_immediately_on_new_tenant_database using var otherHost = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(PeristDocHandler)); + opts.Durability.Mode = DurabilityMode.Solo; // This is too extreme for real usage, but helps tests to run faster opts.Durability.NodeReassignmentPollingTime = 1.Seconds(); opts.Durability.HealthCheckPollingTime = 1.Seconds(); diff --git a/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_tenant_databases_in_solo_mode.cs b/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_tenant_databases_in_solo_mode.cs index 24aa848df..f5e92a8fb 100644 --- a/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_tenant_databases_in_solo_mode.cs +++ b/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_tenant_databases_in_solo_mode.cs @@ -42,6 +42,7 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery(); opts.Durability.Mode = DurabilityMode.Solo; // This is too extreme for real usage, but helps tests to run faster diff --git a/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_tenant_databases_with_autocreate.cs b/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_tenant_databases_with_autocreate.cs index 81e3d6e65..808ebb624 100644 --- a/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_tenant_databases_with_autocreate.cs +++ b/src/Persistence/MartenTests/MultiTenancy/dynamically_spin_up_new_tenant_databases_with_autocreate.cs @@ -96,6 +96,9 @@ public async Task add_databases_and_see_durability_agents_fail_to_start() var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(PeristDocHandler)); + opts.Durability.Mode = DurabilityMode.Solo; // This is too extreme for real usage, but helps tests to run faster opts.Durability.NodeReassignmentPollingTime = 1.Seconds(); diff --git a/src/Persistence/MartenTests/MultiTenancy/multi_tenancy_queue_usage.cs b/src/Persistence/MartenTests/MultiTenancy/multi_tenancy_queue_usage.cs index b7bb783be..e9742ef38 100644 --- a/src/Persistence/MartenTests/MultiTenancy/multi_tenancy_queue_usage.cs +++ b/src/Persistence/MartenTests/MultiTenancy/multi_tenancy_queue_usage.cs @@ -76,8 +76,9 @@ public async Task InitializeAsync() // This is too extreme for real usage, but helps tests to run faster opts.Durability.NodeReassignmentPollingTime = 1.Seconds(); opts.Durability.HealthCheckPollingTime = 1.Seconds(); - opts.Durability.TenantCheckPeriod = 250.Milliseconds(); - + opts.Durability.TenantCheckPeriod = 250.Milliseconds(); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(TenantDocHandler)); opts.Durability.Mode = DurabilityMode.Solo; opts.ListenToPostgresqlQueue("one"); @@ -110,6 +111,7 @@ public async Task InitializeAsync() _sender = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery(); // This is too extreme for real usage, but helps tests to run faster opts.Durability.NodeReassignmentPollingTime = 1.Seconds(); opts.Durability.HealthCheckPollingTime = 1.Seconds(); @@ -153,10 +155,11 @@ public async Task InitializeAsync() public async Task DisposeAsync() { - await _receiver.StopAsync(); + await Task.WhenAll( + _receiver.StopAsync(), + _sender.StopAsync() + ); _receiver.Dispose(); - - await _sender.StopAsync(); _sender.Dispose(); } diff --git a/src/Persistence/MartenTests/MultiTenancy/using_tenant_specific_queues_and_subscriptions.cs b/src/Persistence/MartenTests/MultiTenancy/using_tenant_specific_queues_and_subscriptions.cs index 674b53fa4..060ad49d4 100644 --- a/src/Persistence/MartenTests/MultiTenancy/using_tenant_specific_queues_and_subscriptions.cs +++ b/src/Persistence/MartenTests/MultiTenancy/using_tenant_specific_queues_and_subscriptions.cs @@ -63,6 +63,7 @@ public async Task InitializeAsync() _sender = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(UpdateColorCountsHandler)); // This is too extreme for real usage, but helps tests to run faster opts.Durability.NodeReassignmentPollingTime = 1.Seconds(); opts.Durability.HealthCheckPollingTime = 1.Seconds(); @@ -104,21 +105,17 @@ public async Task InitializeAsync() public async Task DisposeAsync() { - foreach (var host in _receivers) host.GetRuntime().Agents.DisableHealthChecks(); - - _receivers.Reverse(); - foreach (var host in _receivers.ToArray()) await shutdownHostAsync(host); - - await _sender.StopAsync(); - _sender.Dispose(); + await Task.WhenAll([ + .._receivers.Select(ShutdownHostAsync), + ShutdownHostAsync(_sender) + ]); } - private async Task shutdownHostAsync(IHost host) + private static async Task ShutdownHostAsync(IHost host) { host.GetRuntime().Agents.DisableHealthChecks(); await host.StopAsync(); host.Dispose(); - _receivers.Remove(host); } private async Task CreateDatabaseIfNotExists(NpgsqlConnection conn, string databaseName) @@ -142,6 +139,8 @@ protected async Task startNewReceiver() var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(UpdateColorCountsHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Durability.Mode = DurabilityMode.Balanced; opts.ListenToPostgresqlQueue("numbers").ListenWithStrictOrdering(); @@ -190,26 +189,6 @@ private async Task cleanOldData(string connectionString) await conn.CloseAsync(); } - private async Task publishNumbers(string tenantId, List colors) - { - await using var session = theSenderStore.LightweightSession(tenantId); - - while (colors.Any(x => !x.IsComplete())) - { - foreach (var color in colors) - { - if (color.IsComplete()) - { - continue; - } - - color.PublishSome(session); - } - } - - await session.SaveChangesAsync(); - } - [Fact] public async Task big_bang_end_to_end() { diff --git a/src/Persistence/MartenTests/Persistence/MartenBackedListenerContext.cs b/src/Persistence/MartenTests/Persistence/MartenBackedListenerContext.cs index 1f3df320c..48506ab84 100644 --- a/src/Persistence/MartenTests/Persistence/MartenBackedListenerContext.cs +++ b/src/Persistence/MartenTests/Persistence/MartenBackedListenerContext.cs @@ -6,7 +6,6 @@ using NSubstitute; using Shouldly; using Wolverine; -using Wolverine.Persistence.Durability; using Wolverine.Postgresql; using Wolverine.RDBMS; using Wolverine.Runtime; @@ -43,56 +42,46 @@ public async Task handling_a_single_scheduled_but_expired_envelope() } } -public class MartenBackedListenerContext : PostgresqlContext, IDisposable, IAsyncLifetime +public class MartenBackedListenerContext : PostgresqlContext, IAsyncLifetime { - protected readonly IMessageStoreAdmin MessageStoreAdmin = - new PostgresqlMessageStore(new DatabaseSettings() - { ConnectionString = Servers.PostgresConnectionString }, new DurabilitySettings(), NpgsqlDataSource.Create(Servers.PostgresConnectionString), - new NullLogger()); - - protected readonly IList theEnvelopes = new List(); + private readonly IList theEnvelopes = []; private readonly IHandlerPipeline thePipeline = Substitute.For(); - protected readonly DocumentStore theStore; - protected readonly Uri theUri = "tcp://localhost:1111".ToUri(); - internal DurableReceiver theReceiver = null!; + private readonly Uri theUri = "tcp://localhost:1111".ToUri(); + private DocumentStore _documentStore = null!; + private PostgresqlMessageStore _messageStore = null!; + private DurableReceiver _receiver = null!; protected DurabilitySettings theSettings = null!; - public MartenBackedListenerContext() - { - theStore = DocumentStore.For(opts => { opts.Connection(Servers.PostgresConnectionString); }); - } - public async Task InitializeAsync() { - theSettings = new DurabilitySettings(); + _documentStore = DocumentStore.For(opts => + opts.Connection(Servers.PostgresConnectionString)); + theSettings = new DurabilitySettings(); - await MessageStoreAdmin.RebuildAsync(); + _messageStore = new PostgresqlMessageStore( + new DatabaseSettings() { ConnectionString = Servers.PostgresConnectionString }, + theSettings, + NpgsqlDataSource.Create(Servers.PostgresConnectionString), + new NullLogger()); - var persistence = - new PostgresqlMessageStore( - new DatabaseSettings() { ConnectionString = Servers.PostgresConnectionString }, theSettings, NpgsqlDataSource.Create(Servers.PostgresConnectionString), - new NullLogger()); + await _messageStore.RebuildAsync(); var runtime = Substitute.For(); - runtime.Storage.Returns(persistence); + runtime.Storage.Returns(_messageStore); runtime.Pipeline.Returns(thePipeline); runtime.DurabilitySettings.Returns(theSettings); - - theReceiver = new DurableReceiver(new LocalQueue("temp"), runtime, runtime.Pipeline); + _receiver = new DurableReceiver(new LocalQueue("temp"), runtime, runtime.Pipeline); } - public Task DisposeAsync() + public async Task DisposeAsync() { - Dispose(); - return Task.CompletedTask; - } - - public void Dispose() - { - theStore?.Dispose(); + if (_documentStore is not null) + await _documentStore.DisposeAsync(); + if (_messageStore is not null) + await _messageStore.DisposeAsync(); } protected Envelope notScheduledEnvelope() @@ -109,21 +98,6 @@ protected Envelope notScheduledEnvelope() return env; } - protected Envelope scheduledEnvelope() - { - var env = new Envelope - { - Data = [1, 2, 3, 4], - ScheduledTime = DateTimeOffset.Now.Add(1.Hours()), - MessageType = "foo", - ContentType = EnvelopeConstants.JsonContentType - }; - - theEnvelopes.Add(env); - - return env; - } - protected Envelope scheduledButExpiredEnvelope() { var env = new Envelope @@ -143,18 +117,13 @@ protected async Task> afterReceivingTheEnvelopes() { var listener = Substitute.For(); listener.Address.Returns(theUri); - await theReceiver.ProcessReceivedMessagesAsync(DateTimeOffset.Now, listener, theEnvelopes.ToArray()); + await _receiver.ProcessReceivedMessagesAsync(DateTimeOffset.Now, listener, [.. theEnvelopes]); - return await MessageStoreAdmin.AllIncomingAsync(); + return await _messageStore!.AllIncomingAsync(); } protected void assertEnvelopeWasEnqueued(Envelope envelope) { - thePipeline.Received().InvokeAsync(envelope, theReceiver); - } - - protected void assertEnvelopeWasNotEnqueued(Envelope envelope) - { - thePipeline.DidNotReceive().InvokeAsync(envelope, theReceiver); + thePipeline.Received().InvokeAsync(envelope, _receiver); } } \ No newline at end of file diff --git a/src/Persistence/MartenTests/Persistence/MartenBackedMessagePersistenceTests.cs b/src/Persistence/MartenTests/Persistence/MartenBackedMessagePersistenceTests.cs index 65f47504d..7e6c9bddb 100644 --- a/src/Persistence/MartenTests/Persistence/MartenBackedMessagePersistenceTests.cs +++ b/src/Persistence/MartenTests/Persistence/MartenBackedMessagePersistenceTests.cs @@ -40,6 +40,9 @@ public async Task InitializeAsync() { theHost = await WolverineHost.ForAsync(opts => { + opts.Discovery.DisableConventionalDiscovery(); + opts.Durability.Mode = DurabilityMode.Solo; + opts.Services.AddMarten(x => { x.Connection(Servers.PostgresConnectionString); }) .IntegrateWithWolverine(); }); diff --git a/src/Persistence/MartenTests/Persistence/Sagas/MartenSagaHost.cs b/src/Persistence/MartenTests/Persistence/Sagas/MartenSagaHost.cs index 554716c59..13263bc6f 100644 --- a/src/Persistence/MartenTests/Persistence/Sagas/MartenSagaHost.cs +++ b/src/Persistence/MartenTests/Persistence/Sagas/MartenSagaHost.cs @@ -6,6 +6,8 @@ using Wolverine.ComplianceTests; using Wolverine.ComplianceTests.Sagas; using Weasel.Core; +using Wolverine; +using Wolverine.Persistence.Durability; using Wolverine.Marten; namespace MartenTests.Persistence.Sagas; @@ -20,6 +22,8 @@ public async Task BuildHostAsync() { opts.DisableConventionalDiscovery().IncludeType(); + opts.Durability.Mode = DurabilityMode.Solo; + opts.Services.AddMarten(x => { x.Connection(Servers.PostgresConnectionString); diff --git a/src/Persistence/MartenTests/Persistence/end_to_end_with_persistence.cs b/src/Persistence/MartenTests/Persistence/end_to_end_with_persistence.cs index 46e61c654..a6a4dbf57 100644 --- a/src/Persistence/MartenTests/Persistence/end_to_end_with_persistence.cs +++ b/src/Persistence/MartenTests/Persistence/end_to_end_with_persistence.cs @@ -16,11 +16,10 @@ namespace MartenTests.Persistence; -public class end_to_end_with_persistence : PostgresqlContext, IDisposable, IAsyncLifetime +public class end_to_end_with_persistence : PostgresqlContext, IAsyncLifetime { private readonly ITestOutputHelper _output; private IHost theReceiver = null!; - private IHost theSender = null!; public end_to_end_with_persistence(ITestOutputHelper output) @@ -47,6 +46,11 @@ public async Task InitializeAsync() }).IntegrateWithWolverine(); opts.ListenAtPort(2567); + + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(ItemCreatedHandler)) + .IncludeType(typeof(QuestionHandler)); + opts.Durability.Mode = DurabilityMode.Solo; }); theReceiver = await WolverineHost.ForAsync(opts => @@ -61,6 +65,10 @@ public async Task InitializeAsync() x.Connection(Servers.PostgresConnectionString); x.DatabaseSchemaName = "receiver"; }).IntegrateWithWolverine(); + + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(ItemCreatedHandler)); + opts.Durability.Mode = DurabilityMode.Solo; }); await theSender.ResetResourceState(); @@ -68,15 +76,10 @@ public async Task InitializeAsync() } public Task DisposeAsync() - { - Dispose(); - return Task.CompletedTask; - } - - public void Dispose() { theSender?.Dispose(); theReceiver?.Dispose(); + return Task.CompletedTask; } [Fact] @@ -120,7 +123,7 @@ public async Task publish_locally() var item2 = await session.LoadAsync(item.Id); if (item2 == null) { - Thread.Sleep(500); + await Task.Delay(500); item2 = await session.LoadAsync(item.Id); } diff --git a/src/Persistence/MartenTests/Persistence/marten_durability_end_to_end.cs b/src/Persistence/MartenTests/Persistence/marten_durability_end_to_end.cs index 2ef686437..b10f3cb77 100644 --- a/src/Persistence/MartenTests/Persistence/marten_durability_end_to_end.cs +++ b/src/Persistence/MartenTests/Persistence/marten_durability_end_to_end.cs @@ -17,7 +17,6 @@ namespace MartenTests.Persistence; -[Trait("Category", "Flaky")] public class marten_durability_end_to_end : IAsyncLifetime { private const string SenderSchemaName = "sender"; @@ -27,6 +26,8 @@ public class marten_durability_end_to_end : IAsyncLifetime private DocumentStore _receiverStore = null!; private LightweightCache _senders = null!; private DocumentStore _sendingStore = null!; + private PostgresqlMessageStore? _receiverMessageStore; + private PostgresqlMessageStore? _senderMessageStore; public async Task InitializeAsync() { @@ -52,15 +53,15 @@ public async Task InitializeAsync() var advanced = new DurabilitySettings(); var logger = new NullLogger(); - await new PostgresqlMessageStore(new DatabaseSettings() + _receiverMessageStore = new PostgresqlMessageStore(new DatabaseSettings() { ConnectionString = Servers.PostgresConnectionString, SchemaName = ReceiverSchemaName }, advanced, NpgsqlDataSource.Create(Servers.PostgresConnectionString), - logger) - .RebuildAsync(); + logger); + await _receiverMessageStore.RebuildAsync(); - await new PostgresqlMessageStore(new DatabaseSettings() + _senderMessageStore = new PostgresqlMessageStore(new DatabaseSettings() { ConnectionString = Servers.PostgresConnectionString, SchemaName = SenderSchemaName }, advanced, NpgsqlDataSource.Create(Servers.PostgresConnectionString), - logger) - .RebuildAsync(); + logger); + await _senderMessageStore.RebuildAsync(); await _sendingStore.Advanced.Clean.CompletelyRemoveAllAsync(); await _sendingStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync(); @@ -72,6 +73,7 @@ public async Task InitializeAsync() return Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Policies.AutoApplyTransactions(); opts.DisableConventionalDiscovery(); opts.IncludeType(); @@ -93,6 +95,7 @@ public async Task InitializeAsync() return Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.DisableConventionalDiscovery(); opts.Policies.AutoApplyTransactions(); @@ -137,6 +140,18 @@ public async Task DisposeAsync() _receiverStore = null!; _sendingStore.Dispose(); _sendingStore = null!; + + if (_receiverMessageStore != null) + { + await _receiverMessageStore.DisposeAsync(); + _receiverMessageStore = null; + } + + if (_senderMessageStore != null) + { + await _senderMessageStore.DisposeAsync(); + _senderMessageStore = null; + } } protected void StartReceiver(string name) @@ -178,13 +193,10 @@ protected async Task WaitForMessagesToBeProcessed(int count) for (var i = 0; i < 480; i++) { var actual = await session.Query().CountAsync(); - var envelopeCount = PersistedIncomingCount(); - + var envelopeCount = await PersistedIncomingCount(); if (actual == count && envelopeCount == 0) - { return; - } await Task.Delay(250); } @@ -192,24 +204,28 @@ protected async Task WaitForMessagesToBeProcessed(int count) throw new Exception("All messages were not received"); } - protected long PersistedIncomingCount() + protected async Task PersistedIncomingCount() { - using var conn = _receiverStore.Tenancy.Default.Database.CreateConnection(); - conn.Open(); + await using var conn = _receiverStore.Tenancy.Default.Database.CreateConnection(); + await conn.OpenAsync(); - return (long)conn.CreateCommand( - $"select count(*) from receiver.{DatabaseConstants.IncomingTable} where {DatabaseConstants.Status} = '{EnvelopeStatus.Incoming}'") - .ExecuteScalar()!; + var command = conn.CreateCommand( + $"select count(*) from receiver.{DatabaseConstants.IncomingTable} where {DatabaseConstants.Status} = '{EnvelopeStatus.Incoming}'"); + + var count = await command.ExecuteScalarAsync(); + return Convert.ToInt64(count); } - protected long PersistedOutgoingCount() + protected async Task PersistedOutgoingCount() { - using var conn = _sendingStore.Tenancy.Default.Database.CreateConnection(); - conn.Open(); + await using var conn = _sendingStore.Tenancy.Default.Database.CreateConnection(); + await conn.OpenAsync(); + + var command = conn.CreateCommand( + $"select count(*) from sender.{DatabaseConstants.OutgoingTable}"); - return (long)conn.CreateCommand( - $"select count(*) from sender.{DatabaseConstants.OutgoingTable}") - .ExecuteScalar()!; + var count = await command.ExecuteScalarAsync(); + return Convert.ToInt64(count); } protected async Task StopReceiver(string name) @@ -234,12 +250,12 @@ public async Task sending_recovered_messages_when_sender_starts_up() StartSender("Sender1"); await SendMessages("Sender1", 10); await StopSender("Sender1"); - PersistedOutgoingCount().ShouldBe(10); + (await PersistedOutgoingCount()).ShouldBe(10); StartReceiver("Receiver1"); StartSender("Sender2"); await WaitForMessagesToBeProcessed(10); - PersistedIncomingCount().ShouldBe(0); - PersistedOutgoingCount().ShouldBe(0); + (await PersistedIncomingCount()).ShouldBe(0); + (await PersistedOutgoingCount()).ShouldBe(0); (await ReceivedMessageCount()).ShouldBe(10); } @@ -250,8 +266,8 @@ public async Task sending_resumes_when_the_receiver_is_detected() await SendMessages("Sender1", 5); StartReceiver("Receiver1"); await WaitForMessagesToBeProcessed(5); - PersistedIncomingCount().ShouldBe(0); - PersistedOutgoingCount().ShouldBe(0); + (await PersistedIncomingCount()).ShouldBe(0); + (await PersistedOutgoingCount()).ShouldBe(0); (await ReceivedMessageCount()).ShouldBe(5); } } diff --git a/src/Persistence/MartenTests/Requirements/using_data_requirements.cs b/src/Persistence/MartenTests/Requirements/using_data_requirements.cs index d9703ab93..c71e3b0ed 100644 --- a/src/Persistence/MartenTests/Requirements/using_data_requirements.cs +++ b/src/Persistence/MartenTests/Requirements/using_data_requirements.cs @@ -21,6 +21,14 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(CreateThingHandler)) + .IncludeType(typeof(CreateThing2Handler)) + .IncludeType(typeof(CreateThingByAttributeHandler)) + .IncludeType(typeof(CreateThingByAttributeExplicitHandler)) + .IncludeType(typeof(EnsureNoDuplicateThingHandler)) + .IncludeType(typeof(CreateThing3Handler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services .AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); diff --git a/src/Persistence/MartenTests/Saga/OrderSagaTests.cs b/src/Persistence/MartenTests/Saga/OrderSagaTests.cs index 61a8bf30e..9d2160c17 100644 --- a/src/Persistence/MartenTests/Saga/OrderSagaTests.cs +++ b/src/Persistence/MartenTests/Saga/OrderSagaTests.cs @@ -38,7 +38,9 @@ public async Task InitializeAsync() ) .UseWolverine(options => { - options.Discovery.IncludeAssembly(Assembly.GetAssembly(typeof(Order))!); + options.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(Order)); + options.Durability.Mode = DurabilityMode.Solo; }) .StartAsync(); diff --git a/src/Persistence/MartenTests/Saga/RevisionedSaga.cs b/src/Persistence/MartenTests/Saga/RevisionedSaga.cs index 9fd78cd8c..7b8c72a07 100644 --- a/src/Persistence/MartenTests/Saga/RevisionedSaga.cs +++ b/src/Persistence/MartenTests/Saga/RevisionedSaga.cs @@ -25,6 +25,8 @@ public async Task InitializeAsync() theHost = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(RevisionedSaga)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.DisableNpgsqlLogging = true; diff --git a/src/Persistence/MartenTests/Saga/When_handling_messages_in_saga.cs b/src/Persistence/MartenTests/Saga/When_handling_messages_in_saga.cs index 0308e8344..ead254e59 100644 --- a/src/Persistence/MartenTests/Saga/When_handling_messages_in_saga.cs +++ b/src/Persistence/MartenTests/Saga/When_handling_messages_in_saga.cs @@ -17,6 +17,9 @@ public async Task should_not_throw() await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); @@ -47,6 +50,9 @@ public async Task will_not_throw_nonexistent_document_in_not_found() await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); @@ -69,10 +75,9 @@ public async Task should_not_throw_in_memory() await Host.CreateDefaultBuilder() .UseWolverine(opts => { - // opts.Services.AddMarten(Servers.PostgresConnectionString) - // .IntegrateWithWolverine(); - // - // opts.Policies.AutoApplyTransactions(); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(); + opts.Durability.Mode = DurabilityMode.Solo; }) .StartAsync(); @@ -97,10 +102,9 @@ public async Task will_not_throw_nonexistent_document_in_not_found_in_memory() await Host.CreateDefaultBuilder() .UseWolverine(opts => { - // opts.Services.AddMarten(Servers.PostgresConnectionString) - // .IntegrateWithWolverine(); - // - // opts.Policies.AutoApplyTransactions(); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(); + opts.Durability.Mode = DurabilityMode.Solo; }) .StartAsync(); diff --git a/src/Persistence/MartenTests/Saga/When_ordering_a_happy_meal.cs b/src/Persistence/MartenTests/Saga/When_ordering_a_happy_meal.cs index 744a25f4f..7576e1508 100644 --- a/src/Persistence/MartenTests/Saga/When_ordering_a_happy_meal.cs +++ b/src/Persistence/MartenTests/Saga/When_ordering_a_happy_meal.cs @@ -14,7 +14,13 @@ public async Task InitializeAsync() { _host = await Host.CreateDefaultBuilder() - .UseWolverine() + .UseWolverine(opts => + { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType() + .IncludeType(); + opts.Durability.Mode = DurabilityMode.Solo; + }) .StartAsync(); var session = await _host.InvokeMessageAndWaitAsync(new HappyMealOrder { Drink = "Soda" }); diff --git a/src/Persistence/MartenTests/Saga/marten_saga_store_diagnostics_tests.cs b/src/Persistence/MartenTests/Saga/marten_saga_store_diagnostics_tests.cs index d91a3c50f..9609aa991 100644 --- a/src/Persistence/MartenTests/Saga/marten_saga_store_diagnostics_tests.cs +++ b/src/Persistence/MartenTests/Saga/marten_saga_store_diagnostics_tests.cs @@ -32,6 +32,7 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Discovery.DisableConventionalDiscovery().IncludeType(); opts.Services.AddMarten(x => diff --git a/src/Persistence/MartenTests/Saga/multiple_sagas_for_same_message.cs b/src/Persistence/MartenTests/Saga/multiple_sagas_for_same_message.cs index b1ed7fe11..41e0d07b1 100644 --- a/src/Persistence/MartenTests/Saga/multiple_sagas_for_same_message.cs +++ b/src/Persistence/MartenTests/Saga/multiple_sagas_for_same_message.cs @@ -18,6 +18,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(ShippingSaga)); + opts.Durability.Mode = DurabilityMode.Solo; opts.MultipleHandlerBehavior = MultipleHandlerBehavior.Separated; opts.Discovery.IncludeType(); @@ -37,6 +39,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/Saga/not_found_usage.cs b/src/Persistence/MartenTests/Saga/not_found_usage.cs index 3a4395b4f..cd3b3884e 100644 --- a/src/Persistence/MartenTests/Saga/not_found_usage.cs +++ b/src/Persistence/MartenTests/Saga/not_found_usage.cs @@ -20,6 +20,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(InvitationPolicy)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.DisableNpgsqlLogging = true; @@ -34,6 +36,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/Saga/resequencer_saga_end_to_end.cs b/src/Persistence/MartenTests/Saga/resequencer_saga_end_to_end.cs index e2a7da0ab..0a2b5db06 100644 --- a/src/Persistence/MartenTests/Saga/resequencer_saga_end_to_end.cs +++ b/src/Persistence/MartenTests/Saga/resequencer_saga_end_to_end.cs @@ -40,6 +40,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(StartMartenSequencedSaga)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.DisableNpgsqlLogging = true; diff --git a/src/Persistence/MartenTests/Saga/soft_deleted_saga_experiment.cs b/src/Persistence/MartenTests/Saga/soft_deleted_saga_experiment.cs index 03c0e879d..8e58e6dc8 100644 --- a/src/Persistence/MartenTests/Saga/soft_deleted_saga_experiment.cs +++ b/src/Persistence/MartenTests/Saga/soft_deleted_saga_experiment.cs @@ -20,6 +20,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(SoftDeletedOrderSaga)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Discovery.IncludeType(); opts.Services.AddMarten(m => @@ -39,6 +41,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/Saga/starting_saga_by_returning_it_from_handler.cs b/src/Persistence/MartenTests/Saga/starting_saga_by_returning_it_from_handler.cs index 374b808d1..fc299672b 100644 --- a/src/Persistence/MartenTests/Saga/starting_saga_by_returning_it_from_handler.cs +++ b/src/Persistence/MartenTests/Saga/starting_saga_by_returning_it_from_handler.cs @@ -17,10 +17,14 @@ public async Task create_sagas_from_a_starting_message() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) - .IntegrateWithWolverine(); + .IntegrateWithWolverine(); - opts.Discovery.IncludeType(typeof(StartSagasThing)); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(Saga1)) + .IncludeType(typeof(Saga2)) + .IncludeType(typeof(StartSagasThing)); opts.Policies.AutoApplyTransactions(); }).StartAsync(); diff --git a/src/Persistence/MartenTests/Saga/strong_typed_id_saga.cs b/src/Persistence/MartenTests/Saga/strong_typed_id_saga.cs index e61bc239e..a7559d9b8 100644 --- a/src/Persistence/MartenTests/Saga/strong_typed_id_saga.cs +++ b/src/Persistence/MartenTests/Saga/strong_typed_id_saga.cs @@ -89,6 +89,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(OrderSagaWorkflow)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.DisableNpgsqlLogging = true; diff --git a/src/Persistence/MartenTests/Sample/BootstrapWithAutoTransactions.cs b/src/Persistence/MartenTests/Sample/BootstrapWithAutoTransactions.cs index 85382349c..7fe551949 100644 --- a/src/Persistence/MartenTests/Sample/BootstrapWithAutoTransactions.cs +++ b/src/Persistence/MartenTests/Sample/BootstrapWithAutoTransactions.cs @@ -13,6 +13,8 @@ public static async Task bootstrap() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery(); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten("some connection string") .IntegrateWithWolverine(); diff --git a/src/Persistence/MartenTests/Sample/SampleApp.cs b/src/Persistence/MartenTests/Sample/SampleApp.cs index 6b4aa6844..b4c64c894 100644 --- a/src/Persistence/MartenTests/Sample/SampleApp.cs +++ b/src/Persistence/MartenTests/Sample/SampleApp.cs @@ -27,6 +27,10 @@ public async Task InitializeAsync() opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); + + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(UserHandler)); + opts.Durability.Mode = DurabilityMode.Solo; }); await theHost.Get().Advanced.Clean.CompletelyRemoveAllAsync(); @@ -37,6 +41,7 @@ public async Task DisposeAsync() if (theHost != null) { await theHost.StopAsync(); + theHost.Dispose(); } } diff --git a/src/Persistence/MartenTests/TestHelpers/catch_up_and_then_do_nothing.cs b/src/Persistence/MartenTests/TestHelpers/catch_up_and_then_do_nothing.cs index 8ceb315ff..cdfd77123 100644 --- a/src/Persistence/MartenTests/TestHelpers/catch_up_and_then_do_nothing.cs +++ b/src/Persistence/MartenTests/TestHelpers/catch_up_and_then_do_nothing.cs @@ -22,6 +22,10 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(AppendLettersHandler)) + .IncludeType(typeof(AppendLetters2Handler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); @@ -57,6 +61,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/TestHelpers/catch_up_then_restart.cs b/src/Persistence/MartenTests/TestHelpers/catch_up_then_restart.cs index 6a419a64b..6dd5e0915 100644 --- a/src/Persistence/MartenTests/TestHelpers/catch_up_then_restart.cs +++ b/src/Persistence/MartenTests/TestHelpers/catch_up_then_restart.cs @@ -22,6 +22,10 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(AppendLettersHandler)) + .IncludeType(typeof(AppendLetters2Handler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); @@ -55,6 +59,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/TestHelpers/catch_up_when_using_wolverine_distribution.cs b/src/Persistence/MartenTests/TestHelpers/catch_up_when_using_wolverine_distribution.cs index f14216b87..465a64672 100644 --- a/src/Persistence/MartenTests/TestHelpers/catch_up_when_using_wolverine_distribution.cs +++ b/src/Persistence/MartenTests/TestHelpers/catch_up_when_using_wolverine_distribution.cs @@ -49,6 +49,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/TestHelpers/reset_data_first.cs b/src/Persistence/MartenTests/TestHelpers/reset_data_first.cs index 7d818251c..911926912 100644 --- a/src/Persistence/MartenTests/TestHelpers/reset_data_first.cs +++ b/src/Persistence/MartenTests/TestHelpers/reset_data_first.cs @@ -22,6 +22,10 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(AppendLettersHandler)) + .IncludeType(typeof(AppendLetters2Handler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); @@ -55,6 +59,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/TestHelpers/second_stage_waiting.cs b/src/Persistence/MartenTests/TestHelpers/second_stage_waiting.cs index 250ec4541..36ffa6666 100644 --- a/src/Persistence/MartenTests/TestHelpers/second_stage_waiting.cs +++ b/src/Persistence/MartenTests/TestHelpers/second_stage_waiting.cs @@ -26,6 +26,11 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(AppendLettersHandler)) + .IncludeType(typeof(AppendLetters2Handler)) + .IncludeType(typeof(GotFiveHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); @@ -59,6 +64,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/TestHelpers/wait_for_non_stale_data_after.cs b/src/Persistence/MartenTests/TestHelpers/wait_for_non_stale_data_after.cs index 23c1673aa..871d19769 100644 --- a/src/Persistence/MartenTests/TestHelpers/wait_for_non_stale_data_after.cs +++ b/src/Persistence/MartenTests/TestHelpers/wait_for_non_stale_data_after.cs @@ -22,6 +22,10 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(AppendLettersHandler)) + .IncludeType(typeof(AppendLetters2Handler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); @@ -55,6 +59,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/basic_marten_integration.cs b/src/Persistence/MartenTests/basic_marten_integration.cs index 1a6522908..b94907f7a 100644 --- a/src/Persistence/MartenTests/basic_marten_integration.cs +++ b/src/Persistence/MartenTests/basic_marten_integration.cs @@ -3,12 +3,10 @@ using JasperFx.Core.Reflection; using Marten; using Marten.Internal.Sessions; -using Marten.Storage; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using JasperFx.Resources; using Shouldly; -using Weasel.Core; using Wolverine; using Wolverine.Marten; using Wolverine.Marten.Publishing; @@ -33,6 +31,8 @@ public async Task InitializeAsync() o.AutoCreateSchemaObjects = AutoCreate.All; }).UseLightweightSessions().IntegrateWithWolverine(); + opts.Discovery.DisableConventionalDiscovery(); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); } @@ -68,6 +68,8 @@ public void override_schema_name() o.AutoCreateSchemaObjects = AutoCreate.All; }).IntegrateWithWolverine(x => x.MessageStorageSchemaName = "wolverine"); + opts.Discovery.DisableConventionalDiscovery(); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddResourceSetupOnStartup(); }).Start(); diff --git a/src/Persistence/MartenTests/batch_processing.cs b/src/Persistence/MartenTests/batch_processing.cs index 54318dbad..5b2dc55c1 100644 --- a/src/Persistence/MartenTests/batch_processing.cs +++ b/src/Persistence/MartenTests/batch_processing.cs @@ -6,10 +6,6 @@ using Shouldly; using Wolverine; using Wolverine.Marten; -using Wolverine.Runtime; -using Wolverine.Runtime.Batching; -using Wolverine.Runtime.Handlers; -using Wolverine.Runtime.Routing; using Wolverine.Tracking; namespace MartenTests; @@ -39,6 +35,11 @@ public async Task end_to_end_with_durable() batching.BatchSize = 8; batching.LocalExecutionQueueName = "items"; }).UseDurableInbox(); + + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(BatchItemHandler)); + opts.Durability.Mode = DurabilityMode.Solo; + }).StartAsync(); await theHost.CleanAllMartenDataAsync(); @@ -121,7 +122,11 @@ public async Task end_to_end_with_tenancy() batching.TriggerTime = 1.Seconds(); batching.BatchSize = 8; batching.LocalExecutionQueueName = "items"; - }).UseDurableInbox(); + }).UseDurableInbox(); + + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(BatchItemHandler)); + opts.Durability.Mode = DurabilityMode.Solo; }).StartAsync(); var item1 = new BatchItem("one", Guid.NewGuid()); diff --git a/src/Persistence/MartenTests/batch_querying_support.cs b/src/Persistence/MartenTests/batch_querying_support.cs index 54ac31cf1..68510e90e 100644 --- a/src/Persistence/MartenTests/batch_querying_support.cs +++ b/src/Persistence/MartenTests/batch_querying_support.cs @@ -27,6 +27,10 @@ public async Task InitializeAsync() }).UseLightweightSessions().IntegrateWithWolverine(); + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(DoStuffWithDocsHandler)) + .IncludeType(typeof(ReadAggregateWithDocsHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddResourceSetupOnStartup(); }).StartAsync(); } diff --git a/src/Persistence/MartenTests/concurrency_resilient_sharded_processing.cs b/src/Persistence/MartenTests/concurrency_resilient_sharded_processing.cs index f6ba73440..196569cbf 100644 --- a/src/Persistence/MartenTests/concurrency_resilient_sharded_processing.cs +++ b/src/Persistence/MartenTests/concurrency_resilient_sharded_processing.cs @@ -53,6 +53,7 @@ public async Task hammer_it_with_lots_of_messages_against_buffered() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(LetterMessageHandler)); opts.Services.AddMarten(m => @@ -99,6 +100,7 @@ public async Task hammer_it_with_lots_of_messages_against_buffered_with_inferred using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(LetterMessageHandler)); opts.Services.AddMarten(m => @@ -153,6 +155,7 @@ public async Task hammer_it_with_lots_of_messages_against_buffered_and_sharded_m using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(LetterMessageHandler)); // Telling Wolverine how to assign a GroupId to a message, that we'll use @@ -197,6 +200,7 @@ public async Task hammer_it_with_lots_of_messages_against_durable() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Durability.Mode = DurabilityMode.Solo; opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(LetterMessageHandler)); // Telling Wolverine how to assign a GroupId to a message, that we'll use diff --git a/src/Persistence/MartenTests/end_to_end_publish_messages_through_marten_to_wolverine.cs b/src/Persistence/MartenTests/end_to_end_publish_messages_through_marten_to_wolverine.cs index e369cee0a..bb3504736 100644 --- a/src/Persistence/MartenTests/end_to_end_publish_messages_through_marten_to_wolverine.cs +++ b/src/Persistence/MartenTests/end_to_end_publish_messages_through_marten_to_wolverine.cs @@ -36,6 +36,9 @@ public async Task can_publish_messages_through_outbox() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(GotBHandler)) + .IncludeType(typeof(CustomerChangedHandler)); opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => @@ -80,6 +83,8 @@ public async Task can_publish_messages_through_outbox_running_inline() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(GotBHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.DisableNpgsqlLogging = true; @@ -124,6 +129,8 @@ public async Task can_publish_messages_through_outbox_with_tenancy() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(GotBHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); @@ -173,6 +180,8 @@ public async Task can_publish_messages_through_outbox_running_inline_from_within using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(GotBHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); @@ -303,6 +312,9 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(CustomerChangedHandler)) + .IncludeType(typeof(GotBHandler)); opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => @@ -321,9 +333,10 @@ public async Task InitializeAsync() }).StartAsync(); } - public Task DisposeAsync() + public async Task DisposeAsync() { - return _host.StopAsync(); + await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/event_streaming.cs b/src/Persistence/MartenTests/event_streaming.cs index 347814ea7..746d68678 100644 --- a/src/Persistence/MartenTests/event_streaming.cs +++ b/src/Persistence/MartenTests/event_streaming.cs @@ -150,7 +150,7 @@ public async Task event_should_be_published_from_sender_to_receiver() [Fact] public async Task execution_of_forwarded_events_can_be_awaited_from_tests() { - var host = await Host.CreateDefaultBuilder() + using var host = await Host.CreateDefaultBuilder() .UseWolverine() .ConfigureServices(services => { @@ -216,12 +216,8 @@ public class TriggeredEvent public class TriggerEventHandler { - private static readonly TaskCompletionSource _source = new(); - public static Task Waiter => _source.Task; - public void Handle(TriggeredEvent message) { - _source.SetResult(message); } #region sample_execution_of_forwarded_events_second_message_to_fourth_event diff --git a/src/Persistence/MartenTests/fetch_specifications_tests.cs b/src/Persistence/MartenTests/fetch_specifications_tests.cs index 61a1e7d7a..df4cbced4 100644 --- a/src/Persistence/MartenTests/fetch_specifications_tests.cs +++ b/src/Persistence/MartenTests/fetch_specifications_tests.cs @@ -31,6 +31,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(LoadOneNoteHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); @@ -53,6 +55,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } private IDocumentStore Store => _host.Services.GetRequiredService(); diff --git a/src/Persistence/MartenTests/global_entity_defaults.cs b/src/Persistence/MartenTests/global_entity_defaults.cs index fc317caae..b7b8d5c1a 100644 --- a/src/Persistence/MartenTests/global_entity_defaults.cs +++ b/src/Persistence/MartenTests/global_entity_defaults.cs @@ -19,6 +19,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(GlobalThingHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Policies.AutoApplyTransactions(); // Set global defaults @@ -36,6 +38,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/handler_actions_with_implied_marten_operations.cs b/src/Persistence/MartenTests/handler_actions_with_implied_marten_operations.cs index a31433588..a6af49f2c 100644 --- a/src/Persistence/MartenTests/handler_actions_with_implied_marten_operations.cs +++ b/src/Persistence/MartenTests/handler_actions_with_implied_marten_operations.cs @@ -23,6 +23,10 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(AppendManyNamedDocumentsHandler)) + .IncludeType(typeof(MartenCommandHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services .AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); diff --git a/src/Persistence/MartenTests/handler_actions_with_returned_StartStream.cs b/src/Persistence/MartenTests/handler_actions_with_returned_StartStream.cs index affb429a9..19a61c07d 100644 --- a/src/Persistence/MartenTests/handler_actions_with_returned_StartStream.cs +++ b/src/Persistence/MartenTests/handler_actions_with_returned_StartStream.cs @@ -23,6 +23,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(StartStreamMessageHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services .AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); @@ -68,6 +70,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(StartStreamMessageHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services .AddMarten(m => { diff --git a/src/Persistence/MartenTests/idempotency_check_in_marten_envelope_transaction.cs b/src/Persistence/MartenTests/idempotency_check_in_marten_envelope_transaction.cs index 3ff0360b3..599dfd7ba 100644 --- a/src/Persistence/MartenTests/idempotency_check_in_marten_envelope_transaction.cs +++ b/src/Persistence/MartenTests/idempotency_check_in_marten_envelope_transaction.cs @@ -26,6 +26,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(MaybeIdempotentHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); @@ -39,6 +41,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] @@ -99,6 +102,8 @@ public async Task happy_and_sad_path(IdempotencyStyle idempotency) using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(MaybeIdempotentHandler)); + opts.Durability.Mode = DurabilityMode.Solo; // TODO -- make this the default opts.OnException().Discard(); opts.Policies.AutoApplyTransactions(idempotency); @@ -140,6 +145,8 @@ public async Task happy_and_sad_path_with_message_and_destination_tracking(Idemp using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(MaybeIdempotentHandler)); + opts.Durability.Mode = DurabilityMode.Solo; // TODO -- make this the default opts.OnException().Discard(); opts.Policies.AutoApplyTransactions(idempotency); diff --git a/src/Persistence/MartenTests/marten_tracking_diagnostics.cs b/src/Persistence/MartenTests/marten_tracking_diagnostics.cs index b1cac554e..a3261684f 100644 --- a/src/Persistence/MartenTests/marten_tracking_diagnostics.cs +++ b/src/Persistence/MartenTests/marten_tracking_diagnostics.cs @@ -36,6 +36,8 @@ public async Task save_changes_events_baked_into_codegen_when_outbox_diagnostics using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(MartenTrackingHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString).IntegrateWithWolverine(); // AutoApplyTransactions wires the Marten persistence frame provider's // ApplyTransactionSupport onto chains that touch Marten — that's what @@ -65,6 +67,8 @@ public async Task save_changes_events_absent_from_codegen_when_outbox_diagnostic using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(MartenTrackingHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString).IntegrateWithWolverine(); opts.Policies.AutoApplyTransactions(); // OutboxDiagnosticsEnabled left at its default (false) diff --git a/src/Persistence/MartenTests/missing_data_handling_with_entity_attributes.cs b/src/Persistence/MartenTests/missing_data_handling_with_entity_attributes.cs index 525541e31..e2aaf085a 100644 --- a/src/Persistence/MartenTests/missing_data_handling_with_entity_attributes.cs +++ b/src/Persistence/MartenTests/missing_data_handling_with_entity_attributes.cs @@ -21,6 +21,10 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(GuidThingHandler)) + .IncludeType(typeof(ThingHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Policies.AutoApplyTransactions(); opts.Services.AddMarten(m => { @@ -34,6 +38,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/non_transactional_attribute_opt_out.cs b/src/Persistence/MartenTests/non_transactional_attribute_opt_out.cs index bc866fe34..0af95cf54 100644 --- a/src/Persistence/MartenTests/non_transactional_attribute_opt_out.cs +++ b/src/Persistence/MartenTests/non_transactional_attribute_opt_out.cs @@ -18,6 +18,11 @@ public async Task handler_with_non_transactional_attribute_should_not_be_transac using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(TransactionalCommandHandler)) + .IncludeType(typeof(NonTransactionalClassCommandHandler)) + .IncludeType(typeof(NonTransactionalCommandHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); @@ -38,6 +43,9 @@ public async Task handler_without_non_transactional_attribute_should_still_be_tr using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(TransactionalCommandHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); @@ -58,6 +66,9 @@ public async Task non_transactional_attribute_on_handler_class_should_opt_out() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery() + .IncludeType(typeof(NonTransactionalClassCommandHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(Servers.PostgresConnectionString) .IntegrateWithWolverine(); diff --git a/src/Persistence/MartenTests/strong_typed_identifiers.cs b/src/Persistence/MartenTests/strong_typed_identifiers.cs index 77b96e01d..880d324e8 100644 --- a/src/Persistence/MartenTests/strong_typed_identifiers.cs +++ b/src/Persistence/MartenTests/strong_typed_identifiers.cs @@ -18,6 +18,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(KnobHandler)); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services.AddMarten(m => { m.Connection(Servers.PostgresConnectionString); @@ -29,6 +31,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/MartenTests/transactional_frame_end_to_end.cs b/src/Persistence/MartenTests/transactional_frame_end_to_end.cs index 7a4d1085c..6f0fee385 100644 --- a/src/Persistence/MartenTests/transactional_frame_end_to_end.cs +++ b/src/Persistence/MartenTests/transactional_frame_end_to_end.cs @@ -67,6 +67,8 @@ private static async Task Using_CommandsAreTransactional() using var host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(CreateDocCommand2Handler)); + opts.Durability.Mode = DurabilityMode.Solo; // And actually use the policy opts.Policies.Add(); }).StartAsync(); diff --git a/src/Persistence/MartenTests/using_an_aggregate_that_handles_commands.cs b/src/Persistence/MartenTests/using_an_aggregate_that_handles_commands.cs index c68883c3d..41717b632 100644 --- a/src/Persistence/MartenTests/using_an_aggregate_that_handles_commands.cs +++ b/src/Persistence/MartenTests/using_an_aggregate_that_handles_commands.cs @@ -28,6 +28,8 @@ public using_an_aggregate_that_handles_commands() theHost = Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery(); + opts.Durability.Mode = DurabilityMode.Solo; opts.ApplicationAssembly = GetType().Assembly; opts.Services.AddMarten(o => { diff --git a/src/Persistence/MartenTests/validate_empty_stream_key_on_start_stream.cs b/src/Persistence/MartenTests/validate_empty_stream_key_on_start_stream.cs index 6045f5473..b863c7e92 100644 --- a/src/Persistence/MartenTests/validate_empty_stream_key_on_start_stream.cs +++ b/src/Persistence/MartenTests/validate_empty_stream_key_on_start_stream.cs @@ -22,6 +22,8 @@ public async Task InitializeAsync() _host = await Host.CreateDefaultBuilder() .UseWolverine(opts => { + opts.Discovery.DisableConventionalDiscovery(); + opts.Durability.Mode = DurabilityMode.Solo; opts.Services .AddMarten(m => { diff --git a/src/Persistence/MySql/MySqlTests/MultiTenancy/MySqlMultiTenancyContext.cs b/src/Persistence/MySql/MySqlTests/MultiTenancy/MySqlMultiTenancyContext.cs index 70f8564a7..16eecf02e 100644 --- a/src/Persistence/MySql/MySqlTests/MultiTenancy/MySqlMultiTenancyContext.cs +++ b/src/Persistence/MySql/MySqlTests/MultiTenancy/MySqlMultiTenancyContext.cs @@ -42,6 +42,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await theHost.StopAsync(); + theHost.Dispose(); } private async Task CreateDatabaseIfNotExists(MySqlConnection conn, string databaseName) @@ -49,13 +50,13 @@ private async Task CreateDatabaseIfNotExists(MySqlConnection conn, strin var builder = new MySqlConnectionStringBuilder(Servers.MySqlConnectionString); // Check if database exists - var checkCmd = conn.CreateCommand(); + await using var checkCmd = conn.CreateCommand(); checkCmd.CommandText = $"SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '{databaseName}'"; var exists = await checkCmd.ExecuteScalarAsync() != null; if (!exists) { - var createCmd = conn.CreateCommand(); + await using var createCmd = conn.CreateCommand(); createCmd.CommandText = $"CREATE DATABASE {databaseName}"; await createCmd.ExecuteNonQueryAsync(); } @@ -70,7 +71,7 @@ private async Task cleanItems(string connectionString) await conn.OpenAsync(); // Create items table if not exists - var createTableCmd = conn.CreateCommand(); + await using var createTableCmd = conn.CreateCommand(); createTableCmd.CommandText = @" CREATE TABLE IF NOT EXISTS items ( Id BINARY(16) PRIMARY KEY, @@ -79,7 +80,7 @@ Name VARCHAR(255) await createTableCmd.ExecuteNonQueryAsync(); // Clean the table - var deleteCmd = conn.CreateCommand(); + await using var deleteCmd = conn.CreateCommand(); deleteCmd.CommandText = "DELETE FROM items"; await deleteCmd.ExecuteNonQueryAsync(); diff --git a/src/Persistence/MySql/MySqlTests/Sagas/configuring_saga_table_storage.cs b/src/Persistence/MySql/MySqlTests/Sagas/configuring_saga_table_storage.cs index 11d00b55c..1b0821a38 100644 --- a/src/Persistence/MySql/MySqlTests/Sagas/configuring_saga_table_storage.cs +++ b/src/Persistence/MySql/MySqlTests/Sagas/configuring_saga_table_storage.cs @@ -49,7 +49,7 @@ private static async Task dropSchemaAsync() await conn.OpenAsync(); // Drop and recreate the schema - var dropCmd = conn.CreateCommand(); + await using var dropCmd = conn.CreateCommand(); dropCmd.CommandText = "DROP DATABASE IF EXISTS color_sagas; CREATE DATABASE color_sagas;"; await dropCmd.ExecuteNonQueryAsync(); diff --git a/src/Persistence/MySql/MySqlTests/Sagas/saga_storage_operations.cs b/src/Persistence/MySql/MySqlTests/Sagas/saga_storage_operations.cs index 907ecaad3..dcf1dbb01 100644 --- a/src/Persistence/MySql/MySqlTests/Sagas/saga_storage_operations.cs +++ b/src/Persistence/MySql/MySqlTests/Sagas/saga_storage_operations.cs @@ -138,7 +138,7 @@ public async Task concurrency_exception_when_version_does_not_match() await conn.OpenAsync(); // Clean up the table - var cleanCmd = conn.CreateCommand(); + await using var cleanCmd = conn.CreateCommand(); cleanCmd.CommandText = "DELETE FROM lightweight_sagas.mysqllightweightsaga_saga"; await cleanCmd.ExecuteNonQueryAsync(); diff --git a/src/Persistence/MySql/MySqlTests/Transport/end_to_end_from_scratch.cs b/src/Persistence/MySql/MySqlTests/Transport/end_to_end_from_scratch.cs index fddcae702..9ea40ad47 100644 --- a/src/Persistence/MySql/MySqlTests/Transport/end_to_end_from_scratch.cs +++ b/src/Persistence/MySql/MySqlTests/Transport/end_to_end_from_scratch.cs @@ -51,6 +51,8 @@ public async Task DisposeAsync() { await Api.StopAsync(); await UI.StopAsync(); + Api.Dispose(); + UI.Dispose(); } [Fact] diff --git a/src/Persistence/Oracle/OracleTests/Agents/health_check_timestamp_round_trip.cs b/src/Persistence/Oracle/OracleTests/Agents/health_check_timestamp_round_trip.cs index f82d4f673..481df3081 100644 --- a/src/Persistence/Oracle/OracleTests/Agents/health_check_timestamp_round_trip.cs +++ b/src/Persistence/Oracle/OracleTests/Agents/health_check_timestamp_round_trip.cs @@ -54,7 +54,7 @@ await conn.CreateCommand("ALTER SESSION SET TIME_ZONE = '+05:00'") // Insert a node row using the column DEFAULT for health_check (the path // that NodeAgentController hits via PersistAsync on first heartbeat). - var insertCmd = conn.CreateCommand( + await using var insertCmd = conn.CreateCommand( "INSERT INTO WOLVERINE.WOLVERINE_NODES (id, uri, capabilities, description, version) " + "VALUES (:id, :uri, :capabilities, :description, :version)"); insertCmd.With("id", nodeId); diff --git a/src/Persistence/Oracle/OracleTests/Sagas/saga_storage_operations.cs b/src/Persistence/Oracle/OracleTests/Sagas/saga_storage_operations.cs index 2c17c3c92..4eed7025b 100644 --- a/src/Persistence/Oracle/OracleTests/Sagas/saga_storage_operations.cs +++ b/src/Persistence/Oracle/OracleTests/Sagas/saga_storage_operations.cs @@ -138,7 +138,7 @@ public async Task concurrency_exception_when_version_does_not_match() await conn.OpenAsync(); // Clean up the table - var cleanCmd = conn.CreateCommand( + await using var cleanCmd = conn.CreateCommand( $"DELETE FROM WOLVERINE.{nameof(OracleLightweightSaga).ToUpperInvariant()}_SAGA"); await cleanCmd.ExecuteNonQueryAsync(); diff --git a/src/Persistence/Oracle/OracleTests/Transport/basic_functionality.cs b/src/Persistence/Oracle/OracleTests/Transport/basic_functionality.cs index 669066694..6d00a3f13 100644 --- a/src/Persistence/Oracle/OracleTests/Transport/basic_functionality.cs +++ b/src/Persistence/Oracle/OracleTests/Transport/basic_functionality.cs @@ -44,14 +44,14 @@ public async Task InitializeAsync() // Drop queue tables if they exist try { - var cmd = conn.CreateCommand("DROP TABLE WOLVERINE.WOLVERINE_QUEUE_ONE CASCADE CONSTRAINTS"); + await using var cmd = conn.CreateCommand("DROP TABLE WOLVERINE.WOLVERINE_QUEUE_ONE CASCADE CONSTRAINTS"); await cmd.ExecuteNonQueryAsync(); } catch (OracleException) { /* table doesn't exist */ } try { - var cmd = conn.CreateCommand("DROP TABLE WOLVERINE.WOLVERINE_QUEUE_ONE_SCHEDULED CASCADE CONSTRAINTS"); + await using var cmd = conn.CreateCommand("DROP TABLE WOLVERINE.WOLVERINE_QUEUE_ONE_SCHEDULED CASCADE CONSTRAINTS"); await cmd.ExecuteNonQueryAsync(); } catch (OracleException) { /* table doesn't exist */ } diff --git a/src/Persistence/PersistenceTests/ModularMonoliths/end_to_end_modular_monolith.cs b/src/Persistence/PersistenceTests/ModularMonoliths/end_to_end_modular_monolith.cs index 405757597..cd747bfa5 100644 --- a/src/Persistence/PersistenceTests/ModularMonoliths/end_to_end_modular_monolith.cs +++ b/src/Persistence/PersistenceTests/ModularMonoliths/end_to_end_modular_monolith.cs @@ -118,9 +118,10 @@ private async Task withItemsTable() } } - public Task DisposeAsync() + public async Task DisposeAsync() { - return Host.StopAsync(); + await Host.StopAsync(); + Host.Dispose(); } private async Task CreateDatabaseIfNotExists(NpgsqlConnection conn, string databaseName) diff --git a/src/Persistence/PersistenceTests/ModularMonoliths/registration_of_message_stores.cs b/src/Persistence/PersistenceTests/ModularMonoliths/registration_of_message_stores.cs index 9f5a1ac6c..2cb039466 100644 --- a/src/Persistence/PersistenceTests/ModularMonoliths/registration_of_message_stores.cs +++ b/src/Persistence/PersistenceTests/ModularMonoliths/registration_of_message_stores.cs @@ -76,6 +76,7 @@ async Task IAsyncLifetime.DisposeAsync() if (_host != null) { await _host.StopAsync(); + _host.Dispose(); } } diff --git a/src/Persistence/PersistenceTests/Postgresql/Transport/data_operations.cs b/src/Persistence/PersistenceTests/Postgresql/Transport/data_operations.cs index b5d5e011b..f84f8759b 100644 --- a/src/Persistence/PersistenceTests/Postgresql/Transport/data_operations.cs +++ b/src/Persistence/PersistenceTests/Postgresql/Transport/data_operations.cs @@ -75,6 +75,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/PolecatTests/AggregateHandlerWorkflow/strong_named_identifiers.cs b/src/Persistence/PolecatTests/AggregateHandlerWorkflow/strong_named_identifiers.cs index 6f2bf61f9..93448d09b 100644 --- a/src/Persistence/PolecatTests/AggregateHandlerWorkflow/strong_named_identifiers.cs +++ b/src/Persistence/PolecatTests/AggregateHandlerWorkflow/strong_named_identifiers.cs @@ -36,6 +36,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await theHost.StopAsync(); + theHost.Dispose(); } [Fact] diff --git a/src/Persistence/PolecatTests/Sagas/multiple_sagas_for_same_message.cs b/src/Persistence/PolecatTests/Sagas/multiple_sagas_for_same_message.cs index 09f93938b..d83eccf63 100644 --- a/src/Persistence/PolecatTests/Sagas/multiple_sagas_for_same_message.cs +++ b/src/Persistence/PolecatTests/Sagas/multiple_sagas_for_same_message.cs @@ -40,6 +40,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/PolecatTests/Sagas/not_found_usage.cs b/src/Persistence/PolecatTests/Sagas/not_found_usage.cs index 0a43b6998..2c255d339 100644 --- a/src/Persistence/PolecatTests/Sagas/not_found_usage.cs +++ b/src/Persistence/PolecatTests/Sagas/not_found_usage.cs @@ -37,6 +37,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/PolecatTests/missing_data_handling_with_entity_attributes.cs b/src/Persistence/PolecatTests/missing_data_handling_with_entity_attributes.cs index 70b14a07f..691848e96 100644 --- a/src/Persistence/PolecatTests/missing_data_handling_with_entity_attributes.cs +++ b/src/Persistence/PolecatTests/missing_data_handling_with_entity_attributes.cs @@ -35,6 +35,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/PolecatTests/strong_typed_identifiers.cs b/src/Persistence/PolecatTests/strong_typed_identifiers.cs index 86a09d4e0..fa237dd72 100644 --- a/src/Persistence/PolecatTests/strong_typed_identifiers.cs +++ b/src/Persistence/PolecatTests/strong_typed_identifiers.cs @@ -33,6 +33,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } [Fact] diff --git a/src/Persistence/PostgresqlTests/MultiTenancy/MultiTenancyContext.cs b/src/Persistence/PostgresqlTests/MultiTenancy/MultiTenancyContext.cs index ef585f6b2..44fa9f9c8 100644 --- a/src/Persistence/PostgresqlTests/MultiTenancy/MultiTenancyContext.cs +++ b/src/Persistence/PostgresqlTests/MultiTenancy/MultiTenancyContext.cs @@ -54,6 +54,7 @@ public async Task SchemaTables(IDatabase database) public async Task DisposeAsync() { await theHost.StopAsync(); + theHost.Dispose(); } private async Task CreateDatabaseIfNotExists(NpgsqlConnection conn, string databaseName) diff --git a/src/Persistence/PostgresqlTests/MultiTenancy/multi_tenant_durability_agents.cs b/src/Persistence/PostgresqlTests/MultiTenancy/multi_tenant_durability_agents.cs index a66c9d6f2..b8beea3c2 100644 --- a/src/Persistence/PostgresqlTests/MultiTenancy/multi_tenant_durability_agents.cs +++ b/src/Persistence/PostgresqlTests/MultiTenancy/multi_tenant_durability_agents.cs @@ -168,7 +168,7 @@ await bus.ScheduleAsync(new TenantScheduledMessage(blueId), 2.Seconds(), private static async Task Poll(TimeSpan timeout, Func condition) { - var cts = new CancellationTokenSource(timeout); + using var cts = new CancellationTokenSource(timeout); while (!cts.IsCancellationRequested) { if (condition()) return true; diff --git a/src/Persistence/PostgresqlTests/Transport/end_to_end_from_scratch.cs b/src/Persistence/PostgresqlTests/Transport/end_to_end_from_scratch.cs index 7dae7a9d0..023017354 100644 --- a/src/Persistence/PostgresqlTests/Transport/end_to_end_from_scratch.cs +++ b/src/Persistence/PostgresqlTests/Transport/end_to_end_from_scratch.cs @@ -51,6 +51,8 @@ public async Task DisposeAsync() { await Api.StopAsync(); await UI.StopAsync(); + Api.Dispose(); + UI.Dispose(); } [Fact] diff --git a/src/Persistence/PostgresqlTests/Transport/inbox_outbox_usage.cs b/src/Persistence/PostgresqlTests/Transport/inbox_outbox_usage.cs index ec28531a1..dbbdd3bc7 100644 --- a/src/Persistence/PostgresqlTests/Transport/inbox_outbox_usage.cs +++ b/src/Persistence/PostgresqlTests/Transport/inbox_outbox_usage.cs @@ -58,6 +58,7 @@ public async Task schedule_a_ping() public async Task DisposeAsync() { await _host.StopAsync(); + _host.Dispose(); } } diff --git a/src/Persistence/PostgresqlTests/Transport/sticky_listener_health_tests.cs b/src/Persistence/PostgresqlTests/Transport/sticky_listener_health_tests.cs index 30d78349c..bef190d6b 100644 --- a/src/Persistence/PostgresqlTests/Transport/sticky_listener_health_tests.cs +++ b/src/Persistence/PostgresqlTests/Transport/sticky_listener_health_tests.cs @@ -88,7 +88,7 @@ public async Task InitializeAsync() await using var conn = await _dataSource.OpenConnectionAsync(); try { - var drop = conn.CreateCommand(); + await using var drop = conn.CreateCommand(); drop.CommandText = $"DROP TABLE IF EXISTS {_tableName} CASCADE"; await drop.ExecuteNonQueryAsync(); } @@ -105,7 +105,7 @@ public async Task DisposeAsync() await using var conn = await _dataSource.OpenConnectionAsync(); try { - var drop = conn.CreateCommand(); + await using var drop = conn.CreateCommand(); drop.CommandText = $"DROP TABLE IF EXISTS {_tableName} CASCADE"; await drop.ExecuteNonQueryAsync(); } @@ -140,7 +140,7 @@ public async Task get_queue_depth_reflects_inserted_rows() { for (var i = 0; i < 7; i++) { - var insert = conn.CreateCommand(); + await using var insert = conn.CreateCommand(); insert.CommandText = $"INSERT INTO {_tableName} (id, body, message_type, keep_until) " + "VALUES (gen_random_uuid(), '\\x00'::bytea, 'TestMessage', null)"; diff --git a/src/Persistence/PostgresqlTests/bumping_stale_inbox_messages.cs b/src/Persistence/PostgresqlTests/bumping_stale_inbox_messages.cs index 01e44b508..cc54e9f4e 100644 --- a/src/Persistence/PostgresqlTests/bumping_stale_inbox_messages.cs +++ b/src/Persistence/PostgresqlTests/bumping_stale_inbox_messages.cs @@ -35,6 +35,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await theHost.StopAsync(); + theHost.Dispose(); } [Fact] diff --git a/src/Persistence/PostgresqlTests/bumping_stale_outbox_messages.cs b/src/Persistence/PostgresqlTests/bumping_stale_outbox_messages.cs index 212b0835c..17852eeec 100644 --- a/src/Persistence/PostgresqlTests/bumping_stale_outbox_messages.cs +++ b/src/Persistence/PostgresqlTests/bumping_stale_outbox_messages.cs @@ -35,6 +35,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await theHost.StopAsync(); + theHost.Dispose(); } [Fact] diff --git a/src/Persistence/SqlServerTests/MultiTenancy/MultiTenancyContext.cs b/src/Persistence/SqlServerTests/MultiTenancy/MultiTenancyContext.cs index 0e4fe5342..5af4a934e 100644 --- a/src/Persistence/SqlServerTests/MultiTenancy/MultiTenancyContext.cs +++ b/src/Persistence/SqlServerTests/MultiTenancy/MultiTenancyContext.cs @@ -41,6 +41,7 @@ public abstract class MultiTenancyContext : SqlServerContext, IAsyncLifetime public new async Task DisposeAsync() { await theHost.StopAsync(); + theHost.Dispose(); } private async Task CreateDatabaseIfNotExists(SqlConnection conn, string databaseName) @@ -60,7 +61,7 @@ private async Task CreateDatabaseIfNotExists(SqlConnection conn, string private static async Task DatabaseExistsAsync(SqlConnection conn, string databaseName) { - var cmd = conn.CreateCommand($"SELECT DB_ID(@databaseName)"); + await using var cmd = conn.CreateCommand($"SELECT DB_ID(@databaseName)"); cmd.Parameters.AddWithValue("@databaseName", databaseName); var result = await cmd.ExecuteScalarAsync(); return result != null && result != DBNull.Value; diff --git a/src/Persistence/SqlServerTests/bumping_stale_inbox_messages.cs b/src/Persistence/SqlServerTests/bumping_stale_inbox_messages.cs index 789cdfa7e..201794232 100644 --- a/src/Persistence/SqlServerTests/bumping_stale_inbox_messages.cs +++ b/src/Persistence/SqlServerTests/bumping_stale_inbox_messages.cs @@ -35,6 +35,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await theHost.StopAsync(); + theHost.Dispose(); } [Fact] diff --git a/src/Persistence/SqlServerTests/bumping_stale_outbox_messages.cs b/src/Persistence/SqlServerTests/bumping_stale_outbox_messages.cs index 9477315fe..5571ff422 100644 --- a/src/Persistence/SqlServerTests/bumping_stale_outbox_messages.cs +++ b/src/Persistence/SqlServerTests/bumping_stale_outbox_messages.cs @@ -35,6 +35,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { await theHost.StopAsync(); + theHost.Dispose(); } [Fact] diff --git a/src/Persistence/SqlServerTests/solo_mode_does_not_release_orphaned_messages.cs b/src/Persistence/SqlServerTests/solo_mode_does_not_release_orphaned_messages.cs index dbc5bbc8b..cdaedc76c 100644 --- a/src/Persistence/SqlServerTests/solo_mode_does_not_release_orphaned_messages.cs +++ b/src/Persistence/SqlServerTests/solo_mode_does_not_release_orphaned_messages.cs @@ -44,6 +44,8 @@ public async Task DisposeAsync() { await theSoloHost.StopAsync(); await theBalancedHost.StopAsync(); + theSoloHost.Dispose(); + theBalancedHost.Dispose(); } [Fact] diff --git a/src/Persistence/SqliteTests/Sagas/saga_storage_operations.cs b/src/Persistence/SqliteTests/Sagas/saga_storage_operations.cs index b30a4979b..26ba648cf 100644 --- a/src/Persistence/SqliteTests/Sagas/saga_storage_operations.cs +++ b/src/Persistence/SqliteTests/Sagas/saga_storage_operations.cs @@ -39,7 +39,7 @@ public async Task InitializeAsync() await using var conn = await _dataSource.OpenConnectionAsync(); var table = (Table)_theSchema.Table; var sql = table.ToBasicCreateTableSql(); - var cmd = conn.CreateCommand(); + await using var cmd = conn.CreateCommand(); cmd.CommandText = sql; await cmd.ExecuteNonQueryAsync(); _theSchema.MarkAsChecked(); diff --git a/src/Persistence/SqliteTests/Transport/multi_tenancy_with_multiple_files.cs b/src/Persistence/SqliteTests/Transport/multi_tenancy_with_multiple_files.cs index c6cb1722b..60c7a5a4f 100644 --- a/src/Persistence/SqliteTests/Transport/multi_tenancy_with_multiple_files.cs +++ b/src/Persistence/SqliteTests/Transport/multi_tenancy_with_multiple_files.cs @@ -121,7 +121,7 @@ public async Task scheduled_messages_are_processed_in_tenant_files() private static async Task Poll(TimeSpan timeout, Func condition) { - var cts = new CancellationTokenSource(timeout); + using var cts = new CancellationTokenSource(timeout); while (!cts.IsCancellationRequested) { if (condition()) return true; diff --git a/src/Testing/BackPressureTests/Harness.cs b/src/Testing/BackPressureTests/Harness.cs index 4ee1c73e8..ec88df197 100644 --- a/src/Testing/BackPressureTests/Harness.cs +++ b/src/Testing/BackPressureTests/Harness.cs @@ -24,6 +24,12 @@ public void Cancel() { _cancellation.Cancel(); } + + public void Dispose() + { + _cancellation.Cancel(); + _cancellation.Dispose(); + } public void StartPublishing(int maximum = 5000, TimeSpan? time = null) { diff --git a/src/Testing/CoreTests/Acceptance/encryption_acceptance.cs b/src/Testing/CoreTests/Acceptance/encryption_acceptance.cs index 153d0c8bc..b62461add 100644 --- a/src/Testing/CoreTests/Acceptance/encryption_acceptance.cs +++ b/src/Testing/CoreTests/Acceptance/encryption_acceptance.cs @@ -357,7 +357,7 @@ public async Task wire_does_not_contain_plaintext_when_encryption_is_required() var receiverPort = PortFinder.GetAvailablePort(); var canary = "WIRE-CANARY-" + Guid.NewGuid().ToString("N"); - var captured = new MemoryStream(); + using var captured = new MemoryStream(); using var snifferCts = new CancellationTokenSource(); var sniffer = new TcpListener(IPAddress.Loopback, snifferPort); sniffer.Start(); diff --git a/src/Testing/CoreTests/Persistence/ClaimCheck/end_to_end_round_trip.cs b/src/Testing/CoreTests/Persistence/ClaimCheck/end_to_end_round_trip.cs index eea1b9fce..afd83f08b 100644 --- a/src/Testing/CoreTests/Persistence/ClaimCheck/end_to_end_round_trip.cs +++ b/src/Testing/CoreTests/Persistence/ClaimCheck/end_to_end_round_trip.cs @@ -43,6 +43,8 @@ public async Task DisposeAsync() { await _receiver.StopAsync(); await _publisher.StopAsync(); + _receiver.Dispose(); + _publisher.Dispose(); try { diff --git a/src/Testing/CoreTests/Runtime/Handlers/concurrent_saga_chain_compilation.cs b/src/Testing/CoreTests/Runtime/Handlers/concurrent_saga_chain_compilation.cs index 909bef758..e94f43ac7 100644 --- a/src/Testing/CoreTests/Runtime/Handlers/concurrent_saga_chain_compilation.cs +++ b/src/Testing/CoreTests/Runtime/Handlers/concurrent_saga_chain_compilation.cs @@ -28,7 +28,7 @@ public async Task concurrent_first_time_resolution_of_a_saga_handler_does_not_th var graph = host.Services.GetRequiredService(); - var start = new ManualResetEventSlim(false); + using var start = new ManualResetEventSlim(false); var failures = new ConcurrentBag(); var threads = new Thread[concurrency]; diff --git a/src/Testing/CoreTests/Transports/Sending/CircuitWatcherTester.cs b/src/Testing/CoreTests/Transports/Sending/CircuitWatcherTester.cs index 448c68d65..b62ecb839 100644 --- a/src/Testing/CoreTests/Transports/Sending/CircuitWatcherTester.cs +++ b/src/Testing/CoreTests/Transports/Sending/CircuitWatcherTester.cs @@ -9,7 +9,7 @@ public class CircuitWatcherTester //[Fact] //TODO -- CI doesn't like this one sometimes. public void ping_until_connected() { - var completed = new ManualResetEvent(false); + using var completed = new ManualResetEvent(false); var watcher = new CircuitWatcher(new StubCircuit(5, completed), default); @@ -64,6 +64,7 @@ public Task ResumeAsync(CancellationToken cancellationToken) public void Dispose() { + _completed.Dispose(); } public void Start(ISenderCallback callback) diff --git a/src/Testing/CoreTests/Transports/Tcp/WireProtocolFrameLimitTests.cs b/src/Testing/CoreTests/Transports/Tcp/WireProtocolFrameLimitTests.cs index 450c47914..a7edb6cf6 100644 --- a/src/Testing/CoreTests/Transports/Tcp/WireProtocolFrameLimitTests.cs +++ b/src/Testing/CoreTests/Transports/Tcp/WireProtocolFrameLimitTests.cs @@ -24,7 +24,7 @@ public async Task receive_async_rejects_oversize_frame_length() { WireProtocol.MaxFrameSize = 32 * 1024 * 1024; // explicit 32 MiB for this test - var ms = new MemoryStream(); + using var ms = new MemoryStream(); var writer = new BinaryWriter(ms); writer.Write(int.MaxValue); // 4-byte hostile length prefix writer.Flush(); @@ -56,7 +56,7 @@ public async Task receive_async_rejects_negative_frame_length() { WireProtocol.MaxFrameSize = 32 * 1024 * 1024; - var ms = new MemoryStream(); + using var ms = new MemoryStream(); var writer = new BinaryWriter(ms); writer.Write(-1); // negative length writer.Flush(); @@ -80,7 +80,7 @@ public async Task receive_async_accepts_zero_length_frame() { // A zero-length frame is a valid ping / no-op that ReceiveAsync handles // by returning immediately without error. - var ms = new MemoryStream(); + using var ms = new MemoryStream(); var writer = new BinaryWriter(ms); writer.Write(0); // zero length writer.Flush(); diff --git a/src/Testing/SlowTests/Bug_concurrency_with_global_partitioning.cs b/src/Testing/SlowTests/Bug_concurrency_with_global_partitioning.cs index 9a4a70abc..e40aeeee1 100644 --- a/src/Testing/SlowTests/Bug_concurrency_with_global_partitioning.cs +++ b/src/Testing/SlowTests/Bug_concurrency_with_global_partitioning.cs @@ -109,7 +109,8 @@ public async Task should_not_have_concurrency_exceptions_with_global_partitionin // Allow Kafka consumer group rebalancing to stabilize before sending messages await Task.Delay(15.Seconds()); - var cts = new CancellationTokenSource(30.Seconds()); + using var cts = new CancellationTokenSource(30.Seconds()); + cts.CancelAfter(30.Seconds()); // Simulate 6 institutions publishing concurrently, spreading across hosts var institutionIds = Enumerable.Range(1, 6) diff --git a/src/Testing/Wolverine.ComplianceTests/LeadershipElectionCompliance.cs b/src/Testing/Wolverine.ComplianceTests/LeadershipElectionCompliance.cs index 1e6b8c192..b7cb74fa0 100644 --- a/src/Testing/Wolverine.ComplianceTests/LeadershipElectionCompliance.cs +++ b/src/Testing/Wolverine.ComplianceTests/LeadershipElectionCompliance.cs @@ -151,7 +151,7 @@ public async Task singular_agent_is_only_running_on_one() var uri = new Uri("simple://"); - var cancellation = new CancellationTokenSource(); + using var cancellation = new CancellationTokenSource(); cancellation.CancelAfter(15.Seconds()); while (!cancellation.IsCancellationRequested && !_hosts.Any(x => x.RunningAgents().Contains(uri))) { @@ -361,7 +361,7 @@ await _originalHost.WaitUntilAssignmentsChangeTo(w => var expectedNodeNumbers = nodes.Select(x => x.NodeNumber()).ToHashSet(); // Poll for delivery to all 3 nodes (control queue messages are not tracked) - var cancellation = new CancellationTokenSource(); + using var cancellation = new CancellationTokenSource(); cancellation.CancelAfter(15.Seconds()); while (!cancellation.IsCancellationRequested) { diff --git a/src/Testing/Wolverine.ComplianceTests/SimpleSingularAgent.cs b/src/Testing/Wolverine.ComplianceTests/SimpleSingularAgent.cs index 76e2981a6..3774fc146 100644 --- a/src/Testing/Wolverine.ComplianceTests/SimpleSingularAgent.cs +++ b/src/Testing/Wolverine.ComplianceTests/SimpleSingularAgent.cs @@ -33,6 +33,8 @@ private void execute(object? state) // This template method should be used to cleanly stop up your background service protected override Task stopAsync(CancellationToken cancellationToken) { + _cancellation.Cancel(); + _cancellation.Dispose(); _timer.SafeDispose(); return Task.CompletedTask; } diff --git a/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/Bugs/Bug_2078_pause_then_requeue.cs b/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/Bugs/Bug_2078_pause_then_requeue.cs index 3d73e6a82..422f2c4f1 100644 --- a/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/Bugs/Bug_2078_pause_then_requeue.cs +++ b/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/Bugs/Bug_2078_pause_then_requeue.cs @@ -101,7 +101,7 @@ public async Task pause_then_requeue_should_eventually_reprocess_message() private static async Task Poll(TimeSpan timeout, Func condition) { - var cts = new CancellationTokenSource(timeout); + using var cts = new CancellationTokenSource(timeout); while (!cts.IsCancellationRequested) { if (condition()) return true; diff --git a/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/end_to_end.cs b/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/end_to_end.cs index 08175bb7e..d8bb8b8a1 100644 --- a/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/end_to_end.cs +++ b/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/end_to_end.cs @@ -225,7 +225,7 @@ public async Task send_message_to_and_receive_through_rabbitmq_with_inline_recei await publisher.SendAsync(new ColorChosen { Name = "blue" }); } - var cancellation = new CancellationTokenSource(30.Seconds()); + using var cancellation = new CancellationTokenSource(30.Seconds()); var queue = receiver.Get().Endpoints.EndpointByName(queueName).ShouldBeOfType(); while (!cancellation.IsCancellationRequested && await queue.QueuedCountAsync() > 0) @@ -272,7 +272,7 @@ public async Task send_message_to_and_receive_through_rabbitmq_with_inline_recei await publisher.SendAsync(new ColorChosen { Name = "blue" }); } - var cancellation = new CancellationTokenSource(30.Seconds()); + using var cancellation = new CancellationTokenSource(30.Seconds()); var queue = receiver.Get().Endpoints.EndpointByName(queueName).ShouldBeOfType(); while (!cancellation.IsCancellationRequested && await queue.QueuedCountAsync() > 0) @@ -321,7 +321,7 @@ public async Task send_message_to_and_receive_through_rabbitmq_with_inline_recei await publisher.SendAsync(new ColorChosen { Name = "blue" }); } - var cancellation = new CancellationTokenSource(30.Seconds()); + using var cancellation = new CancellationTokenSource(30.Seconds()); var queue = receiver.Get().Endpoints.EndpointByName(queueName).ShouldBeOfType(); while (!cancellation.IsCancellationRequested && await queue.QueuedCountAsync() > 0) diff --git a/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/end_to_end_with_named_broker.cs b/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/end_to_end_with_named_broker.cs index 397fb3579..a703dbdcc 100644 --- a/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/end_to_end_with_named_broker.cs +++ b/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/end_to_end_with_named_broker.cs @@ -54,7 +54,7 @@ public async Task send_message_to_and_receive_through_rabbitmq_with_inline_recei await publisher.SendAsync(new ColorChosen { Name = "blue" }); } - var cancellation = new CancellationTokenSource(30.Seconds()); + using var cancellation = new CancellationTokenSource(30.Seconds()); var queue = receiver.Get().Endpoints.EndpointByName(queueName).ShouldBeOfType(); while (!cancellation.IsCancellationRequested && await queue.QueuedCountAsync() > 0) diff --git a/src/Wolverine.HealthChecks.Tests/WolverineBusHealthCheckTests.cs b/src/Wolverine.HealthChecks.Tests/WolverineBusHealthCheckTests.cs index e6c043105..aad09fe5b 100644 --- a/src/Wolverine.HealthChecks.Tests/WolverineBusHealthCheckTests.cs +++ b/src/Wolverine.HealthChecks.Tests/WolverineBusHealthCheckTests.cs @@ -22,7 +22,7 @@ private static IWolverineRuntime BuildRuntime(bool started, bool cancellationReq { var runtime = Substitute.For(); runtime.Options.Returns(new WolverineOptions { ServiceName = "test-service" }); - var cts = new CancellationTokenSource(); + using var cts = new CancellationTokenSource(); if (cancellationRequested) cts.Cancel(); runtime.Cancellation.Returns(cts.Token);