Skip to content
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 @@ -6,7 +6,7 @@

#nullable enable
using System;
using Akka.Serialization;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
Expand All @@ -25,35 +25,53 @@ protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IService
builder.WithSerializationV2();
}

[Fact(DisplayName = "Should_add_an_enabled_SerializationV2Setup_When_WithSerializationV2_is_called")]
public void Should_add_an_enabled_SerializationV2Setup_When_WithSerializationV2_is_called()
[Fact(DisplayName = "Should_set_the_serialization_v2_HOCON_key_to_true_When_WithSerializationV2_is_called")]
public async Task Should_set_the_serialization_v2_HOCON_key_to_true_When_WithSerializationV2_is_called()
{
var setup = Sys.Settings.Setup.Get<SerializationV2Setup>();
setup.HasValue.Should().BeTrue();
setup.Value.Enabled.Should().BeTrue();
await Task.Yield();
Sys.Settings.Config.GetBoolean("akka.actor.serialization-v2", false).Should().BeTrue();
}
}

public sealed class SerializationV2SpecsOverridden : TestKit
public sealed class SerializationV2SpecsDisabled : TestKit
{
public SerializationV2SpecsOverridden(XunitTestOutputHelper output)
: base(nameof(SerializationV2SpecsOverridden), output, logLevel: LogLevel.Information)
public SerializationV2SpecsDisabled(XunitTestOutputHelper output)
: base(nameof(SerializationV2SpecsDisabled), output, logLevel: LogLevel.Information)
{
}

protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider)
{
// HOCON says on, and the last builder call says off: the setup wins over HOCON, and the last call wins
// HOCON added earlier says on; the extension wins over it
builder.AddHocon("akka.actor.serialization-v2 = on", HoconAddMode.Prepend);
builder.WithSerializationV2();
builder.WithSerializationV2(false);
}

[Fact(DisplayName = "Should_keep_only_the_last_SerializationV2Setup_When_WithSerializationV2_is_called_twice")]
public void Should_keep_only_the_last_SerializationV2Setup_When_WithSerializationV2_is_called_twice()
[Fact(DisplayName = "Should_set_the_serialization_v2_HOCON_key_to_false_When_WithSerializationV2_is_called_with_false")]
public async Task Should_set_the_serialization_v2_HOCON_key_to_false_When_WithSerializationV2_is_called_with_false()
{
await Task.Yield();
Sys.Settings.Config.GetBoolean("akka.actor.serialization-v2", true).Should().BeFalse();
}
}

public sealed class SerializationV2SpecsLastCallWins : TestKit
{
public SerializationV2SpecsLastCallWins(XunitTestOutputHelper output)
: base(nameof(SerializationV2SpecsLastCallWins), output, logLevel: LogLevel.Information)
{
}

protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider)
{
builder.WithSerializationV2(false);
builder.WithSerializationV2();
}

[Fact(DisplayName = "Should_use_the_last_value_When_WithSerializationV2_is_called_twice")]
public async Task Should_use_the_last_value_When_WithSerializationV2_is_called_twice()
{
var setup = Sys.Settings.Setup.Get<SerializationV2Setup>();
setup.HasValue.Should().BeTrue();
setup.Value.Enabled.Should().BeFalse();
await Task.Yield();
Sys.Settings.Config.GetBoolean("akka.actor.serialization-v2", false).Should().BeTrue();
}
}
9 changes: 4 additions & 5 deletions src/contrib/hosting/Akka.Hosting/AkkaHostingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ public static AkkaConfigurationBuilder WithStrictSerialization(this AkkaConfigur
}

