creating actor in Test file throws ActorInitializationException

335 views
Skip to first unread message

Adrian M

unread,
Sep 17, 2013, 1:26:08 PM9/17/13
to akka...@googlegroups.com
Hi,
I have some testcases in a project which I moved to another project (along with their dependencies).
The testcases are not working anymore because every time I create an actor I get this exception:
How can I make this exception go away?

[akka://ClusterSystem/user/$$a] 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

        at akka.actor.ActorInitializationException$.apply(Actor.scala:218)
        at akka.actor.ActorCell.create(ActorCell.scala:578)
        at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:425)
        at akka.actor.ActorCell.systemInvoke(ActorCell.scala:447)
        at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:262)
        at akka.testkit.CallingThreadDispatcher.process$1(CallingThreadDispatche
r.scala:244)
        at akka.testkit.CallingThreadDispatcher.runQueue(CallingThreadDispatcher
.scala:284)
        at akka.testkit.CallingThreadDispatcher.register(CallingThreadDispatcher
.scala:153)
        at akka.dispatch.MessageDispatcher.attach(AbstractDispatcher.scala:133)
        at akka.actor.dungeon.Dispatch$class.start(Dispatch.scala:84)
        at akka.actor.ActorCell.start(ActorCell.scala:338)
        at akka.testkit.TestActorRef.<init>(TestActorRef.scala:50)
        at akka.testkit.TestActorRef$.apply(TestActorRef.scala:141)
        at akka.testkit.TestActorRef$.apply(TestActorRef.scala:137)
        at akka.testkit.TestActorRef$.apply(TestActorRef.scala:146)
        at akka.testkit.TestActorRef$.apply(TestActorRef.scala:144)
        at test.scala.SvcsServicesTests$$anonfun$1.apply$mcV$sp(SvcsServicesTest
s.scala:305)
        at test.scala.SvcsServicesTests$$anonfun$1.apply(SvcsServicesTests.scala
:303)
        at test.scala.SvcsServicesTests$$anonfun$1.apply(SvcsServicesTests.scala
:303)
        at org.scalatest.FlatSpec$$anon$1.apply(FlatSpec.scala:3062)
        at org.scalatest.Suite$class.withFixture(Suite.scala:1099)
        at test.scala.SvcsServicesTests.withFixture(SvcsServicesTests.scala:31)
        at org.scalatest.FlatSpec$class.invokeWithFixture$1(FlatSpec.scala:3059)

        at org.scalatest.FlatSpec$$anonfun$runTest$1.apply(FlatSpec.scala:3071)
        at org.scalatest.FlatSpec$$anonfun$runTest$1.apply(FlatSpec.scala:3071)
        at org.scalatest.SuperEngine.runTestImpl(Engine.scala:234)
        at org.scalatest.FlatSpec$class.runTest(FlatSpec.scala:3071)
        at test.scala.SvcsServicesTests.runTest(SvcsServicesTests.scala:31)
        at org.scalatest.FlatSpec$$anonfun$runTests$1.apply(FlatSpec.scala:3129)
        at org.scalatest.FlatSpec$$anonfun$runTests$1.apply(FlatSpec.scala:3129)

        at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.
scala:330)
        at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.
scala:318)
        at scala.collection.immutable.List.foreach(List.scala:318)
        at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:318)
        at org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch
(Engine.scala:309)
        at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.
scala:338)
        at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.
scala:318)
        at scala.collection.immutable.List.foreach(List.scala:318)
        at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:318)
        at org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch
(Engine.scala:313)
        at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:394)
        at org.scalatest.FlatSpec$class.runTests(FlatSpec.scala:3129)
        at test.scala.SvcsServicesTests.runTests(SvcsServicesTests.scala:31)
        at org.scalatest.Suite$class.run(Suite.scala:1426)
        at test.scala.SvcsServicesTests.org$scalatest$FlatSpec$$super$run(SvcsSe
rvicesTests.scala:31)
        at org.scalatest.FlatSpec$$anonfun$run$1.apply(FlatSpec.scala:3175)
        at org.scalatest.FlatSpec$$anonfun$run$1.apply(FlatSpec.scala:3175)
        at org.scalatest.SuperEngine.runImpl(Engine.scala:430)
        at org.scalatest.FlatSpec$class.run(FlatSpec.scala:3175)
        at test.scala.SvcsServicesTests.run(SvcsServicesTests.scala:31)
        at org.scalatest.tools.ScalaTestFramework$ScalaTestRunner.run(ScalaTestF
ramework.scala:267)
        at org.scalatools.testing.Runner2.run(Runner2.java:16)
        at sbt.TestRunner.delegateRun(TestFramework.scala:57)
        at sbt.TestRunner.run(TestFramework.scala:51)
        at sbt.TestRunner.runTest$1(TestFramework.scala:71)
        at sbt.TestRunner.run(TestFramework.scala:80)
        at sbt.TestFramework$$anonfun$9$$anonfun$apply$9$$anonfun$10$$anonfun$ap
ply$10.apply(TestFramework.scala:188)
        at sbt.TestFramework$$anonfun$9$$anonfun$apply$9$$anonfun$10$$anonfun$ap
ply$10.apply(TestFramework.scala:188)
        at sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework
