make available TestKitLight without implicit ActorRef

This commit is contained in:
Roland 2011-05-29 22:47:55 +02:00
parent 6b6ec0df72
commit 2852e1a763
2 changed files with 23 additions and 2 deletions

View file

@ -387,6 +387,23 @@ invariably lead to spurious test failures on the heavily loaded Jenkins server
internally scaled by a factor taken from ``akka.conf``, internally scaled by a factor taken from ``akka.conf``,
``akka.test.timefactor``, which defaults to 1. ``akka.test.timefactor``, which defaults to 1.
Resolving Conflicts with Implicit ActorRef
------------------------------------------
The :class:`TestKit` trait contains an implicit value of type :class:`ActorRef`
to enable the magic reply handling. This value is named ``self`` so that e.g.
anonymous actors may be declared within a test class without having to care
about the ambiguous implicit issues which would otherwise arise. If you find
yourself in a situation where the implicit you need comes from a different
trait than :class:`TestKit` and is not named ``self``, then use
:class:`TestKitLight`, which differs only in not having any implicit members.
You would then need to make an implicit available in locally confined scopes
which need it, e.g. different test cases. If this cannot be done, you will need
to resort to explicitly specifying the sender reference::
val actor = actorOf[MyWorker].start()
actor.!(msg)(testActor)
Using Multiple Probe Actors Using Multiple Probe Actors
--------------------------- ---------------------------

View file

@ -88,7 +88,7 @@ class TestActor(queue: BlockingDeque[TestActor.Message]) extends Actor with FSM[
* @author Roland Kuhn * @author Roland Kuhn
* @since 1.1 * @since 1.1
*/ */
trait TestKit { trait TestKitLight {
import TestActor.{ Message, RealMessage, NullMessage } import TestActor.{ Message, RealMessage, NullMessage }
@ -99,7 +99,7 @@ trait TestKit {
* ActorRef of the test actor. Access is provided to enable e.g. * ActorRef of the test actor. Access is provided to enable e.g.
* registration as message target. * registration as message target.
*/ */
implicit val testActor = actorOf(new TestActor(queue)).start() val testActor = actorOf(new TestActor(queue)).start()
/** /**
* Implicit sender reference so that replies are possible for messages sent * Implicit sender reference so that replies are possible for messages sent
@ -550,6 +550,10 @@ trait TestKit {
private def format(u: TimeUnit, d: Duration) = "%.3f %s".format(d.toUnit(u), u.toString.toLowerCase) private def format(u: TimeUnit, d: Duration) = "%.3f %s".format(d.toUnit(u), u.toString.toLowerCase)
} }
trait TestKit extends TestKitLight {
implicit val self = testActor
}
/** /**
* TestKit-based probe which allows sending, reception and reply. * TestKit-based probe which allows sending, reception and reply.
*/ */