2
votes

Is there any way to get the underlying Actor from an ActorRef using the Akka Actor Test Kit?

I'm aware of TestActorRef, but I can not use them in my tests, since the Actors are instantiated deep in my application. All I can get is their reference. Testing everything with messaging would be a pain.

Thanks!

1

1 Answers

1
votes

What you're attempting is a very bad anti-pattern in Akka. The entire purpose of Actors and their interaction is the isolation - hiding the Actor instance from the outside.

If you were to inspect the Actor instance you'd keep running into race conditions, as such access is not protected by the Actor guarantee of "as-if" single-threadedness.

I strongly suggest building and composing your actors in such a way that you're able to test the interactions they're modeling, and not have to inspect their internal state directly. For example, you could have methods that ask the actor to give it's internal state etc. Point is, that then it's made on purpose and the state that you expose can be different from the one that's actually kept in the instance (easier to evolve and change internal representation).