From ce732295fa8a6c190d54da4392ce2ed689f4b3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bon=C3=A9r?= Date: Fri, 9 Apr 2010 14:24:33 +0200 Subject: [PATCH] cleaned up remote tests + remvod akkaHome from sbt build file --- .../ClientInitiatedRemoteActorSpec.scala | 55 +++++-------------- .../ServerInitiatedRemoteActorSpec.scala | 24 ++++---- project/build/AkkaProject.scala | 55 +++---------------- 3 files changed, 33 insertions(+), 101 deletions(-) diff --git a/akka-core/src/test/scala/ClientInitiatedRemoteActorSpec.scala b/akka-core/src/test/scala/ClientInitiatedRemoteActorSpec.scala index 71d8c0b0e2..718c8b88c1 100644 --- a/akka-core/src/test/scala/ClientInitiatedRemoteActorSpec.scala +++ b/akka-core/src/test/scala/ClientInitiatedRemoteActorSpec.scala @@ -9,16 +9,17 @@ import org.junit.{Test, Before, After} import se.scalablesolutions.akka.remote.{RemoteServer, RemoteClient} import se.scalablesolutions.akka.dispatch.Dispatchers -object Global { - val oneWay = new CountDownLatch(1) - val remoteReply = new CountDownLatch(1) +case class Send(actor: Actor) + +object RemoteActorSpecActorUnidirectional { + val latch = new CountDownLatch(1) } class RemoteActorSpecActorUnidirectional extends Actor { dispatcher = Dispatchers.newThreadBasedDispatcher(this) def receive = { case "OneWay" => - Global.oneWay.countDown + RemoteActorSpecActorUnidirectional.latch.countDown } } @@ -31,21 +32,6 @@ class RemoteActorSpecActorBidirectional extends Actor { } } -case class Send(actor: Actor) - -class RemoteActorSpecActorAsyncSender extends Actor { - def receive = { - case Send(actor: Actor) => - actor ! "Hello" - case "World" => - Global.remoteReply.countDown - } - - def send(actor: Actor) { - this ! Send(actor) - } -} - class SendOneWayAndReplyReceiverActor extends Actor { def receive = { case "Hello" => @@ -53,6 +39,9 @@ class SendOneWayAndReplyReceiverActor extends Actor { } } +object SendOneWayAndReplySenderActor { + val latch = new CountDownLatch(1) +} class SendOneWayAndReplySenderActor extends Actor { var state: Option[AnyRef] = None var sendTo: Actor = _ @@ -63,7 +52,7 @@ class SendOneWayAndReplySenderActor extends Actor { def receive = { case msg: AnyRef => state = Some(msg) - latch.countDown + SendOneWayAndReplySenderActor.latch.countDown } } @@ -104,7 +93,7 @@ class ClientInitiatedRemoteActorSpec extends JUnitSuite { actor.makeRemote(HOSTNAME, PORT1) actor.start actor ! "OneWay" - assert(Global.oneWay.await(1, TimeUnit.SECONDS)) + assert(RemoteActorSpecActorUnidirectional.latch.await(1, TimeUnit.SECONDS)) actor.stop } @@ -113,14 +102,12 @@ class ClientInitiatedRemoteActorSpec extends JUnitSuite { val actor = new SendOneWayAndReplyReceiverActor actor.makeRemote(HOSTNAME, PORT1) actor.start - val latch = new CountDownLatch(1) val sender = new SendOneWayAndReplySenderActor sender.setReplyToAddress(HOSTNAME, PORT2) sender.sendTo = actor - sender.latch = latch sender.start sender.sendOff - assert(latch.await(1, TimeUnit.SECONDS)) + assert(SendOneWayAndReplySenderActor.latch.await(1, TimeUnit.SECONDS)) assert(sender.state.isDefined === true) assert("World" === sender.state.get.asInstanceOf[String]) actor.stop @@ -128,7 +115,7 @@ class ClientInitiatedRemoteActorSpec extends JUnitSuite { } @Test - def shouldSendReplyAsync = { + def shouldSendBangBangMessageAndReceiveReply = { val actor = new RemoteActorSpecActorBidirectional actor.makeRemote(HOSTNAME, PORT1) actor.start @@ -138,23 +125,7 @@ class ClientInitiatedRemoteActorSpec extends JUnitSuite { } @Test - def shouldSendRemoteReply = { - implicit val timeout = 500000000L - val actor = new RemoteActorSpecActorBidirectional - actor.setReplyToAddress(HOSTNAME, PORT2) - actor.makeRemote(HOSTNAME, PORT2) - actor.start - - val sender = new RemoteActorSpecActorAsyncSender - sender.setReplyToAddress(HOSTNAME, PORT1) - sender.start - sender.send(actor) - assert(Global.remoteReply.await(1, TimeUnit.SECONDS)) - actor.stop - } - - @Test - def shouldSendReceiveException = { + def shouldSendAndReceiveRemoteException = { implicit val timeout = 500000000L val actor = new RemoteActorSpecActorBidirectional actor.makeRemote(HOSTNAME, PORT1) diff --git a/akka-core/src/test/scala/ServerInitiatedRemoteActorSpec.scala b/akka-core/src/test/scala/ServerInitiatedRemoteActorSpec.scala index eec242f7ae..d2d5795bc6 100644 --- a/akka-core/src/test/scala/ServerInitiatedRemoteActorSpec.scala +++ b/akka-core/src/test/scala/ServerInitiatedRemoteActorSpec.scala @@ -11,20 +11,18 @@ object ServerInitiatedRemoteActorSpec { val HOSTNAME = "localhost" val PORT = 9990 var server: RemoteServer = null + + case class Send(actor: Actor) - object Global { - val oneWay = new CountDownLatch(1) - var remoteReply = new CountDownLatch(1) + object RemoteActorSpecActorUnidirectional { + val latch = new CountDownLatch(1) } - class RemoteActorSpecActorUnidirectional extends Actor { - dispatcher = Dispatchers.newThreadBasedDispatcher(this) start def receive = { case "OneWay" => - println("================== ONEWAY") - Global.oneWay.countDown + RemoteActorSpecActorUnidirectional.latch.countDown } } @@ -38,15 +36,16 @@ object ServerInitiatedRemoteActorSpec { } } - case class Send(actor: Actor) - + object RemoteActorSpecActorAsyncSender { + val latch = new CountDownLatch(1) + } class RemoteActorSpecActorAsyncSender extends Actor { start def receive = { case Send(actor: Actor) => actor ! "Hello" case "World" => - Global.remoteReply.countDown + RemoteActorSpecActorAsyncSender.latch.countDown } def send(actor: Actor) { @@ -91,7 +90,7 @@ class ServerInitiatedRemoteActorSpec extends JUnitSuite { 5000L, HOSTNAME, PORT) val result = actor ! "OneWay" - assert(Global.oneWay.await(1, TimeUnit.SECONDS)) + assert(RemoteActorSpecActorUnidirectional.latch.await(1, TimeUnit.SECONDS)) actor.stop } @@ -113,12 +112,11 @@ class ServerInitiatedRemoteActorSpec extends JUnitSuite { "se.scalablesolutions.akka.actor.ServerInitiatedRemoteActorSpec$RemoteActorSpecActorBidirectional", timeout, HOSTNAME, PORT) - val sender = new RemoteActorSpecActorAsyncSender sender.setReplyToAddress(HOSTNAME, PORT) sender.start sender.send(actor) - assert(Global.remoteReply.await(1, TimeUnit.SECONDS)) + assert(RemoteActorSpecActorAsyncSender.latch.await(1, TimeUnit.SECONDS)) actor.stop } diff --git a/project/build/AkkaProject.scala b/project/build/AkkaProject.scala index b5c776fb80..5b2958ddf5 100644 --- a/project/build/AkkaProject.scala +++ b/project/build/AkkaProject.scala @@ -1,42 +1,12 @@ -/*------------------------------------------------------------------------------- - Copyright (C) 2009-2010 Scalable Solutions AB - - ---------------------------------------------------- - -------- sbt buildfile for the Akka project -------- - ---------------------------------------------------- - - Akka implements a unique hybrid of: - * Actors , which gives you: - * Simple and high-level abstractions for concurrency and parallelism. - * Asynchronous, non-blocking and highly performant event-driven programming model. - * Very lightweight event-driven processes (create ~6.5 million actors on 4 G RAM). - * Supervision hierarchies with let-it-crash semantics. For writing highly - fault-tolerant systems that never stop, systems that self-heal. - * Software Transactional Memory (STM). (Distributed transactions coming soon). - * Transactors: combine actors and STM into transactional actors. Allows you to - compose atomic message flows with automatic rollback and retry. - * Remoting: highly performant distributed actors with remote supervision and - error management. - * Cluster membership management. - - Akka also has a set of add-on modules: - * Persistence: A set of pluggable back-end storage modules that work in sync with the STM. - * Cassandra distributed and highly scalable database. - * MongoDB document database. - * Redis data structures database - * Camel: Expose Actors as Camel endpoints. - * REST (JAX-RS): Expose actors as REST services. - * Comet: Expose actors as Comet services. - * Security: Digest and Kerberos based security. - * Spring: Spring integration - * Guice: Guice integration - * Microkernel: Run Akka as a stand-alone kernel. - --------------------------------------------------------------------------------*/ + /*---------------------------------------------------------------------------\ +| Copyright (C) 2009-2010 Scalable Solutions AB | +\---------------------------------------------------------------------------*/ import sbt._ import sbt.CompileOrder._ + import scala.Array + import java.util.jar.Attributes import java.util.jar.Attributes.Name._ import java.io.File @@ -51,18 +21,11 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) { val LIFT_VERSION = "2.0-scala280-SNAPSHOT" val SCALATEST_VERSION = "1.0.1-for-scala-2.8.0.Beta1-with-test-interfaces-0.3-SNAPSHOT" - // ------------------------------------------------------------ - lazy val akkaHome = { - val home = System.getenv("AKKA_HOME") - if (home == null) throw new Error( - "You need to set the $AKKA_HOME environment variable to the root of the Akka distribution") - Path.fromFile(home) - } + // ------------------------------------------------------------ val encodingUtf8 = List("-encoding", "UTF-8") - override def parallelExecution = false - lazy val deployPath = akkaHome / "deploy" - lazy val distPath = akkaHome / "dist" + lazy val deployPath = info.projectPath / "deploy" + lazy val distPath = info.projectPath / "dist" override def javaCompileOptions = JavaCompileOption("-Xlint:unchecked") :: super.javaCompileOptions.toList @@ -72,7 +35,7 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) { // ------------------------------------------------------------ // repositories - val embeddedrepo = "embedded repo" at (akkaHome / "embedded-repo").asURL.toString + val embeddedrepo = "embedded repo" at (info.projectPath / "embedded-repo").asURL.toString val sunjdmk = "sunjdmk" at "http://wp5.e-taxonomy.eu/cdmlib/mavenrepo" val databinder = "DataBinder" at "http://databinder.net/repo" // val configgy = "Configgy" at "http://www.lag.net/repo"