From 6c0503ea5113369ecb0eefaaa50b9072722afa04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bon=C3=A9r?= Date: Wed, 14 Jul 2010 15:46:05 +0200 Subject: [PATCH] Changed Akka config file syntax to JSON-style instead of XML style Plus added missing test classes for ActiveObjectContextSpec --- .../akka/actor/SimpleJavaPojoCaller.java | 20 ++++++ .../test/scala/ActiveObjectContextSpec.scala | 45 +++++++++++++ akka-core/src/test/scala/TransactorSpec.scala | 14 ++-- config/akka-reference.conf | 67 ++++++++++--------- 4 files changed, 108 insertions(+), 38 deletions(-) create mode 100644 akka-core/src/test/java/se/scalablesolutions/akka/actor/SimpleJavaPojoCaller.java create mode 100644 akka-core/src/test/scala/ActiveObjectContextSpec.scala diff --git a/akka-core/src/test/java/se/scalablesolutions/akka/actor/SimpleJavaPojoCaller.java b/akka-core/src/test/java/se/scalablesolutions/akka/actor/SimpleJavaPojoCaller.java new file mode 100644 index 0000000000..0fb6aff9c5 --- /dev/null +++ b/akka-core/src/test/java/se/scalablesolutions/akka/actor/SimpleJavaPojoCaller.java @@ -0,0 +1,20 @@ +package se.scalablesolutions.akka.actor; + +import se.scalablesolutions.akka.dispatch.CompletableFuture; + +public class SimpleJavaPojoCaller { + + SimpleJavaPojo pojo; + + public void setPojo(SimpleJavaPojo pojo) { + this.pojo = pojo; + } + + public Object getSenderFromSimpleJavaPojo() { + return pojo.getSender(); + } + + public CompletableFuture getSenderFutureFromSimpleJavaPojo() { + return pojo.getSenderFuture(); + } +} diff --git a/akka-core/src/test/scala/ActiveObjectContextSpec.scala b/akka-core/src/test/scala/ActiveObjectContextSpec.scala new file mode 100644 index 0000000000..5a54f0a505 --- /dev/null +++ b/akka-core/src/test/scala/ActiveObjectContextSpec.scala @@ -0,0 +1,45 @@ +/** + * Copyright (C) 2009-2010 Scalable Solutions AB + */ + +package se.scalablesolutions.akka.actor + +import org.scalatest.Spec +import org.scalatest.Assertions +import org.scalatest.matchers.ShouldMatchers +import org.scalatest.BeforeAndAfterAll +import org.scalatest.junit.JUnitRunner +import org.junit.runner.RunWith + +import se.scalablesolutions.akka.dispatch.DefaultCompletableFuture; + +@RunWith(classOf[JUnitRunner]) +class ActiveObjectContextSpec extends + Spec with + ShouldMatchers with + BeforeAndAfterAll { + + describe("ActiveObjectContext") { + it("context.sender should return the sender Active Object reference") { + val pojo = ActiveObject.newInstance(classOf[SimpleJavaPojo]) + val pojoCaller = ActiveObject.newInstance(classOf[SimpleJavaPojoCaller]) + pojoCaller.setPojo(pojo) + try { + pojoCaller.getSenderFromSimpleJavaPojo should equal (pojoCaller) + } catch { + case e => fail("no sender available") + } + } + + it("context.senderFuture should return the senderFuture Active Object reference") { + val pojo = ActiveObject.newInstance(classOf[SimpleJavaPojo]) + val pojoCaller = ActiveObject.newInstance(classOf[SimpleJavaPojoCaller]) + pojoCaller.setPojo(pojo) + try { + pojoCaller.getSenderFutureFromSimpleJavaPojo.getClass.getName should equal (classOf[DefaultCompletableFuture[_]].getName) + } catch { + case e => fail("no sender future available", e) + } + } + } +} diff --git a/akka-core/src/test/scala/TransactorSpec.scala b/akka-core/src/test/scala/TransactorSpec.scala index 069bbba630..dcce33837a 100644 --- a/akka-core/src/test/scala/TransactorSpec.scala +++ b/akka-core/src/test/scala/TransactorSpec.scala @@ -44,7 +44,7 @@ class StatefulTransactor(expectedInvocationCount: Int) extends Transactor { self.reply(notifier) case GetMapState(key) => self.reply(mapState.get(key).get) -// notifier.countDown + notifier.countDown case GetVectorSize => self.reply(vectorState.length.asInstanceOf[AnyRef]) notifier.countDown @@ -80,7 +80,7 @@ class StatefulTransactor(expectedInvocationCount: Int) extends Transactor { case SetMapStateOneWay(key, msg) => println("------- SetMapStateOneWay") mapState.put(key, msg) -// notifier.countDown + notifier.countDown case SetVectorStateOneWay(msg) => vectorState.add(msg) notifier.countDown @@ -97,7 +97,7 @@ class StatefulTransactor(expectedInvocationCount: Int) extends Transactor { mapState.put(key, msg) vectorState.add(msg) refState.swap(msg) -// notifier.countDown + notifier.countDown failer ! "Failure" } } @@ -133,7 +133,7 @@ class TransactorSpec extends JUnitSuite { stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired assert("new state" === (stateful !! GetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess")).get) } -*/ + @Test def shouldOneWayMapShouldRollbackStateForStatefulServerInCaseOfFailure = { val stateful = actorOf(new StatefulTransactor(4)) @@ -145,11 +145,11 @@ class TransactorSpec extends JUnitSuite { stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method println("------- sending FailureOneWay") Thread.sleep(100) -// val notifier = (stateful !! GetNotifier).as[CountDownLatch] -// assert(notifier.get.await(5, TimeUnit.SECONDS)) + val notifier = (stateful !! GetNotifier).as[CountDownLatch] + assert(notifier.get.await(5, TimeUnit.SECONDS)) assert("init" === (stateful !! GetMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")).get) // check that state is == init state } -/* + @Test def shouldMapShouldRollbackStateForStatefulServerInCaseOfFailure = { val stateful = actorOf[StatefulTransactor] diff --git a/config/akka-reference.conf b/config/akka-reference.conf index 97889729fd..326dd64636 100644 --- a/config/akka-reference.conf +++ b/config/akka-reference.conf @@ -5,16 +5,21 @@ # This file has all the default settings, so all these could be removed with no visible effect. # Modify as needed. - +log { filename = "./logs/akka.log" roll = "daily" # Options: never, hourly, daily, sunday/monday/... - level = "trace" # Options: fatal, critical, error, warning, info, debug, trace + level = "debug" # Options: fatal, critical, error, warning, info, debug, trace console = on # syslog_host = "" # syslog_server_name = "" - - + akka { + node = "se.scalablesolutions.akka" + level = "info" + } +} + +akka { version = "0.10" # FQN (Fully Qualified Name) to the class doing initial active object/actor @@ -24,26 +29,26 @@ "sample.rest.scala.Boot", "sample.security.Boot"] - + actor { timeout = 5000 # default timeout for future based invocations serialize-messages = off # does a deep clone of (non-primitive) messages to ensure immutability throughput = 5 # default throughput for ExecutorBasedEventDrivenDispatcher - + } - + stm { fair = on # should global transactions be fair or non-fair (non fair yield better performance) jta-aware = off # 'on' means that if there JTA Transaction Manager available then the STM will # begin (or join), commit or rollback the JTA transaction. Default is 'off'. - + } - + jta { provider = "from-jndi" # Options: "from-jndi" (means that Akka will try to detect a TransactionManager in the JNDI) # "atomikos" (means that Akka will use the Atomikos based JTA impl in 'akka-jta', # e.g. you need the akka-jta JARs on classpath). timeout = 60000 - + } - + rest { service = on hostname = "localhost" port = 9998 @@ -52,53 +57,53 @@ authenticator = "sample.security.BasicAuthenticationService" # The authentication service to use. Need to be overridden (uses sample now) #IF you are using a KerberosAuthenticationActor - # + # kerberos { # servicePrincipal = "HTTP/localhost@EXAMPLE.COM" # keyTabLocation = "URL to keytab" # kerberosDebug = "true" # realm = "EXAMPLE.COM" - # - + # } + } - + remote { compression-scheme = "zlib" # Options: "zlib" (lzf to come), leave out for no compression zlib-compression-level = 6 # Options: 0-9 (1 being fastest and 9 being the most compressed), default is 6 - + cluster { service = on name = "default" # The name of the cluster serializer = "se.scalablesolutions.akka.serialization.Serializer$Java$" # FQN of the serializer class - + } - + server { service = on hostname = "localhost" port = 9999 connection-timeout = 1000 # in millis (1 sec default) - + } - + client { reconnect-delay = 5000 # in millis (5 sec default) read-timeout = 10000 # in millis (10 sec default) - - + } + } - - + storage { + cassandra { hostname = "127.0.0.1" # IP address or hostname of one of the Cassandra cluster's seeds port = 9160 consistency-level = "QUORUM" # Options: ZERO, ONE, QUORUM, DCQUORUM, DCQUORUMSYNC, ALL, ANY - + } - + mongodb { hostname = "127.0.0.1" # IP address or hostname of the MongoDB DB instance port = 27017 dbname = "mydb" - + } - + redis { hostname = "127.0.0.1" # IP address or hostname of the Redis instance port = 6379 - - - + } + } +}