While Anders has already pointed out the flaw, there were a few other things 
that I’d like to comment on, see inline.

> 8 apr 2015 kl. 00:36 skrev Tom Hay <[email protected]>:
> 
> 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

Where exactly did you find it documented like this? There might be mistakes out 
there, but when I look at the docs 
<http://doc.akka.io/docs/akka/2.3.9/java/testing.html#Asynchronous_Integration_Testing_with_JavaTestKit>
 I see something slightly different :-)

> , 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

What do you mean? TestKit is used my thousands of developers every day, but 
mostly it just works and therefore does not lead to messages being posted here. 
We do get a few questions per month, though.

> , has everyone given up on Java and moved to the Scala version?

What makes you say this? Our observation is that Akka users are firmly 
distributed across both sides of the fence—if you want to call it that—and all 
APIs that we offer present the same power and versatility to each of the 
audiences.

> Or am I doing something stupid? (I have non-testkit Akka systems

I assume that you mean “running outside of tests”, right? Because all Akka 
systems are accessible to TestKit-based verification—variations in degree are 
only due to your particular design choices (i.e. which parts of an Actor you 
make fixed and which are replaceable in a test scenario).

Regards,

Roland

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



Dr. Roland Kuhn
Akka Tech Lead
Typesafe <http://typesafe.com/> – Reactive apps on the JVM.
twitter: @rolandkuhn
 <http://twitter.com/#!/rolandkuhn>

-- 
>>>>>>>>>>      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