The problem is resolved, root cause was my own inability to follow simple 
instructions.

@Anders, thank you so much, that resolved the problem. At some point during 
my attempts to make the test compile (because I picked up old source), the 
scoping went astray.

@Roland, I must have picked up an old version of the documentation, the 
cut-and-pasted code didn't compile, from that point on my 'fixes' just made 
things worse. Regarding Java v Scala, I read too much into the comment in 
the documentation "Due to the conciseness of test DSLs available for Scala (
ScalaTest <http://scalatest.org/>, Specs2 <http://specs2.org/>, ScalaCheck 
<http://code.google.com/p/scalacheck/>), it may be a good idea to write the 
test suite in that language even if the main project is written in Java." 
Sorry if I sounded like I was criticising the Java API, so far I'm loving 
it. I'm coming to Akka bearing the scars of a big Erlang project and it's a 
delight to be able to use industry-standard IDE, tools and libraries!

Thanks again.
Tom.

On Tuesday, 7 April 2015 23:38:33 UTC+1, Tom Hay wrote:
>
> Hi, I'm an Akka noob so apologies if this is a dumb question. I'm trying 
> to make the Testkit work with Java, starting with JUnit testing. Example 
> taken from documentation, tweaked to make it compile, source included 
> below. When I run the test using JUnit 4 in Eclipse Luna, I get the stack 
> trace below.  I'm using 2.11-2.3.9 jars. There hasn't been any discussion 
> of testkit for a couple of years, has everyone given up on Java and moved 
> to the Scala version? Or am I doing something stupid? (I have non-testkit 
> Akka systems runnning happily in the same build / run environment).
>
> TIA,
> Tom.
>
> akka.actor.ActorInitializationException: You cannot create an instance of 
> [test.MyActor] explicitly using the constructor (new). You have to use one 
> of the 'actorOf' factory methods to create a new actor. See the 
> documentation.
> at akka.actor.ActorInitializationException$.apply(Actor.scala:165)
> at akka.actor.Actor$class.$init$(Actor.scala:421)
> at akka.actor.UntypedActor.<init>(UntypedActor.scala:97)
> at test.MyActor.<init>(MyActor.java:12)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
> at 
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195)
> at 
> org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)
> at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
> 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:459)
> at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
> at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
> at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
>
>
>
> package test;
>
> import static org.junit.Assert.*;
>
> import org.junit.Test;
>
> import akka.actor.ActorSystem;
> import akka.actor.Props;
> import akka.actor.UntypedActor;
> import akka.testkit.TestActorRef;
>
> public class MyActor extends UntypedActor {
> public void onReceive(Object o) throws Exception {
> if (o.equals("say42")) {
> getSender().tell(42, getSelf());
> } else if (o instanceof Exception) {
> throw (Exception) o;
> }
> }
> public boolean testMe() { return true; }
>
>
> @Test
> public void demonstrateTestActorRef() {
> final ActorSystem system = ActorSystem.apply();
> final Props props = Props.create(MyActor.class);
> final TestActorRef<MyActor> ref = TestActorRef.create(system, props, 
> "testA");
> final MyActor actor = ref.underlyingActor();
> assertTrue(actor.testMe());
> }
> }
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to