.scala:200)
        at sbt.TestFramework$$anonfun$9$$anonfun$apply$9$$anonfun$10.apply(TestF
ramework.scala:188)
        at sbt.TestFramework$$anonfun$9$$anonfun$apply$9$$anonfun$10.apply(TestF
ramework.scala:188)
        at sbt.Tests$$anonfun$makeSerial$1$$anonfun$apply$8.apply(Tests.scala:12
1)
        at sbt.Tests$$anonfun$makeSerial$1$$anonfun$apply$8.apply(Tests.scala:12
1)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike
.scala:233)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike
.scala:233)
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.
scala:59)
        at scala.collection.immutable.List.foreach(List.scala:76)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:233)

        at scala.collection.immutable.List.map(List.scala:76)
        at sbt.Tests$$anonfun$makeSerial$1.apply(Tests.scala:121)
        at sbt.Tests$$anonfun$makeSerial$1.apply(Tests.scala:121)
        at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:47)
        at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:47)
        at sbt.std.Transform$$anon$5.work(System.scala:71)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:23
2)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:23
2)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
        at sbt.Execute.work(Execute.scala:238)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestric
tions.scala:160)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
        at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: akka.actor.ActorInitializationException: Could not instantiate Actor


My test file in path services/src/main/test/scala is:

package test.scala

import svcs.testing.actors._
import com.verticalscope.forum.BBCodeToHtmlTransform
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.verb._
import akka.actor.PoisonPill
import akka.actor.{PoisonPill, ActorSystem, Props, Actor}
import akka.actor.{Kill, Props}
import akka.cluster.ClusterEvent.{CurrentClusterState, MemberUp}

import concurrent.duration._
import org.scalatest.FlatSpec
import org.scalatest.matchers.{MustMatchers, ShouldMatchers}
import akka.actor._
import akka.testkit.TestActorRef
import akka.testkit._

import akka.testkit.TestKit._
import com.verticalscope.services.Messages.RemoveService
import com.typesafe.config.ConfigFactory

class SvcsServicesTests extends FlatSpec /*with AkkaSpec */with ShouldMatchers with MustMatchers /*with ImplicitSender*/ {
  val shutdownTime= 1000 milliseconds


 "Client subscribed to service - first client on, then server on" should "register w each other" in { //within(20 seconds) {
  implicit val system= ActorSystem("ClusterSystem")
    val testClientRef= TestActorRef[TestClient]      //<--exception
    val testClient= testClientRef.underlyingActor  
    testClient.servicesSubscription must equal(Map())
    Thread.sleep(2000)

    val testServer= TestActorRef[TestServer]   //<--exception
    Thread.sleep(2000)

    println(" ActorEquality: "+testServer + " === "+testClient.servicesSubscription.get(testClient.servicesNeeded.toList(0)).get.find(sp=>sp.actor==testServer).get.actor)
    testServer must equal( testClient.servicesSubscription.get(testClient.servicesNeeded.toList(0)).get.find(sp=>sp.actor==testServer).get.actor)
    shutdownActorSystem(system, shutdownTime, false)

    //shutdownActorSystem(system, shutdownTime, false)
  }


}


I declare the actors used in another file in the same test folder: services/src/main/test/scala

package svcs.testing.actors
import com.verticalscope.services.{ServiceProviderTrait, MessageAckServicesTrait, ClientTrait}

  class TestClient extends MessageAckServicesTrait with ClientTrait {
    override def servicesNeeded= Set("serviceY")
  }
  class TestServer extends MessageAckServicesTrait with ServiceProviderTrait {
    val serverName="server"
    override var serviceName ="serviceY"
  }

Akka Team

unread,
Sep 18, 2013, 7:43:56 AM9/18/13
to Akka User List
Hi Adrian,


On Tue, Sep 17, 2013 at 7:26 PM, Adrian M <eamo...@gmail.com> wrote:
Hi,
I have some testcases in a project which I moved to another project (along with their dependencies).
The testcases are not working anymore because every time I create an actor I get this exception:
How can I make this exception go away?

[akka://ClusterSystem/user/$$a] 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

        at akka.actor.ActorInitializationException$.apply(Actor.scala:218)



I declare the actors used in another file in the same test folder: services/src/main/test/scala

package svcs.testing.actors
import com.verticalscope.services.{ServiceProviderTrait, MessageAckServicesTrait, ClientTrait}

  class TestClient extends MessageAckServicesTrait with ClientTrait {
    override def servicesNeeded= Set("serviceY")
  }
  class TestServer extends MessageAckServicesTrait with ServiceProviderTrait {
    val serverName="server"
    override var serviceName ="serviceY"
  }

Are TestClient and TestServer declared in an enclosing class/trait/object? Looking at the indentation in your snippet it might be the case.

-Endre
 

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> 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/groups/opt_out.



--
Akka Team
Typesafe - The software stack for applications that scale
Blog: letitcrash.com
Twitter: @akkateam

Adrian M

unread,
Sep 19, 2013, 4:05:16 PM9/19/13
to akka...@googlegroups.com
Hi,
Well ... yes and no. I have client and server traits which I extend in TestClient and TestServer as shown here: class TestClient extends MessageAckServicesTrait with ClientTrait { .. }

The issue is that I can run this in another project fine. But copying the tests to another project throws the actor initialization error.

I tried to have the test class do "extends TestKit(ActorSystem("testSystem"))" in the hopes that it would use that actor system, but this didn't help.

Any clues?

Akka Team

unread,
Sep 23, 2013, 11:52:20 AM9/23/13
to akka...@googlegroups.com
Hi Adrian,

without the full exception (i.e. including the cause) there is not much I can tell you; does the class extend Actor? 

Regards,

Roland
Reply all
Reply to author
Forward
0 new messages