scalaspring / akka-spring-boot

Apache License 2.0
48 stars 12 forks source link

How to unit test? #2

Closed synox closed 7 years ago

synox commented 8 years ago

Hi Lance

Thanks for providing this library. One thing is not clear to me:

How can I start multiple AkkaSystems in a Java-JUnit-Test? Instead of @Autowired ActorSystem i would like to start and stop them within the test case.

Thanks

synox commented 8 years ago

I solved it like this:

get akka Config and the default akka system:

 @Autowired  private Config config;
 @Autowired  private ActorSystem node1;

Create second akka system:

node2 = ActorSystem.create("test", config.withValue("akka.remote.netty.tcp.port", ConfigValueFactory.fromAnyRef(2552)));

After they can be joined as a cluster:

Cluster cluster1 = Cluster.get(node1);
cluster1.join(cluster1.selfAddress());
Cluster cluster2 = Cluster.get(node2);
cluster2.join(cluster1.selfAddress());

Is this the correct way? Suggestions?