Skip to content

Commit

Permalink
[1.3] Implement cross platform primitive serializer (#7182)
Browse files Browse the repository at this point in the history
* Change the base class of PrimitiveSerializers to SerializerWithStringManifest (#4989)

* Change the base class of PrimitiveSerializers to SerializerWithStringManifest

* Add backward compatibility to the wire format

* Update API Approver list

(cherry picked from commit 25246ac)

* cherry-picked from 6101fea

Add backward compatibility to PrimitiveSerializers (#5280)

* Add backward compatibility to PrimitiveSerializers

* Update API Approver list

* Change PrimitiveSerializer compatibility switch setting name from `use-neutral-primitives` to `use-legacy-behavior` for less ambiguity (#5290)

* Change PrimitiveSerializer compatibility switch setting name from `use-neutral-primitives` to `use-legacy-behavior` for less ambiguity

* Fix unit test

* Change default to full compatibility (on)

* Fix unit test

Co-authored-by: Aaron Stannard <aaron@petabridge.com>
(cherry picked from commit 302e3cb)

* Code cleanup

* Fix FSharp.Core package problem

* Fix CI/CD script - Change vmimage to windows-latest and ubuntu-latest

* Fix CI/CD script - Install SDK

* Bump net45 target to net452

* Fix CI/CD script

* Bump Incrementalist.Cmd to 0.9.0

* Revert "Bump net45 target to net452"

This reverts commit 2d0d76d.

* Revert "Code cleanup"

This reverts commit d72b753.

* Code cleanup

* Code cleanup
  • Loading branch information
Arkatufus authored May 2, 2024
1 parent f23f15f commit 506f8d0
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 39 deletions.
5 changes: 5 additions & 0 deletions build-system/azure-pipeline.mntr-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
pool:
vmImage: ${{ parameters.vmImage }}
steps:
- task: UseDotNet@2
displayName: 'Use .NET SDK'
inputs:
packageType: sdk
useGlobalJson: true
- task: Bash@3
displayName: Linux / OSX Build
inputs:
Expand Down
5 changes: 5 additions & 0 deletions build-system/azure-pipeline.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
pool:
vmImage: ${{ parameters.vmImage }}
steps:
- task: UseDotNet@2
displayName: 'Use .NET SDK'
inputs:
packageType: sdk
useGlobalJson: true
- task: Bash@3
displayName: Linux / OSX Build
inputs:
Expand Down
2 changes: 1 addition & 1 deletion build-system/nightly-builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema for reference

pool:
vmImage: vs2017-win2016
vmImage: windows-latest
demands: Cmd

trigger: none
Expand Down
14 changes: 7 additions & 7 deletions build-system/pr-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- job: WindowsBuild
displayName: Windows Build
pool:
vmImage: vs2017-win2016
vmImage: windows-latest
demands: Cmd
steps:
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
parameters:
name: 'netfx_tests_windows'
displayName: '.NET Framework Unit Tests (Windows)'
vmImage: 'vs2017-win2016'
vmImage: windows-latest
scriptFileName: build.cmd
scriptArgs: runTests incremental targetBranch=v1.3
outputDirectory: 'TestResults'
Expand All @@ -62,7 +62,7 @@ jobs:
parameters:
name: 'net_core_tests_windows'
displayName: '.NET Core Unit Tests (Windows)'
vmImage: 'vs2017-win2016'
vmImage: windows-latest
scriptFileName: build.cmd
scriptArgs: runTestsNetCore incremental targetBranch=v1.3
outputDirectory: 'TestResults'
Expand All @@ -72,7 +72,7 @@ jobs:
parameters:
name: 'net_core_tests_linux'
displayName: '.NET Core Unit Tests (Linux)'
vmImage: 'ubuntu-16.04'
vmImage: ubuntu-latest
scriptFileName: './build.sh'
scriptArgs: runTestsNetCore incremental targetBranch=v1.3
outputDirectory: 'TestResults'
Expand All @@ -82,7 +82,7 @@ jobs:
parameters:
name: 'net_core_mntr_windows'
displayName: '.NET Core Multi-Node Tests (Windows)'
vmImage: 'vs2017-win2016'
vmImage: windows-latest
scriptFileName: 'build.cmd'
scriptArgs: MultiNodeTestsNetCore incremental targetBranch=v1.3
outputDirectory: 'TestResults'
Expand All @@ -94,7 +94,7 @@ jobs:
parameters:
name: 'net_fx_mntr_windows'
displayName: '.NET Framework Multi-Node Tests (Windows)'
vmImage: 'vs2017-win2016'
vmImage: windows-latest
scriptFileName: 'build.cmd'
scriptArgs: MultiNodeTests incremental targetBranch=v1.3
outputDirectory: 'TestResults'
Expand All @@ -106,7 +106,7 @@ jobs:
parameters:
name: 'nuget_pack'
displayName: 'NuGet Pack'
vmImage: 'vs2017-win2016'
vmImage: windows-latest
scriptFileName: build.cmd
scriptArgs: CreateNuget nugetprerelease=dev incremental targetBranch=v1.3
outputDirectory: 'bin/nuget'
Expand Down
2 changes: 1 addition & 1 deletion build-system/windows-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema for reference

pool:
vmImage: vs2017-win2016
vmImage: windows-latest
demands: Cmd

trigger:
Expand Down
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $NugetUrl = "https://dist.nuget.org/win-x86-commandline/v$NugetVersion/nuget.exe
$ProtobufVersion = "3.4.0"
$DocfxVersion = "2.40.5"

$IncrementalistVersion = "0.1.4";
$IncrementalistVersion = "0.9.0";

# Make sure tools folder exists
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
Expand Down
7 changes: 4 additions & 3 deletions src/Akka.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AROUND_MULTIPLICATIVE_OP/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">//-----------------------------------------------------------------------&#xD;
// &lt;copyright file="$FILENAME$" company="Akka.NET Project"&gt;&#xD;
// Copyright (C) 2009-$CURRENT_YEAR$ Lightbend Inc. &lt;http://www.lightbend.com&gt;&#xD;
// Copyright (C) 2013-$CURRENT_YEAR$ .NET Foundation &lt;https://github.com/akkadotnet/akka.net&gt;&#xD;
// &lt;copyright file="${File.FileName}" company="Akka.NET Project"&gt;&#xD;
// Copyright (C) 2009-${CurrentDate.Year} Lightbend Inc. &lt;http://www.lightbend.com&gt;&#xD;
// Copyright (C) 2013-${CurrentDate.Year} .NET Foundation &lt;https://github.com/akkadotnet/akka.net&gt;&#xD;
// &lt;/copyright&gt;&#xD;
//-----------------------------------------------------------------------</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FSM/@EntryIndexedValue">FSM</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECodeCleanup_002EFileHeader_002EFileHeaderSettingsMigrate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/RemotePingPong/RemotePingPong.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<AssemblyName>RemotePingPong</AssemblyName>
<VersionPrefix>1.3.0</VersionPrefix>
<Authors>Akka.NET Team</Authors>
<TargetFrameworks>net461;netcoreapp1.1</TargetFrameworks>
<TargetFrameworks>net452;netcoreapp1.1</TargetFrameworks>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,11 @@ namespace Akka.Remote.Serialization
public override string Manifest(object obj) { }
public override byte[] ToBinary(object obj) { }
}
public sealed class PrimitiveSerializers : Akka.Serialization.Serializer
public sealed class PrimitiveSerializers : Akka.Serialization.SerializerWithStringManifest
{
public PrimitiveSerializers(Akka.Actor.ExtendedActorSystem system) { }
public override bool IncludeManifest { get; }
public override object FromBinary(byte[] bytes, System.Type type) { }
public PrimitiveSerializers(Akka.Actor.ExtendedActorSystem system, Akka.Configuration.Config config) { }
public override object FromBinary(byte[] bytes, string manifest) { }
public override string Manifest(object obj) { }
public override byte[] ToBinary(object obj) { }
}
public class ProtobufSerializer : Akka.Serialization.Serializer
Expand Down
1 change: 1 addition & 0 deletions src/core/Akka.FSharp.Tests/Akka.FSharp.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(XunitVersion)" />
<PackageReference Update="FSharp.Core" Version="4.5.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
1 change: 1 addition & 0 deletions src/core/Akka.FSharp/Akka.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageReference Include="FSharp.Quotations.Evaluator" Version="1.1.3" />
<PackageReference Include="FsPickler" Version="5.2.0" />
<PackageReference Include="FSharp.Core" Version="4.5.0" />
<PackageReference Update="FSharp.Core" Version="4.5.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<ProjectReference Include="..\Akka.Persistence\Akka.Persistence.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.5.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
Expand Down
10 changes: 9 additions & 1 deletion src/core/Akka.Remote.Tests/RemoteConfigSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ public void Remoting_should_contain_correct_hostname_values_in_ReferenceConf()
//Non-specified hostnames should default to IPAddress.Any
Assert.Equal(IPAddress.Any.ToString(), s.Hostname);
Assert.Equal(IPAddress.Any.ToString(), s.PublicHostname);
}
}

[Fact]
public void Remoting_should_contain_correct_PrimitiveSerializer_settings_in_ReferenceConf()
{
var c = RARP.For(Sys).Provider.RemoteSettings.Config.GetConfig("akka.actor.serialization-settings.primitive");
c.Should().NotBeNull();
c.GetBoolean("use-legacy-behavior").Should().BeTrue();
}
}
}