/// <summary>
/// Turns the Serialization V2 switch on or off by adding a <see cref="SerializationV2Setup"/>, which wins over
/// <c>akka.actor.serialization-v2</c> in HOCON. When on, each built-in serializer that has a V2 version takes
/// Turns the Serialization V2 switch (<c>akka.actor.serialization-v2</c>) on or off. When on, each built-in serializer that has a V2 version takes
/// over the bindings of the legacy serializer it replaces; the legacy serializers stay registered for reads.
/// <para>
/// Turn it on only once every node runs a version of Akka.NET that can read the V2 formats. A binding you
Expand All @@ -234,9 +233,9 @@ public static AkkaConfigurationBuilder WithStrictSerialization(this AkkaConfigur
/// <returns>The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in.</returns>
public static AkkaConfigurationBuilder WithSerializationV2(this AkkaConfigurationBuilder builder, bool enabled = true)
{
// one switch per system: a later call replaces an earlier one instead of racing it in the set
builder.Setups.RemoveWhere(s => s is SerializationV2Setup);
return builder.AddSetup(SerializationV2Setup.Create(enabled));
// Prepend, like the other single-key extensions: wins over the reference config and earlier HOCON,
// and a later call wins over an earlier one
return AddHocon(builder, $"akka.actor.serialization-v2 = {(enabled ? "on" : "off")}", HoconAddMode.Prepend);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5284,11 +5284,6 @@ namespace Akka.Serialization
public System.Func<Akka.Actor.ExtendedActorSystem, System.Collections.Immutable.ImmutableHashSet<Akka.Serialization.SerializerDetails>> CreateSerializers { get; }
public static Akka.Serialization.SerializationSetup Create(System.Func<Akka.Actor.ExtendedActorSystem, System.Collections.Immutable.ImmutableHashSet<Akka.Serialization.SerializerDetails>> createSerializers) { }
}
public sealed class SerializationV2Setup : Akka.Actor.Setup.Setup
{
public bool Enabled { get; }
public static Akka.Serialization.SerializationV2Setup Create(bool enabled) { }
}
public abstract class Serializer
{
protected readonly Akka.Actor.ExtendedActorSystem system;
Expand Down
22 changes: 1 addition & 21 deletions src/core/Akka.Tests/Serialization/SerializationV2SwitchSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace Akka.Tests.Serialization
{
/// <summary>
/// The Serialization V2 switch (<c>akka.actor.serialization-v2</c> / <see cref="SerializationV2Setup"/>), driven by
/// The Serialization V2 switch (<c>akka.actor.serialization-v2</c>), driven by
/// a fake module keyed as "Akka.Tests": a legacy row, the read-only V2 row that supersedes it, and an unrelated
/// native row the switch must leave alone. No first-party module ships a V2 row yet.
/// </summary>
Expand Down Expand Up @@ -340,26 +340,6 @@ await WithSystem("akka.actor.serialization-v2 = on", async system =>
}, setup);
}

[Theory(DisplayName = "Should_let_SerializationV2Setup_win_over_HOCON_When_both_set_the_switch")]
[InlineData("akka.actor.serialization-v2 = on", false, true)]
[InlineData("akka.actor.serialization-v2 = on", false, false)]
[InlineData("akka.actor.serialization-v2 = off", true, true)]
[InlineData("akka.actor.serialization-v2 = off", true, false)]
[InlineData(null, true, false)]
public async Task Should_let_SerializationV2Setup_win_over_HOCON_When_both_set_the_switch(string? hocon, bool setupEnabled, bool dynamicTypeLoading)
{
await WithSystem(hocon, async system =>
{
var serialization = await Build(system, dynamicTypeLoading);

if (setupEnabled)
AssertV2Bindings(serialization);
else
AssertLegacyBindings(serialization);
AssertBothFormatsRead(serialization);
}, SerializationV2Setup.Create(setupEnabled));
}

[Theory(DisplayName = "Should_move_the_taken_over_bindings_to_the_override_When_user_HOCON_overrides_the_V2_alias")]
[InlineData(true)]
[InlineData(false)]
Expand Down
1 change: 0 additions & 1 deletion src/core/Akka/Configuration/akka.conf
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ akka {
# Turn it on only once every node runs such a version. To roll back, turn it off.
# A type you bind in serialization-bindings (or in a SerializationSetup) keeps
# your binding, so you can pin one subsystem to its legacy alias.
# A SerializationV2Setup passed to the ActorSystem overrides this setting.
serialization-v2 = off

# extra settings that can be custom to a serializer implementation
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Serialization/ModuleSerializers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal abstract class ModuleSerializers
/// The legacy row each of this module's V2 rows supersedes, as V2 alias to legacy alias - for example
/// <c>["reliable-delivery-v2"] = "reliable-delivery"</c>. Both rows must come from <see cref="Create"/>, and the
/// V2 row ships read-only (empty <see cref="SerializerDetails.UseFor"/>). When the Serialization V2 switch
/// (<c>akka.actor.serialization-v2</c> or <see cref="SerializationV2Setup"/>) is on, the V2 row takes over the
/// (<c>akka.actor.serialization-v2</c>) is on, the V2 row takes over the
/// legacy row's default bindings; when it is off, nothing moves. Both ids stay registered either way.
/// </summary>
public virtual ImmutableDictionary<string, string> Supersedes => ImmutableDictionary<string, string>.Empty;
Expand Down
5 changes: 2 additions & 3 deletions src/core/Akka/Serialization/Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static T WithTransport<T>(ActorSystem system, Address address, Func<T> ac
private Dictionary<int, string> _defaultSerializerIdAlias = new();
private Dictionary<string, (SerializerV2 Serializer, ImmutableHashSet<Type> UseFor)> _moduleDefaultsByAlias = new(StringComparer.Ordinal);

/// <summary>The HOCON key of the Serialization V2 switch; a <see cref="SerializationV2Setup"/> overrides it.</summary>
/// <summary>The HOCON key of the Serialization V2 switch.</summary>
internal const string SerializationV2Key = "akka.actor.serialization-v2";

// the last Serialization V2 line logged per system, so a rebuilt Serialization doesn't repeat it
Expand Down Expand Up @@ -336,8 +336,7 @@ internal Serialization(ExtendedActorSystem system, ModuleSerializerTable modules

// the Serialization V2 switch decides which module row holds a superseded legacy row's default bindings;
// it never changes which ids are registered, so reads don't depend on it
var serializationV2 = system.Settings.Setup.Get<SerializationV2Setup>().Select(s => s.Enabled)
.GetOrElse(system.Settings.Config.GetBoolean(SerializationV2Key, false));
var serializationV2 = system.Settings.Config.GetBoolean(SerializationV2Key, false);
List<LoadedModule> takeoverModules = null;

// modules this system ships with, by assembly name. Every module the table knows about is built here,
Expand Down
54 changes: 0 additions & 54 deletions src/core/Akka/Serialization/SerializationV2Setup.cs

This file was deleted.

Loading