On Fri, Mar 27, 2015 at 6:46 AM, Anton Khodakivskiy <[email protected]
> wrote:

> Hello -
>
> I have an FSM that spawns a future on one of its transitions. I pipe the
> result of the future to the FSM. The future can fail and I'd like to stop
> the FSM and report the error.
>
> class MyFsm(startFuture: => Future[T]) extends FSM[...] {
>   when(a) {
>     case Event(aToB, _) => goto(b)
>   }
>
>   onTransition {
>     case a -> b => startFuture.pipeTo(self)
>   }
>
>   whenUnhandled {
>     case Event(Status.Failure(t), _) => stop(FSM.Failure(t))
>   }
> }
>
> As I understand it's best to pass the handling of the error to the
> supervising actor.
>

Then you have to throw the exception instead of stopping the FSM, and let
the supervision strategy of the parent decide to stop it.


> Now how can unit I test this actor, specitifcally the failing case?
>

Perhaps watch it, and verify that you receive Terminated. Testkit provides
watch and expectTerminated.

/Patrik


> I have the following, but I don't know how to check that the FSM is in the
> stopped state with failure.
>
> test("failing future") {
>   def startFuture
>   val fsm = TestFSMRef(new MyFsm(Future(throw new RuntimeException()))
>   fsm ! aToB
> }
>
> Also I currently see logging error message as below. Ideally I'd like to
> handle the exception and prevent the logging error message from appearing.
>
> Thanks,
>
> Anton
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ:
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Patrik Nordwall
Typesafe <http://typesafe.com/> -  Reactive apps on the JVM
Twitter: @patriknw

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to