43 changes: 43 additions & 0 deletions src/core/Akka.Remote.Tests/Serialization/BugFix5279Spec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// //-----------------------------------------------------------------------
// // <copyright file="BugFix5279Spec.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2021 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

using Akka.Actor;
using Akka.Configuration;
using Akka.Remote.Serialization;
using Akka.TestKit;
using Akka.Util;
using Xunit;
using FluentAssertions;

namespace Akka.Remote.Tests.Serialization
{
public class BugFix5279Spec: AkkaSpec
{
[Theory]
[InlineData(1, "I")]
[InlineData(1L, "L")]
[InlineData("1", "S")]
public void PrimitiveSerializer_without_useNeutralPrimitives_should_return_custom_manifest(object data, string manifest)
{
var config = ConfigurationFactory.ParseString("use-legacy-behavior = off");
var serializer = new PrimitiveSerializers((ExtendedActorSystem)Sys, config);
serializer.Manifest(data).Should().Be(manifest);
}

[Theory]
[InlineData(1)]
[InlineData(1L)]
[InlineData("1")]
public void PrimitiveSerializer_without_useNeutralPrimitives_should_return_type_manifest(object data)
{
var config = ConfigurationFactory.ParseString("use-legacy-behavior = on");
var serializer = new PrimitiveSerializers((ExtendedActorSystem)Sys, config);
serializer.Manifest(data).Should().Be(data.GetType().TypeQualifiedName());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Akka.Configuration;
using Akka.Remote.Configuration;
using Akka.Remote.Serialization;
using Akka.Serialization;
using Akka.TestKit;
using FluentAssertions;
using Xunit;
Expand Down Expand Up @@ -57,16 +58,29 @@ public void Can_serialize_String(string value)

private T AssertAndReturn<T>(T message)
{
var serializer = Sys.Serialization.FindSerializerFor(message);
var serializer = (SerializerWithStringManifest)Sys.Serialization.FindSerializerFor(message);
serializer.Should().BeOfType<PrimitiveSerializers>();
var serializedBytes = serializer.ToBinary(message);
return (T)serializer.FromBinary(serializedBytes, typeof(T));
var manifest = serializer.Manifest(message);
return (T)serializer.FromBinary(serializedBytes, manifest);
}

private T AssertCrossPlatformAndReturn<T>(T message)
{
var serializer = (SerializerWithStringManifest)Sys.Serialization.FindSerializerFor(message);
serializer.Should().BeOfType<PrimitiveSerializers>();
var serializedBytes = serializer.ToBinary(message);
// GetType() will make sure that each namespace is compatible with the serializer
// as the test is run on each platform.
return (T)serializer.FromBinary(serializedBytes, message.GetType());
}

private void AssertEqual<T>(T message)
{
var deserialized = AssertAndReturn(message);
Assert.Equal(message, deserialized);
deserialized = AssertCrossPlatformAndReturn(message);
Assert.Equal(message, deserialized);
}
}
}
6 changes: 5 additions & 1 deletion src/core/Akka.Remote/Configuration/Remote.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
# actor.jar, because otherwise they would be repeated in config rendering.

akka {

actor {
serialization-settings {
primitive {
use-legacy-behavior = on
}
}

serializers {
akka-containers = "Akka.Remote.Serialization.MessageContainerSerializer, Akka.Remote"
Expand Down
Loading

0 comments on commit 506f8d0

Please sign in to comment.