Skip to content

Commit

Permalink
Add constructor with ActorSystemSetup argument to SnapshotStoreSerial…
Browse files Browse the repository at this point in the history
…izationSpec (#6850)

* Add constructor that takes ActorSystemSetup to SnapshotStoreSerializationSpec

* Make Config constructor to call the ActorSystemSetup version
  • Loading branch information
Arkatufus authored Jul 25, 2023
1 parent fe9c570 commit 47a1883
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 12 deletions.
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

0 comments on commit 47a1883

Please sign in to comment.