Skip to content

Commit

Permalink
serialization fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing committed Aug 24, 2015
1 parent cdf5f92 commit 6385cc2
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<Name>Akka.TestKit.NUnit</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override SupervisorStrategy SupervisorStrategy()
return new OneForOneStrategy(10, TimeSpan.FromSeconds(10), reason =>
{
if (reason is IllegalActorStateException) return Directive.Stop;
return Actor.SupervisorStrategy.DefaultDecider(reason);
return Actor.SupervisorStrategy.DefaultDecider.Decide(reason);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public void Serialization_must_serialize_and_deserialize_DaemonMsgCreate_with_fu
[Fact]
public void Serialization_must_serialize_and_deserialize_DaemonMsgCreate_with_Deploy_and_RouterConfig()
{
var supervisorStrategy = new OneForOneStrategy(3, TimeSpan.FromSeconds(10), exception => Directive.Escalate);
var decider = Decider.From(
Directive.Escalate);

var supervisorStrategy = new OneForOneStrategy(3, TimeSpan.FromSeconds(10), decider);
var deploy1 = new Deploy("path1",
ConfigurationFactory.ParseString("a=1"),
new RoundRobinPool(5, null, supervisorStrategy, null),
Expand Down
59 changes: 51 additions & 8 deletions src/core/Akka.Tests/Serialization/SerializationSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,14 @@ public void CanSerializeLocalScope()
[Fact]
public void CanSerializeRoundRobinPool()
{
var message = new RoundRobinPool(10, new DefaultResizer(0,1));
var decider = Decider.From(
Directive.Restart,
Directive.Stop.When<ArgumentException>(),
Directive.Stop.When<NullReferenceException>());

var supervisor = new OneForOneStrategy(decider);

var message = new RoundRobinPool(10, new DefaultResizer(0,1),supervisor,"abc");
AssertEqual(message);
}

Expand All @@ -297,7 +304,14 @@ public void CanSerializeRoundRobinGroup()
[Fact]
public void CanSerializeRandomPool()
{
var message = new RandomPool(10, new DefaultResizer(0, 1));
var decider = Decider.From(
Directive.Restart,
Directive.Stop.When<ArgumentException>(),
Directive.Stop.When<NullReferenceException>());

var supervisor = new OneForOneStrategy(decider);

var message = new RandomPool(10, new DefaultResizer(0, 1),supervisor,"abc");
AssertEqual(message);
}

Expand All @@ -311,29 +325,57 @@ public void CanSerializeRandomGroup()
[Fact]
public void CanSerializeConsistentHashPool()
{
var message = new ConsistentHashingPool(10);
var decider = Decider.From(
Directive.Restart,
Directive.Stop.When<ArgumentException>(),
Directive.Stop.When<NullReferenceException>());

var supervisor = new OneForOneStrategy(decider);

var message = new ConsistentHashingPool(10,null,supervisor,"abc");
AssertEqual(message);
}


[Fact]
public void CanSerializeTailChoppingPool()
{
var message = new TailChoppingPool(10,TimeSpan.FromSeconds(10),TimeSpan.FromSeconds(2));
{
var decider = Decider.From(
Directive.Restart,
Directive.Stop.When<ArgumentException>(),
Directive.Stop.When<NullReferenceException>());

var supervisor = new OneForOneStrategy(decider);

var message = new TailChoppingPool(10,null,supervisor,"abc",TimeSpan.FromSeconds(10),TimeSpan.FromSeconds(2));
AssertEqual(message);
}

[Fact]
public void CanSerializeScatterGatherFirstCompletedPool()
{
var message = new ScatterGatherFirstCompletedPool(10);
var decider = Decider.From(
Directive.Restart,
Directive.Stop.When<ArgumentException>(),
Directive.Stop.When<NullReferenceException>());

var supervisor = new OneForOneStrategy(decider);

var message = new ScatterGatherFirstCompletedPool(10,null,supervisor,"abc",TimeSpan.MaxValue);
AssertEqual(message);
}

[Fact]
public void CanSerializeSmallestMailboxPool()
{
var message = new SmallestMailboxPool(10);
var decider = Decider.From(
Directive.Restart,
Directive.Stop.When<ArgumentException>(),
Directive.Stop.When<NullReferenceException>());

var supervisor = new OneForOneStrategy(decider);

var message = new SmallestMailboxPool(10,null,supervisor,"abc");
AssertEqual(message);
}

Expand All @@ -348,7 +390,8 @@ private void AssertEqual<T>(T message)
{
var serializer = Sys.Serialization.FindSerializerFor(message);
var serialized = serializer.ToBinary(message);
var deserialized = (T)serializer.FromBinary(serialized, typeof(T));
var result = serializer.FromBinary(serialized, typeof(T));
var deserialized = (T) result;

// Assert.True(message.Equals(deserialized));
Assert.Equal(message, deserialized);
Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka/Actor/ActorPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public override bool Equals(object obj)
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
var actorPath = obj as ActorPath;
if (actorPath != null) return Equals(actorPath);
return Equals((Surrogate) obj);

return Equals(actorPath);
}

public override int GetHashCode()
Expand Down
17 changes: 6 additions & 11 deletions src/core/Akka/Actor/SupervisorStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,10 @@ public bool HandleFailure(ActorCell actorCell, Exception cause, ChildRestartStat
/// </summary>
/// <param name="exception">The exception.</param>
/// <returns>Directive.</returns>
public static Directive DefaultDecider(Exception exception)
{
if (exception is ActorInitializationException)
return Directive.Stop;
if (exception is ActorKilledException)
return Directive.Stop;
if (exception is DeathPactException)
return Directive.Stop;

return Directive.Restart;
}
public static IDecider DefaultDecider = Decider.From(Directive.Restart,
Directive.Stop.When<ActorInitializationException>(),
Directive.Stop.When<ActorKilledException>(),
Directive.Stop.When<DeathPactException>());

/// <summary>
/// Restarts the child.
Expand Down Expand Up @@ -364,6 +357,8 @@ public ISurrogated FromSurrogate(ActorSystem system)

public override ISurrogate ToSurrogate(ActorSystem system)
{
if (Decider is LocalOnlyDecider)
throw new NotSupportedException("Can not serialize LocalOnlyDecider");
return new OneForOneStrategySurrogate
{
Decider = Decider,
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Routing/RouterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ protected RouterConfig OverrideUnsetConfig(RouterConfig other)
/// </summary>
public static SupervisorStrategy DefaultStrategy
{
get { return new OneForOneStrategy(10, TimeSpan.FromSeconds(10), ex => Directive.Escalate); }
get { return new OneForOneStrategy(10, TimeSpan.FromSeconds(10), Decider.From(Directive.Escalate)); }
}

#endregion
Expand Down
1 change: 1 addition & 0 deletions src/core/Akka/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="Wire" version="0.0.1" targetFramework="net45" />
</packages>
2 changes: 1 addition & 1 deletion src/examples/FSharp.Api/Supervisioning.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let main() =
Strategy.OneForOne(fun e ->
match e with
| :? CustomException -> Directive.Restart
| _ -> SupervisorStrategy.DefaultDecider(e))) ]
| _ -> SupervisorStrategy.DefaultDecider.Decide(e))) ]

async {
let! response = parent <? Echo "hello world"
Expand Down

0 comments on commit 6385cc2

Please sign in to comment.