diff --git a/akka-camel/src/test/java/se/scalablesolutions/akka/camel/Pojo.java b/akka-camel/src/test/java/se/scalablesolutions/akka/camel/Pojo.java new file mode 100644 index 0000000000..d1848c49ee --- /dev/null +++ b/akka-camel/src/test/java/se/scalablesolutions/akka/camel/Pojo.java @@ -0,0 +1,14 @@ +package se.scalablesolutions.akka.camel; + +import se.scalablesolutions.akka.actor.annotation.consume; + +/** + * @author Martin Krasser + */ +public class Pojo { + + public String foo(String s) { + return String.format("foo: %s", s); + } + +} \ No newline at end of file diff --git a/akka-camel/src/test/java/se/scalablesolutions/akka/camel/PojoRemote.java b/akka-camel/src/test/java/se/scalablesolutions/akka/camel/PojoRemote.java new file mode 100644 index 0000000000..57b0999b8f --- /dev/null +++ b/akka-camel/src/test/java/se/scalablesolutions/akka/camel/PojoRemote.java @@ -0,0 +1,15 @@ +package se.scalablesolutions.akka.camel; + +import se.scalablesolutions.akka.actor.annotation.consume; + +/** + * @author Martin Krasser + */ +public class PojoRemote { + + @consume("direct:remote-active-object") + public String foo(String s) { + return String.format("remote active object: %s", s); + } + +} diff --git a/akka-camel/src/test/scala/RemoteConsumerTest.scala b/akka-camel/src/test/scala/RemoteConsumerTest.scala new file mode 100644 index 0000000000..e1a7842e0d --- /dev/null +++ b/akka-camel/src/test/scala/RemoteConsumerTest.scala @@ -0,0 +1,89 @@ +package se.scalablesolutions.akka.camel + +import java.util.concurrent.{CountDownLatch, TimeUnit} + +import org.scalatest.{GivenWhenThen, BeforeAndAfterAll, FeatureSpec} + +import se.scalablesolutions.akka.actor.Actor._ +import se.scalablesolutions.akka.actor.{ActiveObject, ActorRegistry, RemoteActor} +import se.scalablesolutions.akka.remote.{RemoteClient, RemoteServer} + +/** + * @author Martin Krasser + */ +class RemoteConsumerTest extends FeatureSpec with BeforeAndAfterAll with GivenWhenThen { + import RemoteConsumerTest._ + + var service: CamelService = _ + var server: RemoteServer = _ + + override protected def beforeAll = { + ActorRegistry.shutdownAll + + service = CamelService.newInstance + service.load + + server = new RemoteServer() + server.start(host, port) + + Thread.sleep(1000) + } + + override protected def afterAll = { + server.shutdown + service.unload + + RemoteClient.shutdownAll + ActorRegistry.shutdownAll + + Thread.sleep(1000) + } + + feature("Client-initiated remote consumer actor") { + scenario("access published remote consumer actor") { + given("a client-initiated remote consumer actor") + val consumer = actorOf[RemoteConsumer].start + + when("remote consumer publication is triggered") + val latch = service.consumerPublisher.!![CountDownLatch](SetExpectedMessageCount(1)).get + consumer !! "init" + assert(latch.await(5000, TimeUnit.MILLISECONDS)) + + then("the published actor is accessible via its endpoint URI") + val response = CamelContextManager.template.requestBody("direct:remote-actor", "test") + assert(response === "remote actor: test") + } + } + + /* TODO: enable once issues with remote active objects are resolved + feature("Client-initiated remote consumer active object") { + scenario("access published remote consumer method") { + given("a client-initiated remote consumer active object") + val consumer = ActiveObject.newRemoteInstance(classOf[PojoRemote], host, port) + + when("remote consumer publication is triggered") + val latch = service.consumerPublisher.!![CountDownLatch](SetExpectedMessageCount(1)).get + consumer.foo("init") + assert(latch.await(5000, TimeUnit.MILLISECONDS)) + + then("the published method is accessible via its endpoint URI") + val response = CamelContextManager.template.requestBody("direct:remote-active-object", "test") + assert(response === "remote active object: test") + } + } + */ +} + +object RemoteConsumerTest { + val host = "localhost" + val port = 7774 + + class RemoteConsumer extends RemoteActor(host, port) with Consumer { + def endpointUri = "direct:remote-actor" + + protected def receive = { + case "init" => self.reply("done") + case m: Message => self.reply("remote actor: %s" format m.body) + } + } +} \ No newline at end of file