TestProbe() and actorSelection

323 views
Skip to first unread message

Kostas kougios

unread,
May 21, 2015, 1:22:49 AM5/21/15
to akka...@googlegroups.com
Hi, I am trying to test actor code that uses actorSelection:

val path = RootActorPath(member.address, name = "/user/clusterKeeper")
context.actorSelection(path).resolveOne(5 seconds).foreach {
clusterKeeper =>
clusterKeeper ! msg
}


member.address comes from akka clusters and has the address of the remote actor.

Now I need to mock/probe the clusterKeeper actor but TestProbe() doesn't have a way of defining the name of the actor or it's path. In fact it goes down to TestKitBase where it is hardcoded:

val testActor: ActorRef = {
val impl = system.asInstanceOf[ExtendedActorSystem]
val ref = impl.systemActorOf(TestActor.props(queue)
.withDispatcher(CallingThreadDispatcher.Id),
"testActor" + TestKit.testActorId.incrementAndGet)
awaitCond(ref match {
case r: RepointableRef r.isStarted
case _ true
}, 1 second, 10 millis)
ref
}

Is there a way with the testkit to test this? Ofcourse I could create an actor myself but then I would have to reimpl all expectMsg or maybe have it forward the messages to testkit.

Similar post :
https://groups.google.com/forum/#!searchin/akka-user/testprobe$20actorSelection/akka-user/ETL4XQr1Sj4/N9lo_6gc8voJ

Patrik Nordwall

unread,
May 22, 2015, 9:09:48 AM5/22/15
to akka...@googlegroups.com
I would start an actor on that path that forwards all messages to the test probe.
/Patrik

--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

Konstantinos Kougios

unread,
May 22, 2015, 9:16:21 AM5/22/15
to akka...@googlegroups.com
Thanks Patrik, I actually thought of that too but was wondering if there is any testkit support for it. Then ended up impl a test-only actor that gathers all received messages and my test suite can get them as a stream (blocking if the stream is empty in order to wait for the threading bit to work). Since this is a normal actor, I can create it as I wish and also I can assert on the messages via normal testActor.messages should contain(). I am in the process of writing that code and will replace some of my testcases/TestProbe's with it.
You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/DK0evQ1utCA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Patrik Nordwall

unread,
May 22, 2015, 9:49:05 AM5/22/15
to akka...@googlegroups.com
The forwarding actor is actually included in akka.testkit.TestActors.ForwardActor in Akka 2.4-M1.
/Patrik

Konstantinos Kougios

unread,
May 22, 2015, 9:57:18 AM5/22/15
to akka...@googlegroups.com
nice
Reply all
Reply to author
Forward
0 new messages