Skip to content

Commit

Permalink
Bump Hyperion to 0.12.2 (#5805)
Browse files Browse the repository at this point in the history
* Bump Hyperion to 0.12.2

* Add HyperionSerializerSettings immutable modifier methods

* Fix unit tests
  • Loading branch information
Arkatufus authored Apr 1, 2022
1 parent ab332ea commit 0309498
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<XunitVersion>2.4.1</XunitVersion>
<XunitRunnerVersion>2.4.3</XunitRunnerVersion>
<TestSdkVersion>17.0.0</TestSdkVersion>
<HyperionVersion>0.12.0</HyperionVersion>
<HyperionVersion>0.12.2</HyperionVersion>
<NewtonsoftJsonVersion>[12.0.3,)</NewtonsoftJsonVersion>
<NBenchVersion>2.0.1</NBenchVersion>
<ProtobufVersion>3.19.4</ProtobufVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ public void TypeFilter_defined_in_config_should_filter_serializer_properly(objec
");
using (var system = ActorSystem.Create(nameof(HyperionConfigTests), config))
{
var serializer = (HyperionSerializer)system.Serialization.FindSerializerForType(typeof(object));
var deserializer = (HyperionSerializer)system.Serialization.FindSerializerForType(typeof(object));
var serializer = new HyperionSerializer(null, deserializer.Settings.WithDisallowUnsafeType(false));

((TypeFilter)serializer.Settings.TypeFilter).FilteredTypes.Count.Should().Be(2);
((TypeFilter)deserializer.Settings.TypeFilter).FilteredTypes.Count.Should().Be(2);

var serialized = serializer.ToBinary(sampleObject);
object deserialized = null;
Action act = () => deserialized = serializer.FromBinary<object>(serialized);
Action act = () => deserialized = deserializer.FromBinary<object>(serialized);
if (shouldSucceed)
{
act.Should().NotThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ public void Setup_surrogate_should_work()
[MemberData(nameof(DangerousObjectFactory))]
public void Setup_disallow_unsafe_type_should_work(object dangerousObject, Type type)
{
var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, HyperionSerializerSettings.Default);
var deserializer = new HyperionSerializer((ExtendedActorSystem)Sys, HyperionSerializerSettings.Default);
var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, deserializer.Settings.WithDisallowUnsafeType(false));
var serialized = serializer.ToBinary(dangerousObject);
serializer.Invoking(s => s.FromBinary(serialized, type)).Should().Throw<SerializationException>();
deserializer.Invoking(s => s.FromBinary(serialized, type)).Should().Throw<SerializationException>();
}

[Theory]
Expand All @@ -146,12 +147,13 @@ public void Setup_TypeFilter_should_filter_types_properly(object sampleObject, b
.Build());

var settings = setup.ApplySettings(HyperionSerializerSettings.Default);
var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, settings);

((TypeFilter)serializer.Settings.TypeFilter).FilteredTypes.Count.Should().Be(2);
var deserializer = new HyperionSerializer((ExtendedActorSystem)Sys, settings);
var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, deserializer.Settings.WithDisallowUnsafeType(false));
var serialized = serializer.ToBinary(sampleObject);

((TypeFilter)deserializer.Settings.TypeFilter).FilteredTypes.Count.Should().Be(2);
object deserialized = null;
Action act = () => deserialized = serializer.FromBinary<object>(serialized);
Action act = () => deserialized = deserializer.FromBinary<object>(serialized);
if (shouldSucceed)
{
act.Should().NotThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,5 +401,75 @@ public HyperionSerializerSettings(
DisallowUnsafeType = disallowUnsafeType;
TypeFilter = typeFilter;
}

public HyperionSerializerSettings WithPreserveObjectReference(bool preserveObjectReferences)
=> new HyperionSerializerSettings(
preserveObjectReferences: preserveObjectReferences,
versionTolerance: VersionTolerance,
knownTypesProvider: KnownTypesProvider,
packageNameOverrides: PackageNameOverrides,
surrogates: Surrogates,
disallowUnsafeType: DisallowUnsafeType,
typeFilter: TypeFilter);

public HyperionSerializerSettings WithVersionTolerance(bool versionTolerance)
=> new HyperionSerializerSettings(
preserveObjectReferences: PreserveObjectReferences,
versionTolerance: versionTolerance,
knownTypesProvider: KnownTypesProvider,
packageNameOverrides: PackageNameOverrides,
surrogates: Surrogates,
disallowUnsafeType: DisallowUnsafeType,
typeFilter: TypeFilter);

public HyperionSerializerSettings WithKnownTypesProvider(Type knownTypesProvider)
=> new HyperionSerializerSettings(
preserveObjectReferences: PreserveObjectReferences,
versionTolerance: VersionTolerance,
knownTypesProvider: knownTypesProvider,
packageNameOverrides: PackageNameOverrides,
surrogates: Surrogates,
disallowUnsafeType: DisallowUnsafeType,
typeFilter: TypeFilter);

public HyperionSerializerSettings WithPackageNameOverrides(IEnumerable<Func<string, string>> packageNameOverrides)
=> new HyperionSerializerSettings(
preserveObjectReferences: PreserveObjectReferences,
versionTolerance: VersionTolerance,
knownTypesProvider: KnownTypesProvider,
packageNameOverrides: packageNameOverrides,
surrogates: Surrogates,
disallowUnsafeType: DisallowUnsafeType,
typeFilter: TypeFilter);

public HyperionSerializerSettings WithSurrogates(IEnumerable<Surrogate> surrogates)
=> new HyperionSerializerSettings(
preserveObjectReferences: PreserveObjectReferences,
versionTolerance: VersionTolerance,
knownTypesProvider: KnownTypesProvider,
packageNameOverrides: PackageNameOverrides,
surrogates: surrogates,
disallowUnsafeType: DisallowUnsafeType,
typeFilter: TypeFilter);

public HyperionSerializerSettings WithDisallowUnsafeType(bool disallowUnsafeType)
=> new HyperionSerializerSettings(
preserveObjectReferences: PreserveObjectReferences,
versionTolerance: VersionTolerance,
knownTypesProvider: KnownTypesProvider,
packageNameOverrides: PackageNameOverrides,
surrogates: Surrogates,
disallowUnsafeType: disallowUnsafeType,
typeFilter: TypeFilter);

public HyperionSerializerSettings WithTypeFilter(ITypeFilter typeFilter)
=> new HyperionSerializerSettings(
preserveObjectReferences: PreserveObjectReferences,
versionTolerance: VersionTolerance,
knownTypesProvider: KnownTypesProvider,
packageNameOverrides: PackageNameOverrides,
surrogates: Surrogates,
disallowUnsafeType: DisallowUnsafeType,
typeFilter: typeFilter);
}
}

0 comments on commit 0309498

Please sign in to comment.