I have a Akka Cluster application with two roles: backend and frontend. 
Backend starts sharded actors and do the job. Frontend provides HTTP 
interface for Backend using shard region proxy.

On backend I start shard region as follows: 

ClusterSharding(system).start(
 typeName = UserRegion.shardName,
 entryProps = Some(User.props),
 idExtractor = UserRegion.idExtractor,
 shardResolver = UserRegion.shardResolver
)

And on frontend:

ClusterSharding(system).start(
 typeName = UserRegion.shardName,
 entryProps = None,
 idExtractor = UserRegion.idExtractor,
 shardResolver = UserRegion.shardResolver
)

So my frontend does not know how to instantiate User actor.


In order to test Play! (version 2.4.0) controller in isolation I want to inject 
ActorRef to User actor through controller's constructor.

According documentation 
<https://www.playframework.com/documentation/2.4.x/ScalaAkka> I should 
implement  I have a Akka Cluster application with two roles: backend and 
frontend. Backend starts sharded actors and do the job. Frontend provides HTTP 
interface for Backend using shard region proxy.


On backend I start shard region as follows: 

ClusterSharding(system).start(
 typeName = UserRegion.shardName,
 entryProps = Some(User.props),
 idExtractor = UserRegion.idExtractor,
 shardResolver = UserRegion.shardResolver
)

And on frontend:

ClusterSharding(system).start(
 typeName = UserRegion.shardName,
 entryProps = None,
 idExtractor = UserRegion.idExtractor,
 shardResolver = UserRegion.shardResolver
)

So my frontend does not know how to instantiate User actor.


In order to test Play! (version 2.4.0) controller in isolation I want to inject 
ActorRef of User actor through controller's constructor.

According documentation 
<https://www.playframework.com/documentation/2.4.x/ScalaAkka> I should 
implement AkkaGuiceSupport module:


class UserModule extends AbstractModule with AkkaGuiceSupport {
 def configure = {
   bindActor[User]("user")
 }
}

and then inject User actor using @Named annotation:


@Singleton 
class Application @Inject() (@Named("user") user: ActorRef) (implicit ec: 
ExecutionContext) extends Controller {}

So in my test I could override binding and pass TestProbe() instead of sharded 
actor's ActorRef.


But my frontend does not know how to build User actor and does not contain User 
actor implementation. Normally it should communicate with it using shard region 
proxy.


Could you give me an idea how to inject ActorRef into controller or test it in 
isolation somehow?

-- 
>>>>>>>>>>      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