如何在测试类中创建 TestActorRef。具体来说,我有以下测试设置......
class MatchingEngineSpec extends TestKit(ActorSystem("Securities-Exchange"))
with FeatureSpecLike
with GivenWhenThen
with Matchers {
val google = Security("GOOG")
val ticker = Agent(Tick(google, None, None, None))
val marketRef = TestActorRef(new DoubleAuctionMarket(google, ticker) with BasicMatchingEngine)
val market = marketRef.underlyingActor
...当我运行测试时,一切都通过了,但是在关闭 ActorSystem 后,我得到了这个很长的错误跟踪......
[ERROR] [03/10/2015 15:07:55.571] [Securities-Exchange-akka.actor.default-dispatcher-4] [akka://Securities-Exchange/user/$$b] Could not instantiate Actor
Make sure Actor is NOT defined inside a class/trait,
if so put it outside the class/trait, f.e. in a companion object,
OR try to change: 'actorOf(Props[MyActor]' to 'actorOf(Props(new MyActor)'.
akka.actor.ActorInitializationException: exception during creation
我遇到了这个先前的问题,但在这种情况下,接受的答案对我不起作用。
如果它是相关的,这里是DoubleAuctionMarket
演员的定义......
class DoubleAuctionMarket(val security: Security, val ticker: Agent[Tick]) extends Actor with ActorLogging {
this: MatchingEngine =>
...