Skip to content
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

Add constructor with ActorSystemSetup argument to SnapshotStoreSerializationSpec #6850

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
// </copyright>
//-----------------------------------------------------------------------

using System.Linq;
using Akka.Configuration;
using Akka.Persistence.TCK.Serialization;
using Akka.Util.Internal;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -37,7 +39,38 @@ class = ""Akka.Persistence.Sqlite.Snapshot.SqliteSnapshotStore, Akka.Persistence
connection-string = """ + connectionString + @"""
}
}
}
under-test {
value = true
}");
}

// This is a test for SnapshotStoreSerializationSpec, not SqliteSnapshotStoreSerializationSpec
[Fact(DisplayName = "SnapshotStoreSerializationSpec ctor with ActorSystemSetup should combine all necessary configurations")]
public void AllConfigShouldBePresentTest()
{
var config = Sys.Settings.Config;

// Config inside original ActorSystemSetup should be preserved
config.GetBoolean("under-test.value").Should().BeTrue();

// Config needed by SnapshotStoreSerializationSpec should be injected
var serializers = config.GetConfig("akka.actor.serializers").AsEnumerable().ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
serializers.TryGetValue("my-snapshot", out var mySnapshot).Should().BeTrue();
mySnapshot!.GetString().Should().Be("Akka.Persistence.TCK.Serialization.Test+MySnapshotSerializer, Akka.Persistence.TCK");
serializers.TryGetValue("my-snapshot2", out var mySnapshot2).Should().BeTrue();
mySnapshot2!.GetString().Should().Be("Akka.Persistence.TCK.Serialization.Test+MySnapshotSerializer2, Akka.Persistence.TCK");

var bindings = config.GetConfig("akka.actor.serialization-bindings").AsEnumerable().ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
bindings.TryGetValue("Akka.Persistence.TCK.Serialization.Test+MySnapshot, Akka.Persistence.TCK", out var binding).Should().BeTrue();
binding!.GetString().Should().Be("my-snapshot");
bindings.TryGetValue("Akka.Persistence.TCK.Serialization.Test+MySnapshot2, Akka.Persistence.TCK", out var binding2).Should().BeTrue();
binding2!.GetString().Should().Be("my-snapshot2");

// Akka.Persistence default configuration should be injected
config.HasPath("akka.persistence.max-concurrent-recoveries").Should().BeTrue();
config.GetInt("akka.persistence.max-concurrent-recoveries").Should().Be(50);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,55 @@
using System;
using System.Text;
using Akka.Actor;
using Akka.Actor.Setup;
using Akka.Configuration;
using Akka.Persistence.Fsm;
using Akka.Serialization;
using Xunit;
using Xunit.Abstractions;
using Akka.Util.Internal;
using FluentAssertions;

#nullable enable
namespace Akka.Persistence.TCK.Serialization
{
public abstract class SnapshotStoreSerializationSpec : PluginSpec
{
private static readonly Config BaseConfig = ConfigurationFactory.ParseString(@"
akka.actor {
serializers {
my-snapshot = ""Akka.Persistence.TCK.Serialization.Test+MySnapshotSerializer, Akka.Persistence.TCK""
my-snapshot2 = ""Akka.Persistence.TCK.Serialization.Test+MySnapshotSerializer2, Akka.Persistence.TCK""
}
serialization-bindings {
""Akka.Persistence.TCK.Serialization.Test+MySnapshot, Akka.Persistence.TCK"" = my-snapshot
""Akka.Persistence.TCK.Serialization.Test+MySnapshot2, Akka.Persistence.TCK"" = my-snapshot2
}
}");

private static ActorSystemSetup WithConfig(Config? config = null)
{
return ActorSystemSetup.Empty
.And(BootstrapSetup.Create().WithConfig(BaseConfig.WithFallback(FromConfig(config))));
}

protected static ActorSystemSetup FromActorSystemSetup(ActorSystemSetup setup)
{
var bootstrapOption = setup.Get<BootstrapSetup>();
var bootstrap = bootstrapOption.HasValue ? bootstrapOption.Value : BootstrapSetup.Create();
var config = bootstrap.Config.HasValue
? FromConfig(BaseConfig.WithFallback(bootstrap.Config.Value))
: FromConfig(BaseConfig);
return setup.And(bootstrap.WithConfig(config));
}

protected SnapshotStoreSerializationSpec(Config config, string actorSystem, ITestOutputHelper output)
: base(ConfigurationFactory.ParseString(@"
akka.actor {
serializers {
my-snapshot = ""Akka.Persistence.TCK.Serialization.Test+MySnapshotSerializer, Akka.Persistence.TCK""
my-snapshot2 = ""Akka.Persistence.TCK.Serialization.Test+MySnapshotSerializer2, Akka.Persistence.TCK""
}
serialization-bindings {
""Akka.Persistence.TCK.Serialization.Test+MySnapshot, Akka.Persistence.TCK"" = my-snapshot
""Akka.Persistence.TCK.Serialization.Test+MySnapshot2, Akka.Persistence.TCK"" = my-snapshot2
}
}
").WithFallback(config), actorSystem, output)
: this(WithConfig(config), actorSystem, output)
{
}

protected SnapshotStoreSerializationSpec(ActorSystemSetup setup, string actorSystem, ITestOutputHelper output)
:base(FromActorSystemSetup(setup), actorSystem, output)
{
}

Expand Down