-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into actor-ref-provider-aliases
- Loading branch information
Showing
13 changed files
with
658 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/contrib/serializers/Akka.Serialization.Hyperion.Tests/HyperionConfigTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="HyperionConfigTests.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2016 Akka.NET project <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Akka.Actor; | ||
using Akka.Configuration; | ||
using Xunit; | ||
|
||
namespace Akka.Serialization.Hyperion.Tests | ||
{ | ||
public class HyperionConfigTests | ||
{ | ||
[Fact] | ||
public void Hyperion_serializer_should_have_correct_defaults() | ||
{ | ||
var config = ConfigurationFactory.ParseString(@" | ||
akka.actor { | ||
serializers.hyperion = ""Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"" | ||
serialization-bindings { | ||
""System.Object"" = hyperion | ||
} | ||
} | ||
"); | ||
using (var system = ActorSystem.Create(nameof(HyperionConfigTests), config)) | ||
{ | ||
var serializer = (HyperionSerializer)system.Serialization.FindSerializerForType(typeof(object)); | ||
Assert.Equal(true, serializer.Settings.VersionTolerance); | ||
Assert.Equal(true, serializer.Settings.PreserveObjectReferences); | ||
Assert.Equal("NoKnownTypes", serializer.Settings.KnownTypesProvider.Name); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Hyperion_serializer_should_allow_to_setup_custom_flags() | ||
{ | ||
var config = ConfigurationFactory.ParseString(@" | ||
akka.actor { | ||
serializers.hyperion = ""Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"" | ||
serialization-bindings { | ||
""System.Object"" = hyperion | ||
} | ||
serialization-settings.hyperion { | ||
preserve-object-references = false | ||
version-tolerance = false | ||
} | ||
} | ||
"); | ||
using (var system = ActorSystem.Create(nameof(HyperionConfigTests), config)) | ||
{ | ||
var serializer = (HyperionSerializer)system.Serialization.FindSerializerForType(typeof(object)); | ||
Assert.Equal(false, serializer.Settings.VersionTolerance); | ||
Assert.Equal(false, serializer.Settings.PreserveObjectReferences); | ||
Assert.Equal("NoKnownTypes", serializer.Settings.KnownTypesProvider.Name); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Hyperion_serializer_should_allow_to_setup_custom_types_provider_with_default_constructor() | ||
{ | ||
var config = ConfigurationFactory.ParseString(@" | ||
akka.actor { | ||
serializers.hyperion = ""Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"" | ||
serialization-bindings { | ||
""System.Object"" = hyperion | ||
} | ||
serialization-settings.hyperion { | ||
known-types-provider = ""Akka.Serialization.Hyperion.Tests.DummyTypesProviderWithDefaultCtor, Akka.Serialization.Hyperion.Tests"" | ||
} | ||
} | ||
"); | ||
using (var system = ActorSystem.Create(nameof(HyperionConfigTests), config)) | ||
{ | ||
var serializer = (HyperionSerializer)system.Serialization.FindSerializerForType(typeof(object)); | ||
Assert.Equal(true, serializer.Settings.VersionTolerance); | ||
Assert.Equal(true, serializer.Settings.PreserveObjectReferences); | ||
Assert.Equal(typeof(DummyTypesProviderWithDefaultCtor), serializer.Settings.KnownTypesProvider); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Hyperion_serializer_should_allow_to_setup_custom_types_provider_with_non_default_constructor() | ||
{ | ||
var config = ConfigurationFactory.ParseString(@" | ||
akka.actor { | ||
serializers.hyperion = ""Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"" | ||
serialization-bindings { | ||
""System.Object"" = hyperion | ||
} | ||
serialization-settings.hyperion { | ||
known-types-provider = ""Akka.Serialization.Hyperion.Tests.DummyTypesProvider, Akka.Serialization.Hyperion.Tests"" | ||
} | ||
} | ||
"); | ||
using (var system = ActorSystem.Create(nameof(HyperionConfigTests), config)) | ||
{ | ||
var serializer = (HyperionSerializer)system.Serialization.FindSerializerForType(typeof(object)); | ||
Assert.Equal(true, serializer.Settings.VersionTolerance); | ||
Assert.Equal(true, serializer.Settings.PreserveObjectReferences); | ||
Assert.Equal(typeof(DummyTypesProvider), serializer.Settings.KnownTypesProvider); | ||
} | ||
} | ||
} | ||
|
||
class DummyTypesProvider : IKnownTypesProvider | ||
{ | ||
public DummyTypesProvider(ExtendedActorSystem system) | ||
{ | ||
if (system == null) | ||
throw new ArgumentNullException(nameof(system)); | ||
} | ||
|
||
public IEnumerable<Type> GetKnownTypes() => Enumerable.Empty<Type>(); | ||
} | ||
|
||
class DummyTypesProviderWithDefaultCtor : IKnownTypesProvider | ||
{ | ||
public IEnumerable<Type> GetKnownTypes() => Enumerable.Empty<Type>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/contrib/serializers/Akka.Serialization.Hyperion/IKnownTypesProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="HyperionSerializer.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2016 Akka.NET project <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Akka.Serialization | ||
{ | ||
/// <summary> | ||
/// Interface that can be implemented in order to determine some | ||
/// custom logic, that's going to provide a list of types that | ||
/// are known to be shared for all corresponding parties during | ||
/// remote communication. | ||
/// </summary> | ||
public interface IKnownTypesProvider | ||
{ | ||
IEnumerable<Type> GetKnownTypes(); | ||
} | ||
|
||
internal sealed class NoKnownTypes : IKnownTypesProvider | ||
{ | ||
public IEnumerable<Type> GetKnownTypes() => new Type[0]; | ||
} | ||
} |
Oops, something went wrong.