-
Notifications
You must be signed in to change notification settings - Fork 23
Adding Akka.Persistence health checks #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
ef0160b
c057da2
4ea9841
4be1301
264db74
dab033c
772060d
d3aa948
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,288 @@ | ||
| using System; | ||
| using Akka.Configuration; | ||
| using Akka.Hosting; | ||
| using Akka.Persistence.Journal; | ||
| using Akka.Util; | ||
| using FluentAssertions; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Akka.Persistence.Hosting.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Shared test resources for unified API specs | ||
| /// </summary> | ||
| public static class UnifiedApiTestResources | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests the "unified" Akka.Persistence.Hosting APIs and tries to get test coverage over the |
||
| { | ||
| // Mock journal options for testing | ||
| public sealed class TestJournalOptions : JournalOptions | ||
| { | ||
| public TestJournalOptions(bool isDefault = true) : base(isDefault) | ||
| { | ||
| Identifier = "test-journal"; | ||
| } | ||
|
|
||
| public override string Identifier { get; set; } | ||
|
|
||
| protected override Config InternalDefaultConfig => | ||
| ConfigurationFactory.ParseString(@" | ||
| akka.persistence.journal.test-journal { | ||
| class = ""Akka.Persistence.Journal.MemoryJournal, Akka.Persistence"" | ||
| plugin-dispatcher = ""akka.actor.default-dispatcher"" | ||
| }"); | ||
| } | ||
|
|
||
| // Mock snapshot options for testing | ||
| public sealed class TestSnapshotOptions : SnapshotOptions | ||
| { | ||
| public TestSnapshotOptions(bool isDefault = true) : base(isDefault) | ||
| { | ||
| Identifier = "test-snapshot"; | ||
| } | ||
|
|
||
| public override string Identifier { get; set; } | ||
|
|
||
| protected override Config InternalDefaultConfig => | ||
| ConfigurationFactory.ParseString(@" | ||
| akka.persistence.snapshot-store.test-snapshot { | ||
| class = ""Akka.Persistence.Snapshot.MemorySnapshotStore, Akka.Persistence"" | ||
| plugin-dispatcher = ""akka.actor.default-dispatcher"" | ||
| }"); | ||
| } | ||
|
|
||
| // Test event adapters | ||
| public sealed class TestEvent { } | ||
|
|
||
| public sealed class TestWriteAdapter : IWriteEventAdapter | ||
| { | ||
| public string Manifest(object evt) => string.Empty; | ||
| public object ToJournal(object evt) => evt; | ||
| } | ||
|
|
||
| public sealed class TestReadAdapter : IReadEventAdapter | ||
| { | ||
| public IEventSequence FromJournal(object evt, string manifest) | ||
| => new SingleEventSequence(evt); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test WithJournal(JournalOptions) without builder | ||
| /// </summary> | ||
| public sealed class JournalOptionsOnlySpec : Akka.Hosting.TestKit.TestKit | ||
| { | ||
| public JournalOptionsOnlySpec(ITestOutputHelper output) : base(output: output) { } | ||
|
|
||
| protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) | ||
| { | ||
| base.ConfigureServices(context, services); | ||
| services.AddHealthChecks(); | ||
| } | ||
|
|
||
| protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider) | ||
| { | ||
| var options = new UnifiedApiTestResources.TestJournalOptions { IsDefaultPlugin = true }; | ||
| builder.WithJournal(options); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WithJournal_should_configure_journal_options_only() | ||
| { | ||
| var config = Sys.Settings.Config; | ||
| config.GetString("akka.persistence.journal.plugin") | ||
| .Should().Be("akka.persistence.journal.test-journal"); | ||
| // The plugin should be configured even if class property isn't set in the minimal config | ||
| config.HasPath("akka.persistence.journal.test-journal") | ||
| .Should().BeTrue(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test WithJournal(JournalOptions, builder) with event adapters | ||
| /// </summary> | ||
| public sealed class JournalWithAdaptersSpec : Akka.Hosting.TestKit.TestKit | ||
| { | ||
| public JournalWithAdaptersSpec(ITestOutputHelper output) : base(output: output) { } | ||
|
|
||
| protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) | ||
| { | ||
| base.ConfigureServices(context, services); | ||
| services.AddHealthChecks(); | ||
| } | ||
|
|
||
| protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider) | ||
| { | ||
| var options = new UnifiedApiTestResources.TestJournalOptions { IsDefaultPlugin = true }; | ||
| builder.WithJournal(options, journal => journal | ||
| .AddWriteEventAdapter<UnifiedApiTestResources.TestWriteAdapter>("test-adapter", | ||
| new[] { typeof(UnifiedApiTestResources.TestEvent) }) | ||
| .AddReadEventAdapter<UnifiedApiTestResources.TestReadAdapter>("test-reader", | ||
| new[] { typeof(UnifiedApiTestResources.TestEvent) })); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WithJournal_with_builder_should_configure_options_and_adapters() | ||
| { | ||
| var config = Sys.Settings.Config; | ||
|
|
||
| // assert - journal is configured (checking that at least the path exists) | ||
| config.HasPath("akka.persistence.journal.test-journal") | ||
| .Should().BeTrue(); | ||
|
|
||
| // assert - adapters are configured | ||
| var journalConfig = config.GetConfig("akka.persistence.journal.test-journal"); | ||
| journalConfig.GetString("event-adapters.test-adapter") | ||
| .Should().Be(typeof(UnifiedApiTestResources.TestWriteAdapter).TypeQualifiedName()); | ||
| journalConfig.GetString("event-adapters.test-reader") | ||
| .Should().Be(typeof(UnifiedApiTestResources.TestReadAdapter).TypeQualifiedName()); | ||
|
|
||
| var bindings = journalConfig.GetStringList( | ||
| $"event-adapter-bindings.\"{typeof(UnifiedApiTestResources.TestEvent).TypeQualifiedName()}\""); | ||
| bindings.Should().BeEquivalentTo("test-adapter", "test-reader"); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test WithSnapshot(SnapshotOptions) without builder | ||
| /// </summary> | ||
| public sealed class SnapshotOptionsOnlySpec : Akka.Hosting.TestKit.TestKit | ||
| { | ||
| public SnapshotOptionsOnlySpec(ITestOutputHelper output) : base(output: output) { } | ||
|
|
||
| protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) | ||
| { | ||
| base.ConfigureServices(context, services); | ||
| services.AddHealthChecks(); | ||
| } | ||
|
|
||
| protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider) | ||
| { | ||
| var options = new UnifiedApiTestResources.TestSnapshotOptions { IsDefaultPlugin = true }; | ||
| builder.WithSnapshot(options); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WithSnapshot_should_configure_snapshot_options_only() | ||
| { | ||
| var config = Sys.Settings.Config; | ||
| config.GetString("akka.persistence.snapshot-store.plugin") | ||
| .Should().Be("akka.persistence.snapshot-store.test-snapshot"); | ||
| config.HasPath("akka.persistence.snapshot-store.test-snapshot") | ||
| .Should().BeTrue(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test WithJournalAndSnapshot without builders | ||
| /// </summary> | ||
| public sealed class JournalAndSnapshotWithoutBuildersSpec : Akka.Hosting.TestKit.TestKit | ||
| { | ||
| public JournalAndSnapshotWithoutBuildersSpec(ITestOutputHelper output) : base(output: output) { } | ||
|
|
||
| protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) | ||
| { | ||
| base.ConfigureServices(context, services); | ||
| services.AddHealthChecks(); | ||
| } | ||
|
|
||
| protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider) | ||
| { | ||
| var journalOptions = new UnifiedApiTestResources.TestJournalOptions { IsDefaultPlugin = true }; | ||
| var snapshotOptions = new UnifiedApiTestResources.TestSnapshotOptions { IsDefaultPlugin = true }; | ||
| builder.WithJournalAndSnapshot(journalOptions, snapshotOptions); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WithJournalAndSnapshot_should_configure_both_without_builders() | ||
| { | ||
| var config = Sys.Settings.Config; | ||
| config.GetString("akka.persistence.journal.plugin") | ||
| .Should().Be("akka.persistence.journal.test-journal"); | ||
| config.GetString("akka.persistence.snapshot-store.plugin") | ||
| .Should().Be("akka.persistence.snapshot-store.test-snapshot"); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test WithJournalAndSnapshot with builder actions | ||
| /// </summary> | ||
| public sealed class JournalAndSnapshotWithBuildersSpec : Akka.Hosting.TestKit.TestKit | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. End to end integration test - also asserts that the health checks on each plugin work. |
||
| { | ||
| public JournalAndSnapshotWithBuildersSpec(ITestOutputHelper output) : base(output: output) { } | ||
|
|
||
| protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) | ||
| { | ||
| base.ConfigureServices(context, services); | ||
| services.AddHealthChecks(); | ||
| } | ||
|
|
||
| protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider) | ||
| { | ||
| var journalOptions = new UnifiedApiTestResources.TestJournalOptions { IsDefaultPlugin = true }; | ||
| var snapshotOptions = new UnifiedApiTestResources.TestSnapshotOptions { IsDefaultPlugin = true }; | ||
|
|
||
| builder.WithJournalAndSnapshot( | ||
| journalOptions, | ||
| snapshotOptions, | ||
| journal => journal | ||
| .AddWriteEventAdapter<UnifiedApiTestResources.TestWriteAdapter>("adapter", | ||
| [typeof(UnifiedApiTestResources.TestEvent)]) | ||
| .WithHealthCheck(), | ||
| snapshot => snapshot | ||
| .WithHealthCheck()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WithJournalAndSnapshot_with_builders_should_configure_everything() | ||
| { | ||
| var config = Sys.Settings.Config; | ||
|
|
||
| // assert - both plugins configured | ||
| config.HasPath("akka.persistence.journal.test-journal") | ||
| .Should().BeTrue(); | ||
| config.HasPath("akka.persistence.snapshot-store.test-snapshot") | ||
| .Should().BeTrue(); | ||
|
|
||
| // assert - adapters configured | ||
| var journalConfig = config.GetConfig("akka.persistence.journal.test-journal"); | ||
| journalConfig.GetString("event-adapters.adapter") | ||
| .Should().Be(typeof(UnifiedApiTestResources.TestWriteAdapter).TypeQualifiedName()); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test null builder actions work correctly | ||
| /// </summary> | ||
| public sealed class NullBuilderActionsSpec : Akka.Hosting.TestKit.TestKit | ||
| { | ||
| public NullBuilderActionsSpec(ITestOutputHelper output) : base(output: output) { } | ||
|
|
||
| protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) | ||
| { | ||
| base.ConfigureServices(context, services); | ||
| services.AddHealthChecks(); | ||
| } | ||
|
|
||
| protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider) | ||
| { | ||
| var journalOptions = new UnifiedApiTestResources.TestJournalOptions { IsDefaultPlugin = true }; | ||
| var snapshotOptions = new UnifiedApiTestResources.TestSnapshotOptions { IsDefaultPlugin = false }; | ||
|
|
||
| // Test that passing null for builder actions works | ||
| builder.WithJournal(journalOptions, configureBuilder: null); | ||
| builder.WithSnapshot(snapshotOptions, configureBuilder: null); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Null_builder_actions_should_work() | ||
| { | ||
| var config = Sys.Settings.Config; | ||
| config.GetString("akka.persistence.journal.plugin") | ||
| .Should().Be("akka.persistence.journal.test-journal"); | ||
| config.HasPath("akka.persistence.snapshot-store.test-snapshot") | ||
| .Should().BeTrue(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upgraded to Akka.NET v1.5.51 in order to get access to akkadotnet/akka.net#7842