le-doude
le-doude

Reputation: 3367

JUnit testing Akka actors in play framework 2.0.4 - JAVA ClassNotFoundException on scala.concurrent.duration.Duration

I am trying to implement a JUnit test to test an actor.

I have this ActorTest :

import org.junit.Test;

import play.libs.Akka;
import playtests.PlayFrameworkTest;
import akka.actor.Actor;
import akka.actor.Props;
import akka.actor.UntypedActorFactory;
import akka.testkit.TestActorRef;

public class ActorTest {

    public static FakeApplication dummy;

    @BeforeClass
    public static void startApp() {
        dummy = Helpers.fakeApplication(Helpers.inMemoryDatabase());
        Helpers.start(dummy);
    }

    @AfterClass
    public static void stopApp() {
        Helpers.stop(dummy);
    }


    @Test
    public void test() throws Exception {
        final String myParameter = "someParameter";
        @SuppressWarnings("serial")
        TestActorRef<MyActor> actorRef = TestActorRef.create(Akka.system(), new Props(new UntypedActorFactory() {
            @Override
            public Actor create() {
                return new MyActor(myParameter);
            }
        }), "testActor");
        MyActor actor = actorRef.underlyingActor();

        String message = "message";
        actor.apply(message);
        actor.receive();

    }
}

When I try to run it (both on eclipse and with 'play test' commandline) is I get this exception thrown at the line of the TestActorRef.create()

java.lang.NoClassDefFoundError: scala/concurrent/duration/Duration
    at persistence.actors.ActorTest.test(ActorTest.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: scala.concurrent.duration.Duration
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 26 more

I have looked http://doc.akka.io/docs/akka/snapshot/java/testing.html and http://doc.akka.io/docs/akka/snapshot/scala/testing.html and all I could find on the play framework page.

What am I missing? Why is it not running? I get the same exception if I get my system from Akka.system() and ActorSystem.apply() ... same thing when I pass it my fakeApplication or not.

Upvotes: 1

Views: 1747

Answers (1)

Rich Dougherty
Rich Dougherty

Reputation: 3251

(To summarise the comments above…) The class scala.concurrent.duration.Duration was first included with Scala 2.10. At the time of writing Akka 2.1 and Play 2.1 are the best releases to work with Scala 2.10.

Upvotes: 1

Related Questions