Skip to content

Commit

Permalink
close #1709 verify that FSMs with constructor agruments can be instan…
Browse files Browse the repository at this point in the history
…tiated (#2451)

Merged. some perf tests are failing. But only by a very small margin. And would attribute those to build server busyness.
  • Loading branch information
Aaronontheweb authored and Danthar committed Jan 16, 2017
1 parent 1963573 commit cd1a851
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/core/Akka.TestKit.Tests/Akka.TestKit.Tests.csproj
Expand Up @@ -65,6 +65,7 @@
</Compile>
<Compile Include="NoImplicitSenderSpec.cs" />
<Compile Include="TestActorRefTests\BossActor.cs" />
<Compile Include="TestActorRefTests\FsmActor.cs" />
<Compile Include="TestActorRefTests\WatchAndForwardActor.cs" />
<Compile Include="TestActorRefTests\Logger.cs" />
<Compile Include="TestActorRefTests\NestingActor.cs" />
Expand Down
57 changes: 57 additions & 0 deletions src/core/Akka.TestKit.Tests/TestActorRefTests/FsmActor.cs
@@ -0,0 +1,57 @@
//-----------------------------------------------------------------------
// <copyright file="FsmActor.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 Akka.Actor;

namespace Akka.TestKit.Tests.TestActorRefTests
{
public enum TestFsmState
{
First,
Last
}

public class FsmActor : FSM<TestFsmState, string>
{
private readonly IActorRef _replyActor;

public FsmActor(IActorRef replyActor)
{
_replyActor = replyActor;

When(TestFsmState.First, e =>
{
if (e.FsmEvent.Equals("check"))
{
_replyActor.Tell("first");
}
else if (e.FsmEvent.Equals("next"))
{
return GoTo(TestFsmState.Last);
}
return Stay();
});

When(TestFsmState.Last, e =>
{
if (e.FsmEvent.Equals("check"))
{
_replyActor.Tell("last");
}
else if (e.FsmEvent.Equals("next"))
{
return GoTo(TestFsmState.First);
}
return Stay();
});

StartWith(TestFsmState.First, "foo");
}
}
}
26 changes: 26 additions & 0 deletions src/core/Akka.TestKit.Tests/TestActorRefTests/TestActorRefSpec.cs
Expand Up @@ -185,6 +185,32 @@ public void TestActorRef_must_proxy_receive_for_the_underlying_actor_with_sender
ExpectMsg("workDone");
}

[Fact]
public void TestFsmActorRef_must_proxy_receive_for_underlying_actor_with_sender()
{
var a = new TestFSMRef<FsmActor, TestFsmState, string>(Sys, Props.Create(() => new FsmActor(TestActor)));
a.Receive("check");
ExpectMsg("first");

// verify that we can change state
a.SetState(TestFsmState.Last);
a.Receive("check");
ExpectMsg("last");
}

[Fact]
public void BugFix1709_TestFsmActorRef_must_work_with_Fsms_with_constructor_arguments()
{
var a = ActorOfAsTestFSMRef<FsmActor, TestFsmState, string>(Props.Create(() => new FsmActor(TestActor)));
a.Receive("check");
ExpectMsg("first");

// verify that we can change state
a.SetState(TestFsmState.Last);
a.Receive("check");
ExpectMsg("last");
}

private class SaveStringActor : TActorBase
{
public string ReceivedString { get; private set; }
Expand Down
22 changes: 16 additions & 6 deletions src/core/Akka.TestKit/TestKitBase_ActorOf.cs
Expand Up @@ -119,18 +119,32 @@ public IActorRef ActorOf(Action<IActorDsl> configure, string name = null)
return ActExtensions.ActorOf(this, configure, name);
}


/// <summary>
/// Creates an <see cref="ActorSelection(Akka.Actor.ActorPath)"/>
/// </summary>
/// <param name="actorPath">The path of the actor(s) we want to select.</param>
/// <returns>An ActorSelection</returns>
public ActorSelection ActorSelection(ActorPath actorPath)
{
return Sys.ActorSelection(actorPath);
}

///<summary>
/// Creates an <see cref="ActorSelection(string)"/>
/// </summary>
/// <param name="actorPath">The path of the actor(s) we want to select.</param>
/// <returns>An ActorSelection</returns>
public ActorSelection ActorSelection(string actorPath)
{
return Sys.ActorSelection(actorPath);
}


/// <summary>
/// Creates an <see cref="ActorSelection(string)"/>
/// </summary>
/// <param name="anchorRef">The base actor that anchros the <see cref="actorPath"/>.</param>
/// <param name="actorPath">The path of the actor(s) we want to select.</param>
/// <returns>An ActorSelection</returns>
public ActorSelection ActorSelection(IActorRef anchorRef, string actorPath)
{
return Sys.ActorSelection(anchorRef, actorPath);
Expand Down Expand Up @@ -218,10 +232,6 @@ public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(string name = null) wh
}






/// <summary>
/// Create a new <see cref="FSM{TState,TData}"/> as child of the specified supervisor
/// and returns it as <see cref="TestFSMRef{TActor,TState,TData}"/> to enable inspecting and modifying the FSM directly.
Expand Down

0 comments on commit cd1a851

Please sign in to comment.