Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing authored and Horusiath committed Jul 3, 2015
1 parent 9013315 commit 1b82b86
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
41 changes: 41 additions & 0 deletions src/core/Akka.Tests/Routing/RoutingSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,47 @@ public void Router_RemoveRoute_should_remove_existing_routee_and_leave_the_rest(
updatedRouter.Routees.Cast<ActorRefRoutee>().Any(r => ReferenceEquals(r.Actor, blackHole1)).ShouldBe(true);
updatedRouter.Routees.Cast<ActorRefRoutee>().Any(r => ReferenceEquals(r.Actor, blackHole2)).ShouldBe(true);
}

public class RouterSupervisorSpec : AkkaSpec
{
#region Killable actor

private class KillableActor : ReceiveActor
{
private readonly IActorRef TestActor;

public KillableActor(IActorRef testActor)
{
TestActor = testActor;
Receive<string>(s => s == "go away", s => { throw new ArgumentException("Goodbye then!"); });
}
}

#endregion

#region Tests

[Fact]
public void Routers_must_use_provided_supervisor_strategy()
{
var router = Sys.ActorOf(Props.Create(() => new KillableActor(TestActor))
.WithRouter(
new RoundRobinPool(1, null, new AllForOneStrategy(
exception =>
{
TestActor.Tell("supervised");
return Directive.Stop;
}),
null)),
"router1");

router.Tell("go away");

ExpectMsg("supervised", TimeSpan.FromSeconds(2));
}

#endregion
}
}
}

2 changes: 2 additions & 0 deletions src/core/Akka/Actor/ActorCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ private ActorBase NewActor()
{
_state = _state.ClearBehaviorStack();
instance = CreateNewActorInstance();
//TODO: this overwrites any already initiaized supervisor strategy
//We should investigate what we can do to handle this better
instance.SupervisorStrategyInternal = _props.SupervisorStrategy;
//defaults to null - won't affect lazy instantiation unless explicitly set in props
});
Expand Down
9 changes: 7 additions & 2 deletions src/core/Akka/Routing/RouterPoolActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Akka.Routing
/// </summary>
internal class RouterPoolActor : RouterActor
{
// private SupervisorStrategy supervisorStrategy;
private readonly SupervisorStrategy _supervisorStrategy;

protected Pool Pool
{
Expand All @@ -42,7 +42,12 @@ protected Pool Pool
/// <param name="supervisorStrategy">The supervisor strategy.</param>
public RouterPoolActor(SupervisorStrategy supervisorStrategy)
{
SupervisorStrategyInternal = supervisorStrategy;
_supervisorStrategy = supervisorStrategy;
}

protected override SupervisorStrategy SupervisorStrategy()
{
return _supervisorStrategy;
}

/// <summary>
Expand Down

0 comments on commit 1b82b86

Please sign in to comment.