Comment créer un TestActorRef dans une classe de test. Plus précisément, je le test suivant mis en place ...Comment créer un TestActorRef dans une classe de test pour un acteur avec des paramètres constructeur?
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
... quand je lance des tests tout passe, mais après l'arrêt du ActorSystem je reçois cette longue trace d'erreur ...
[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
Je suis tombé sur this question précédente, mais la réponse acceptée n'a pas fonctionné pour moi dans ce cas.
Dans le cas où il est pertinent, voici la définition de l'acteur DoubleAuctionMarket
...
class DoubleAuctionMarket(val security: Security, val ticker: Agent[Tick]) extends Actor with ActorLogging {
this: MatchingEngine =>
...
Comment est votre acteur 'DoubleAuctionMarket' définir? – vptheron
J'ai mis à jour la question pour inclure des informations sur l'acteur DoubleAuctionMarket. – davidrpugh
Avez-vous essayé sans le mixin «à la volée» de BasicMatchingEngine? Je ne vois rien de mal avec votre code et votre utilisation de 'TestActorRef'. – vptheron