-
Notifications
You must be signed in to change notification settings - Fork 36
Adding Hosting Extensions for Akka.Persistence.MongoDB #331
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 8 commits
cc6a606
4eb0e7d
a45b91b
cff5a02
ec4ae98
8ef8efd
469a32b
fdd3deb
8cd7e00
6ffaaf1
655d3f7
38be7df
7c6a94e
90beb71
472d991
f32eabe
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,22 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <Import Project="..\common.props" /> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>$(NetFrameworkTestVersion);$(NetTestVersion);$(NetCoreTestVersion)</TargetFrameworks> | ||
|
||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="FluentAssertions" Version="6.11.0" /> | ||
mhbuck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" /> | ||
| <PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="xunit" Version="$(XunitVersion)" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Akka.Persistence.MongoDb.Hosting\Akka.Persistence.MongoDb.Hosting.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Text; | ||
| using Akka.Configuration; | ||
| using FluentAssertions; | ||
| using FluentAssertions.Extensions; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Xunit; | ||
|
|
||
| namespace Akka.Persistence.MongoDb.Hosting.Tests | ||
| { | ||
| public class MongoDbJournalOptionsSpec | ||
|
Contributor
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. These tests are basically clones of the ones here https://github.com/akkadotnet/Akka.Persistence.PostgreSql/blob/dev/src/Akka.Persistence.PostgreSql.Tests/Hosting/PostgreSqlOptionsSpec.cs I have split them up and cleaned up parts but if there are additional cases needed I am happy to add them. |
||
| { | ||
| [Fact(DisplayName = "MongoDbJournalOptions as default plugin should generate plugin setting")] | ||
| public void DefaultPluginJournalOptionsTest() | ||
| { | ||
| var options = new MongoDbJournalOptions(true); | ||
| var config = options.ToConfig(); | ||
|
|
||
| config.GetString("akka.persistence.journal.plugin").Should().Be("akka.persistence.journal.mongodb"); | ||
| config.HasPath("akka.persistence.journal.mongodb").Should().BeTrue(); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "Empty MongoDbJournalOptions should equal empty config with default fallback")] | ||
| public void DefaultJournalOptionsTest() | ||
| { | ||
| var options = new MongoDbJournalOptions(false); | ||
| var emptyRootConfig = options.ToConfig().WithFallback(options.DefaultConfig); | ||
| var baseRootConfig = Config.Empty | ||
| .WithFallback(MongoDbPersistence.DefaultConfiguration()); | ||
|
|
||
| emptyRootConfig.GetString("akka.persistence.journal.plugin").Should().Be(baseRootConfig.GetString("akka.persistence.journal.plugin")); | ||
|
|
||
| var config = emptyRootConfig.GetConfig("akka.persistence.journal.mongodb"); | ||
| var baseConfig = baseRootConfig.GetConfig("akka.persistence.journal.mongodb"); | ||
| config.Should().NotBeNull(); | ||
| baseConfig.Should().NotBeNull(); | ||
|
|
||
| config.GetString("class").Should().Be(baseConfig.GetString("class")); | ||
| config.GetString("connection-string").Should().Be(baseConfig.GetString("connection-string")); | ||
| config.GetBoolean("use-write-transaction").Should().Be(baseConfig.GetBoolean("use-write-transaction")); | ||
| config.GetBoolean("auto-initialize").Should().Be(baseConfig.GetBoolean("auto-initialize")); | ||
| config.GetString("plugin-dispatcher").Should().Be(baseConfig.GetString("plugin-dispatcher")); | ||
| config.GetString("collection").Should().Be(baseConfig.GetString("collection")); | ||
| config.GetString("metadata-collection").Should().Be(baseConfig.GetString("metadata-collection")); | ||
| config.GetBoolean("legacy-serialization").Should().Be(baseConfig.GetBoolean("legacy-serialization")); | ||
| config.GetTimeSpan("call-timeout").Should().Be(baseConfig.GetTimeSpan("call-timeout")); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "Empty MongoDbJournalOptions with custom identifier should equal empty config with default fallback")] | ||
| public void CustomIdJournalOptionsTest() | ||
| { | ||
| var options = new MongoDbJournalOptions(false, "custom"); | ||
| var emptyRootConfig = options.ToConfig().WithFallback(options.DefaultConfig); | ||
| var baseRootConfig = Config.Empty | ||
| .WithFallback(MongoDbPersistence.DefaultConfiguration()); | ||
|
|
||
| emptyRootConfig.GetString("akka.persistence.journal.plugin").Should().Be(baseRootConfig.GetString("akka.persistence.journal.plugin")); | ||
|
|
||
| var config = emptyRootConfig.GetConfig("akka.persistence.journal.custom"); | ||
| var baseConfig = baseRootConfig.GetConfig("akka.persistence.journal.mongodb"); | ||
| config.Should().NotBeNull(); | ||
| baseConfig.Should().NotBeNull(); | ||
|
|
||
| config.GetString("class").Should().Be(baseConfig.GetString("class")); | ||
| config.GetString("connection-string").Should().Be(baseConfig.GetString("connection-string")); | ||
| config.GetBoolean("use-write-transaction").Should().Be(baseConfig.GetBoolean("use-write-transaction")); | ||
| config.GetBoolean("auto-initialize").Should().Be(baseConfig.GetBoolean("auto-initialize")); | ||
| config.GetString("plugin-dispatcher").Should().Be(baseConfig.GetString("plugin-dispatcher")); | ||
| config.GetString("collection").Should().Be(baseConfig.GetString("collection")); | ||
| config.GetString("metadata-collection").Should().Be(baseConfig.GetString("metadata-collection")); | ||
| config.GetBoolean("legacy-serialization").Should().Be(baseConfig.GetBoolean("legacy-serialization")); | ||
| config.GetTimeSpan("call-timeout").Should().Be(baseConfig.GetTimeSpan("call-timeout")); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "MongoDbJournalOptions should generate proper config")] | ||
| public void JournalOptionsTest() | ||
| { | ||
| var options = new MongoDbJournalOptions(true) | ||
| { | ||
| Identifier = "custom", | ||
| AutoInitialize = true, | ||
| ConnectionString = "testConnection", | ||
| Collection = "testCollection", | ||
| MetadataCollection = "metadataCollection", | ||
| UseWriteTransaction = true, | ||
| LegacySerialization = true, | ||
| CallTimeout = TimeSpan.FromHours(2) | ||
| }; | ||
|
|
||
| var baseConfig = options.ToConfig(); | ||
|
|
||
| baseConfig.GetString("akka.persistence.journal.plugin").Should().Be("akka.persistence.journal.custom"); | ||
|
|
||
| var config = baseConfig.GetConfig("akka.persistence.journal.custom"); | ||
| config.Should().NotBeNull(); | ||
| config.GetString("connection-string").Should().Be(options.ConnectionString); | ||
| config.GetBoolean("auto-initialize").Should().Be(options.AutoInitialize); | ||
| config.GetString("collection").Should().Be(options.Collection); | ||
| config.GetString("metadata-collection").Should().Be(options.MetadataCollection); | ||
| config.GetBoolean("use-write-transaction").Should().Be(options.UseWriteTransaction); | ||
| config.GetBoolean("legacy-serialization").Should().Be(options.LegacySerialization); | ||
| config.GetTimeSpan("call-timeout").Should().Be(options.CallTimeout); | ||
| } | ||
|
|
||
| const string Json = @" | ||
| { | ||
| ""Logging"": { | ||
| ""LogLevel"": { | ||
| ""Default"": ""Information"", | ||
| ""Microsoft.AspNetCore"": ""Warning"" | ||
| } | ||
| }, | ||
| ""Akka"": { | ||
| ""JournalOptions"": { | ||
| ""ConnectionString"": ""mongodb://localhost:27017"", | ||
| ""UseWriteTransaction"": ""true"", | ||
| ""Identifier"": ""custommongodb"", | ||
| ""AutoInitialize"": true, | ||
| ""IsDefaultPlugin"": false, | ||
|
|
||
| ""Collection"": ""CustomEnventJournalCollection"", | ||
| ""MetadataCollection"": ""CustomMetadataCollection"", | ||
| ""LegacySerialization"" : ""true"", | ||
| ""CallTimeout"": ""00:10:00"", | ||
| ""Serializer"": ""hyperion"", | ||
| } | ||
| } | ||
| }"; | ||
|
|
||
| [Fact(DisplayName = "MongoDbJournalOptions should be bindable to IConfiguration")] | ||
| public void JournalOptionsIConfigurationBindingTest() | ||
| { | ||
| var stream = new MemoryStream(Encoding.UTF8.GetBytes(Json)); | ||
| var jsonConfig = new ConfigurationBuilder().AddJsonStream(stream).Build(); | ||
|
|
||
| var options = jsonConfig.GetSection("Akka:JournalOptions").Get<MongoDbJournalOptions>(); | ||
| options.ConnectionString.Should().Be("mongodb://localhost:27017"); | ||
| options.UseWriteTransaction.Should().BeTrue(); | ||
| options.Identifier.Should().Be("custommongodb"); | ||
| options.AutoInitialize.Should().BeTrue(); | ||
| options.IsDefaultPlugin.Should().BeFalse(); | ||
| options.Collection.Should().Be("CustomEnventJournalCollection"); | ||
| options.MetadataCollection.Should().Be("CustomMetadataCollection"); | ||
| options.LegacySerialization.Should().BeTrue(); | ||
| options.CallTimeout.Should().Be(10.Minutes()); | ||
| options.Serializer.Should().Be("hyperion"); | ||
|
|
||
| // Dispose called here as project not using latest language features. | ||
| stream.Dispose(); | ||
|
Contributor
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. Added this to both tests as the using declarations are not currently available in the language features for this project and it caused build failures. Do you have a preferred way of handling this? |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Text; | ||
| using Akka.Configuration; | ||
| using FluentAssertions; | ||
| using FluentAssertions.Extensions; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Xunit; | ||
|
|
||
| namespace Akka.Persistence.MongoDb.Hosting.Tests | ||
| { | ||
| public class MongoDbSnapshotOptionsSpec | ||
| { | ||
| [Fact(DisplayName = "MongoDbSnapshotOptions as default plugin should generate plugin setting")] | ||
| public void DefaultPluginSnapshotOptionsTest() | ||
| { | ||
| var options = new MongoDbSnapshotOptions(true); | ||
| var config = options.ToConfig(); | ||
|
|
||
| config.GetString("akka.persistence.snapshot-store.plugin").Should().Be("akka.persistence.snapshot-store.mongodb"); | ||
| config.HasPath("akka.persistence.snapshot-store.mongodb").Should().BeTrue(); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "Empty MongoDbSnapshotOptions with default fallback should return default config")] | ||
| public void DefaultSnapshotOptionsTest() | ||
| { | ||
| var options = new MongoDbSnapshotOptions(false); | ||
| var emptyRootConfig = options.ToConfig().WithFallback(options.DefaultConfig); | ||
| var baseRootConfig = Config.Empty | ||
| .WithFallback(MongoDbPersistence.DefaultConfiguration()); | ||
|
|
||
| emptyRootConfig.GetString("akka.persistence.snapshot-store.plugin").Should().Be(baseRootConfig.GetString("akka.persistence.snapshot-store.plugin")); | ||
|
|
||
| var config = emptyRootConfig.GetConfig("akka.persistence.snapshot-store.mongodb"); | ||
| var baseConfig = baseRootConfig.GetConfig("akka.persistence.snapshot-store.mongodb"); | ||
| config.Should().NotBeNull(); | ||
| baseConfig.Should().NotBeNull(); | ||
|
|
||
| config.GetString("class").Should().Be(baseConfig.GetString("class")); | ||
| config.GetString("connection-string").Should().Be(baseConfig.GetString("connection-string")); | ||
| config.GetBoolean("use-write-transaction").Should().Be(baseConfig.GetBoolean("use-write-transaction")); | ||
| config.GetBoolean("auto-initialize").Should().Be(baseConfig.GetBoolean("auto-initialize")); | ||
| config.GetString("plugin-dispatcher").Should().Be(baseConfig.GetString("plugin-dispatcher")); | ||
| config.GetString("collection").Should().Be(baseConfig.GetString("collection")); | ||
| config.GetBoolean("legacy-serialization").Should().Be(baseConfig.GetBoolean("legacy-serialization")); | ||
| config.GetTimeSpan("call-timeout").Should().Be(baseConfig.GetTimeSpan("call-timeout")); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "Empty MongoDbSnapshotOptions with custom identifier should equal empty config with default fallback")] | ||
| public void CustomIdSnapshotOptionsTest() | ||
| { | ||
| var options = new MongoDbSnapshotOptions(false, "custom"); | ||
| var emptyRootConfig = options.ToConfig().WithFallback(options.DefaultConfig); | ||
| var baseRootConfig = Config.Empty | ||
| .WithFallback(MongoDbPersistence.DefaultConfiguration()); | ||
|
|
||
| emptyRootConfig.GetString("akka.persistence.snapshot-store.plugin").Should().Be(baseRootConfig.GetString("akka.persistence.snapshot-store.plugin")); | ||
|
|
||
| var config = emptyRootConfig.GetConfig("akka.persistence.snapshot-store.custom"); | ||
| var baseConfig = baseRootConfig.GetConfig("akka.persistence.snapshot-store.mongodb"); | ||
| config.Should().NotBeNull(); | ||
| baseConfig.Should().NotBeNull(); | ||
|
|
||
| config.GetString("class").Should().Be(baseConfig.GetString("class")); | ||
| config.GetString("connection-string").Should().Be(baseConfig.GetString("connection-string")); | ||
| config.GetBoolean("use-write-transaction").Should().Be(baseConfig.GetBoolean("use-write-transaction")); | ||
| config.GetBoolean("auto-initialize").Should().Be(baseConfig.GetBoolean("auto-initialize")); | ||
| config.GetString("plugin-dispatcher").Should().Be(baseConfig.GetString("plugin-dispatcher")); | ||
| config.GetString("collection").Should().Be(baseConfig.GetString("collection")); | ||
| config.GetBoolean("legacy-serialization").Should().Be(baseConfig.GetBoolean("legacy-serialization")); | ||
| config.GetTimeSpan("call-timeout").Should().Be(baseConfig.GetTimeSpan("call-timeout")); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "MongoDbSnapshotOptions should generate proper config")] | ||
| public void SnapshotOptionsTest() | ||
| { | ||
| var options = new MongoDbSnapshotOptions(true) | ||
| { | ||
| Identifier = "custom", | ||
| AutoInitialize = true, | ||
| ConnectionString = "testConnection", | ||
| Collection = "testCollection", | ||
| UseWriteTransaction = true, | ||
| LegacySerialization = true, | ||
| CallTimeout = TimeSpan.FromHours(2) | ||
| }; | ||
|
|
||
| var baseConfig = options.ToConfig() | ||
| .WithFallback(MongoDbPersistence.DefaultConfiguration()); | ||
|
|
||
| baseConfig.GetString("akka.persistence.snapshot-store.plugin").Should().Be("akka.persistence.snapshot-store.custom"); | ||
|
|
||
| var config = baseConfig.GetConfig("akka.persistence.snapshot-store.custom"); | ||
| config.Should().NotBeNull(); | ||
| config.GetString("connection-string").Should().Be(options.ConnectionString); | ||
| config.GetBoolean("auto-initialize").Should().Be(options.AutoInitialize); | ||
| config.GetString("collection").Should().Be(options.Collection); | ||
| config.GetBoolean("use-write-transaction").Should().Be(options.UseWriteTransaction); | ||
| config.GetBoolean("legacy-serialization").Should().Be(options.LegacySerialization); | ||
| config.GetTimeSpan("call-timeout").Should().Be(options.CallTimeout); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "MongoDbSnapshotOptions should be bindable to IConfiguration")] | ||
| public void SnapshotOptionsIConfigurationBindingTest() | ||
| { | ||
| const string json = @" | ||
| { | ||
| ""Logging"": { | ||
| ""LogLevel"": { | ||
| ""Default"": ""Information"", | ||
| ""Microsoft.AspNetCore"": ""Warning"" | ||
| } | ||
| }, | ||
| ""Akka"": { | ||
| ""SnapshotOptions"": { | ||
| ""ConnectionString"": ""mongodb://localhost:27017"", | ||
| ""UseWriteTransaction"": ""true"", | ||
| ""Identifier"": ""custommongodb"", | ||
| ""AutoInitialize"": true, | ||
| ""IsDefaultPlugin"": false, | ||
|
|
||
| ""Collection"": ""CustomEnventJournalCollection"", | ||
| ""LegacySerialization"" : ""true"", | ||
| ""CallTimeout"": ""00:10:00"", | ||
| ""Serializer"": ""hyperion"", | ||
| } | ||
| } | ||
| }"; | ||
|
|
||
| var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); | ||
| var jsonConfig = new ConfigurationBuilder().AddJsonStream(stream).Build(); | ||
|
|
||
| var options = jsonConfig.GetSection("Akka:SnapshotOptions").Get<MongoDbSnapshotOptions>(); | ||
| options.ConnectionString.Should().Be("mongodb://localhost:27017"); | ||
| options.UseWriteTransaction.Should().BeTrue(); | ||
| options.Identifier.Should().Be("custommongodb"); | ||
| options.AutoInitialize.Should().BeTrue(); | ||
| options.IsDefaultPlugin.Should().BeFalse(); | ||
| options.Collection.Should().Be("CustomEnventJournalCollection"); | ||
| options.LegacySerialization.Should().BeTrue(); | ||
| options.CallTimeout.Should().Be(10.Minutes()); | ||
| options.Serializer.Should().Be("hyperion"); | ||
|
|
||
| // Dispose called here as project not using latest language features. | ||
| stream.Dispose(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <Import Project="..\common.props" /> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>$(NetStandardLibVersion)</TargetFrameworks> | ||
| <LangVersion>latest</LangVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Akka.Persistence.Hosting" Version="$(AkkaVersion)" /> | ||
|
Contributor
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. From the other projects it looked like targeting |
||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Akka.Persistence.MongoDb\Akka.Persistence.MongoDb.csproj" /> | ||
| </ItemGroup> | ||
| </Project> | ||
Uh oh!
There was an error while loading. Please reload this page.