Permalink
Browse files

cleanup

  • Loading branch information...
1 parent 8c587e5 commit d95db4bc34822aecb89f9e07a42b45e8b39e758f Burt Beckwith committed Jan 8, 2013
Showing with 388 additions and 714 deletions.
  1. +1 −3 .gitignore
  2. +1 −40 AkkaGrailsPlugin.groovy
  3. +0 −3 application.properties
  4. +3 −17 grails-app/conf/BuildConfig.groovy
  5. +4 −23 grails-app/conf/Config.groovy
  6. +9 −42 grails-app/conf/DataSource.groovy
  7. +44 −54 test/integration/grails_akka/LocalAkkaIntegrationTests.groovy
  8. +23 −52 test/integration/grails_akka/RemoteAkkaIntegrationTests.groovy
  9. +45 −64 test/unit/grails_akka/LocalAkkaUnitTests.groovy
  10. +6 −7 test/unit/grails_akka/actor/BaseActor.groovy
  11. +9 −10 test/unit/grails_akka/actor/GreetingActor.groovy
  12. +14 −18 test/unit/grails_akka/command/ActorCommand.groovy
  13. +2 −2 test/unit/grails_akka/command/Command.groovy
  14. +8 −10 test/unit/grails_akka/command/GenericCommand.groovy
  15. +1 −1 test/unit/grails_akka/command/GenericCommandArguments.groovy
  16. +1 −6 test/unit/grails_akka/message/BaseMessage.groovy
  17. +6 −7 test/unit/grails_akka/message/GenericMessage.groovy
  18. +4 −4 test/unit/grails_akka/message/Greeting.groovy
  19. +10 −11 test/unit/grails_akka/message/ImmutableMessage.groovy
  20. +1 −8 test/unit/grails_akka/message/Shutdown.groovy
  21. +1 −8 test/unit/grails_akka/message/Stop.groovy
  22. +8 −11 test/unit/grails_akka/message/Wait.groovy
  23. +2 −16 test/webapp/grails-akka-test/grails-app/conf/BootStrap.groovy
  24. +3 −11 test/webapp/grails-akka-test/grails-app/conf/BuildConfig.groovy
  25. +2 −2 test/webapp/grails-akka-test/grails-app/conf/Config.groovy
  26. +6 −7 test/webapp/grails-akka-test/src/groovy/grails_akka/actor/BaseActor.groovy
  27. +9 −10 test/webapp/grails-akka-test/src/groovy/grails_akka/actor/GreetingActor.groovy
  28. +14 −18 test/webapp/grails-akka-test/src/groovy/grails_akka/command/ActorCommand.groovy
  29. +2 −2 test/webapp/grails-akka-test/src/groovy/grails_akka/command/Command.groovy
  30. +8 −10 test/webapp/grails-akka-test/src/groovy/grails_akka/command/GenericCommand.groovy
  31. +1 −1 test/webapp/grails-akka-test/src/groovy/grails_akka/command/GenericCommandArguments.groovy
  32. +1 −6 test/webapp/grails-akka-test/src/groovy/grails_akka/message/BaseMessage.groovy
  33. +6 −7 test/webapp/grails-akka-test/src/groovy/grails_akka/message/GenericMessage.groovy
  34. +4 −5 test/webapp/grails-akka-test/src/groovy/grails_akka/message/Greeting.groovy
  35. +10 −11 test/webapp/grails-akka-test/src/groovy/grails_akka/message/ImmutableMessage.groovy
  36. +1 −8 test/webapp/grails-akka-test/src/groovy/grails_akka/message/Shutdown.groovy
  37. +1 −8 test/webapp/grails-akka-test/src/groovy/grails_akka/message/Stop.groovy
  38. +8 −11 test/webapp/grails-akka-test/src/groovy/grails_akka/message/Wait.groovy
  39. +40 −64 test/webapp/grails-akka-test/test/integration/grails_akka/LocalAkkaIntegrationTests.groovy
  40. +23 −52 test/webapp/grails-akka-test/test/integration/grails_akka/RemoteAkkaIntegrationTests.groovy
  41. +46 −64 test/webapp/grails-akka-test/test/unit/grails_akka/LocalAkkaUnitTests.groovy
View
4 .gitignore
@@ -17,7 +17,6 @@
/*.db
/*.zip
/plugin.xml
-/*.log
/*DB.*
/*.ser
/.link_to_grails_plugins/
@@ -28,5 +27,4 @@
/target/
/target-eclipse/
/temp/
-/web-app/plugins
-/web-app/WEB-INF/classes
+/web-app
View
41 AkkaGrailsPlugin.groovy
@@ -15,55 +15,16 @@
* limitations under the License.
*/
-// import org.apache.log4j.Logger
-
class AkkaGrailsPlugin {
def version = "0.6.1"
def grailsVersion = "2.0 > *"
- def dependsOn = [:]
- def pluginExcludes = [
- "grails-app/views/error.gsp"
- // , "src/docs/"
- ]
-
def title = "Akka Integration"
def author = "Sandro Martini"
def authorEmail = "sandro.martini@gmail.com"
- def description = '''\
-Akka actors integration from Groovy and Java, in a Servlet 3.x environment.
-'''
+ def description = 'Akka actors integration from Groovy and Java, in a Servlet 3.x environment'
def documentation = "http://smartiniongithub.github.com/grails-akka/"
- // Extra (optional) plugin metadata
def license = "APACHE"
- // def organization = [ name: "MartinS", url: "https://github.com/smartiniOnGitHub/grails-akka/" ]
- // def developers = [ [ name: "other developer", email: "other.developer@my-company.com" ]]
def issueManagement = [ system: "github", url: "https://github.com/smartiniOnGitHub/grails-akka/issues/" ]
def scm = [ url: "https://github.com/smartiniOnGitHub/grails-akka/" ]
-
-
- // private Logger log = Logger.getLogger('grails.plugin.akka.AkkaGrailsPlugin')
-
-
- def doWithWebDescriptor = { xml ->
- }
-
- def doWithSpring = {
- }
-
- def doWithDynamicMethods = { ctx ->
- }
-
- def doWithApplicationContext = { applicationContext ->
- }
-
- def onChange = { event ->
- }
-
- def onConfigChange = { event ->
- }
-
- def onShutdown = { event ->
- }
-
}
View
3 application.properties
@@ -1,4 +1 @@
-#Grails Metadata file
-#Fri Jan 04 20:09:53 CET 2013
app.grails.version=2.0.4
-app.name=akka
View
20 grails-app/conf/BuildConfig.groovy
@@ -15,37 +15,24 @@
* limitations under the License.
*/
-// grails.servlet.version = "3.0" // verify if makes sense to enable this even here ...
-grails.project.class.dir = "target/classes"
+grails.project.work.dir = "target"
// grails.project.docs.output.dir = 'docs/manual'
-grails.project.test.class.dir = "target/test-classes"
-grails.project.test.reports.dir = "target/test-reports"
grails.project.source.level = 1.6
grails.project.target.level = 1.6
-// grails.project.war.file = "target/${appName}-${appVersion}.war"
-// grails.project.work.dir = 'target'
-
def akkaVersion = '2.0.5'
grails.project.dependency.resolution = {
- // inherit Grails' default dependencies
- inherits("global") {
- // excludes 'ehcache' // uncomment to disable ehcache
- }
- log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
+ inherits 'global'
+ log 'warn'
repositories {
grailsCentral()
- //mavenCentral()
- //mavenLocal()
mavenRepo "http://repo.typesafe.com/typesafe/releases/"
}
dependencies {
- // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
-
def excludes = {
// disable excludes, or compile errors will happen ...
// // exclude, to avoid version conflict
@@ -64,5 +51,4 @@ grails.project.dependency.resolution = {
export = false
}
}
-
}
View
27 grails-app/conf/Config.groovy
@@ -15,32 +15,13 @@
* limitations under the License.
*/
-// configuration for plugin testing - will not be included in the plugin zip
-
log4j = {
- // Example of changing the log pattern for the default console
- // appender:
- //
- //appenders {
- // console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
- //}
-
- error 'org.codehaus.groovy.grails.web.servlet', // controllers
- 'org.codehaus.groovy.grails.web.pages', // GSP
- 'org.codehaus.groovy.grails.web.sitemesh', // layouts
- 'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
- 'org.codehaus.groovy.grails.web.mapping', // URL mapping
- 'org.codehaus.groovy.grails.commons', // core / classloading
- 'org.codehaus.groovy.grails.plugins', // plugins
- 'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
- 'org.springframework',
- 'org.hibernate',
- 'net.sf.ehcache.hibernate'
-
- warn 'org.mortbay.log'
+ error 'org.codehaus.groovy.grails',
+ 'org.springframework',
+ 'org.hibernate',
+ 'net.sf.ehcache.hibernate'
}
-
grails.doc.authors = 'Sandro Martini'
grails.doc.license = 'Apache License 2.0'
grails.doc.title = 'Akka Integration'
View
51 grails-app/conf/DataSource.groovy
@@ -16,49 +16,16 @@
*/
dataSource {
- pooled = true
- driverClassName = "org.h2.Driver"
- username = "sa"
- password = ""
+ pooled = true
+ driverClassName = 'org.h2.Driver'
+ username = 'sa'
+ password = ''
+ dbCreate = 'update'
+ url = 'jdbc:h2:mem:testDb'
}
hibernate {
- cache.use_second_level_cache = true
- cache.use_query_cache = false
- cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
-}
-
-// environment specific settings
-environments
-{
- development {
- dataSource {
- dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
- url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
- }
- }
- test {
- dataSource {
- dbCreate = "update"
- url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
- }
- }
- production {
- dataSource {
- dbCreate = "update"
- url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
- pooled = true
- properties {
- maxActive = -1
- minEvictableIdleTimeMillis=1800000
- timeBetweenEvictionRunsMillis=1800000
- numTestsPerEvictionRun=3
- testOnBorrow=true
- testWhileIdle=true
- testOnReturn=true
- validationQuery="SELECT 1"
- }
- }
- }
-
+ cache.use_second_level_cache = false
+ cache.use_query_cache = false
+ cache.provider_class = 'org.hibernate.cache.EhCacheProvider'
}
View
98 test/integration/grails_akka/LocalAkkaIntegrationTests.groovy
@@ -17,23 +17,21 @@
package grails_akka
import static org.junit.Assert.*
-
-import grails.test.mixin.*
-import grails.test.mixin.support.*
-import org.junit.*
-import org.junit.rules.*
-
-import akka.actor.*
-import akka.routing.*
-import akka.util.Duration
-import akka.testkit.*
-
-// import java.util.concurrent.TimeUnit
-
-import grails_akka.actor.*
-import grails_akka.command.*
-import grails_akka.message.*
-
+import grails_akka.actor.GreetingActor
+import grails_akka.command.ActorCommand
+import grails_akka.message.GenericMessage
+import grails_akka.message.Greeting
+import grails_akka.message.Stop
+import grails_akka.message.Wait
+
+import org.junit.After
+import org.junit.Before
+import org.junit.Test
+
+import akka.actor.ActorRef
+import akka.actor.ActorSystem
+import akka.actor.Props
+import akka.testkit.TestProbe
/**
* LocalAkkaIntegrationTests
@@ -43,43 +41,42 @@ import grails_akka.message.*
class LocalAkkaIntegrationTests
{
// global actor system for this test class, to reuse it in all test methods here
- ActorSystem system = null
- ActorRef actor = null
+ ActorSystem system
+ ActorRef actor
// the supported mode to mock an actor is with something like this:
- TestProbe probe = null
- ActorRef mock = null
-
+ TestProbe probe
+ ActorRef mock
@Before
- public void setUp()
+ void setUp()
{
// creates the local actor system
// system = ActorSystem.apply()
system = ActorSystem.create("LocalActorSystem")
println("Created Local Actor System instance: $system")
// get a reference to the greetingActor
- // actor = TestActorRef.apply(new Props(GreetingActor.class), system) // this is the supported way
- actor = system.actorOf(new Props(GreetingActor.class), "greeting_actor") // this is my way (not test-specific) ...
+ // actor = TestActorRef.apply(new Props(GreetingActor), system) // this is the supported way
+ actor = system.actorOf(new Props(GreetingActor), "greeting_actor") // this is my way (not test-specific) ...
println("Get Actor Reference to GreetingActor: $actor")
// the supported mode to mock an actor is with something like this:
// mock = TestActorRef.apply(new AbstractFunction0() {
// @Override
- // public Pi.Worker apply() {
- // return new Pi.Worker();
+ // Pi.Worker apply() {
+ // return new Pi.Worker()
// }
- // }, system);
+ // }, system)
// and in any test method then use something like this:
// probe = TestProbe.apply(system)
// mock = probe.ref()
// mock.tell("Hello", probe.ref())
}
@After
- public void tearDown()
+ void tearDown()
{
// shutdown the local actor system
// if (actor != null) {
@@ -91,31 +88,25 @@ class LocalAkkaIntegrationTests
// }
}
- @Test(expected = InstantiationException.class)
+ @Test(expected = InstantiationException)
void testClassAvailable_UntypedActor()
{
log.info "testClassAvailable_UntypedActor()"
- def className = null;
- def classInstance = null;
-
- className = "akka.actor.UntypedActor" // abstract, so not instantiable ...
- classInstance = Class.forName(className).newInstance();
+ def className = "akka.actor.UntypedActor" // abstract, so not instantiable ...
+ def classInstance = Class.forName(className).newInstance()
println("$className instance is: $classInstance")
// assertNotNull classInstance
// here I expect an InstantiationException thrown
}
- @Test(expected = InstantiationException.class)
+ @Test(expected = InstantiationException)
void testClassAvailable_ActorSystem()
{
log.info "testClassAvailable_ActorSystem()"
- def className = null;
- def classInstance = null;
-
- className = "akka.actor.ActorSystem" // abstract, so not instantiable ...
- classInstance = Class.forName(className).newInstance();
+ def className = "akka.actor.ActorSystem" // abstract, so not instantiable ...
+ def classInstance = Class.forName(className).newInstance()
println("$className instance is: $classInstance")
// assertNotNull classInstance
// here I expect an InstantiationException thrown
@@ -132,20 +123,20 @@ class LocalAkkaIntegrationTests
assertNotNull system
// get a reference to our greeting actor
- // ActorRef actor = system.actorOf(new Props(GreetingActor.class), "greeting_actor") // commented, to reuse the actor reference global in this test class
+ // ActorRef actor = system.actorOf(new Props(GreetingActor), "greeting_actor") // commented, to reuse the actor reference global in this test class
println("Actor Reference instance is: $actor")
assertNotNull actor
// send to the greeting actor a null message
- actor.tell(null);
+ actor.tell(null)
assertNotNull actor // dummy
// send to the greeting actor a Greeting message
- actor.tell(new Greeting("Test Greeting"));
+ actor.tell(new Greeting("Test Greeting"))
assertNotNull actor // dummy
// send to the greeting actor an unknown message
- actor.tell(new String("Test String"));
+ actor.tell(new String("Test String"))
assertNotNull actor // dummy
}
@@ -160,12 +151,12 @@ class LocalAkkaIntegrationTests
assertNotNull system
// get a reference to our greeting actor
- // ActorRef actor = system.actorOf(new Props(GreetingActor.class), "greeting_actor") // commented, to reuse the actor reference global in this test class
+ // ActorRef actor = system.actorOf(new Props(GreetingActor), "greeting_actor") // commented, to reuse the actor reference global in this test class
println("Actor Reference instance is: $actor")
assertNotNull actor
// send to the greeting actor a sample generic message
- actor.tell(new GenericMessage<String>("simple generic message with a String"));
+ actor.tell(new GenericMessage<String>("simple generic message with a String"))
assertNotNull actor // dummy
}
@@ -181,9 +172,9 @@ class LocalAkkaIntegrationTests
// send to the greeting actor a Wait message
long sleepTime = 2000 // msec
- long startSleep = System.currentTimeMillis();
- actor.tell(new Wait(sleepTime));
- long stopSleep = System.currentTimeMillis();
+ long startSleep = System.currentTimeMillis()
+ actor.tell(new Wait(sleepTime))
+ long stopSleep = System.currentTimeMillis()
long delta = stopSleep - startSleep
// TODO: enable later and make it working ...
// assertTrue delta >= sleepTime
@@ -201,15 +192,15 @@ class LocalAkkaIntegrationTests
assertNotNull actor
// send to the greeting actor a stop message
- actor.tell(new Stop());
+ actor.tell(new Stop())
assertNotNull actor // dummy
// // send to the greeting actor a shutdown message
- // actor.tell(new Shutdown());
+ // actor.tell(new Shutdown())
// assertNotNull actor // dummy
// send to the greeting actor an unknown message
- actor.tell(new String("Test String"));
+ actor.tell(new String("Test String"))
assertNotNull actor // dummy
// ok, but note that this actor (after the Shutdown message) will not get this message ...
}
@@ -236,5 +227,4 @@ class LocalAkkaIntegrationTests
cmd2.execute()
assertNotNull cmd2 // dummy
}
-
}
View
75 test/integration/grails_akka/RemoteAkkaIntegrationTests.groovy
@@ -17,23 +17,15 @@
package grails_akka
import static org.junit.Assert.*
+import grails_akka.actor.GreetingActor
-import grails.test.mixin.*
-import grails.test.mixin.support.*
-import org.junit.*
-import org.junit.rules.*
-
-import akka.actor.*
-import akka.routing.*
-import akka.util.Duration
-import akka.testkit.*
-
-// import java.util.concurrent.TimeUnit
-
-import grails_akka.actor.*
-import grails_akka.command.*
-import grails_akka.message.*
+import org.junit.Before
+import org.junit.Test
+import akka.actor.ActorRef
+import akka.actor.ActorSystem
+import akka.actor.Props
+import akka.testkit.TestProbe
/**
* RemoteAkkaIntegrationTests
@@ -43,82 +35,61 @@ import grails_akka.message.*
class RemoteAkkaIntegrationTests
{
// global actor system for this test class, to reuse it in all test methods here
- ActorSystem system = null
- ActorRef actor = null
+ ActorSystem system
+ ActorRef actor
// the supported mode to mock an actor is with something like this:
- TestProbe probe = null
- ActorRef mock = null
-
+ TestProbe probe
+ ActorRef mock
@Before
- public void setUp()
+ void setUp()
{
// creates the local actor system
// system = ActorSystem.apply()
system = ActorSystem.create("LocalActorSystem")
println("Created Local Actor System instance: $system")
// get a reference to the greetingActor
- // actor = TestActorRef.apply(new Props(GreetingActor.class), system) // this is the supported way
- actor = system.actorOf(new Props(GreetingActor.class), "greeting_actor") // this is my way (not test-specific) ...
+ // actor = TestActorRef.apply(new Props(GreetingActor), system) // this is the supported way
+ actor = system.actorOf(new Props(GreetingActor), "greeting_actor") // this is my way (not test-specific) ...
println("Get Actor Reference to GreetingActor: $actor")
// the supported mode to mock an actor is with something like this:
// mock = TestActorRef.apply(new AbstractFunction0() {
// @Override
- // public Pi.Worker apply() {
- // return new Pi.Worker();
+ // Pi.Worker apply() {
+ // return new Pi.Worker()
// }
- // }, system);
+ // }, system)
// and in any test method then use something like this:
// probe = TestProbe.apply(system)
// mock = probe.ref()
// mock.tell("Hello", probe.ref())
}
- @After
- public void tearDown()
- {
- // shutdown the local actor system
- // if (actor != null) {
- // actor.stop()
- // }
- // if (system != null) {
- // println("Shutting down Local Actor System instance: $system")
- // system.shutdown()
- // }
- }
-
- @Test(expected = InstantiationException.class)
+ @Test(expected = InstantiationException)
void testClassAvailable_UntypedActor()
{
log.info "testClassAvailable_UntypedActor()"
- def className = null;
- def classInstance = null;
-
- className = "akka.actor.UntypedActor" // abstract, so not instantiable ...
- classInstance = Class.forName(className).newInstance();
+ def className = "akka.actor.UntypedActor" // abstract, so not instantiable ...
+ def classInstance = Class.forName(className).newInstance()
println("$className instance is: $classInstance")
// assertNotNull classInstance
// here I expect an InstantiationException thrown
}
- @Test(expected = InstantiationException.class)
+ @Test(expected = InstantiationException)
void testClassAvailable_ActorSystem()
{
log.info "testClassAvailable_ActorSystem()"
- def className = null;
- def classInstance = null;
-
- className = "akka.actor.ActorSystem" // abstract, so not instantiable ...
- classInstance = Class.forName(className).newInstance();
+ def className = "akka.actor.ActorSystem" // abstract, so not instantiable ...
+ def classInstance = Class.forName(className).newInstance()
println("$className instance is: $classInstance")
// assertNotNull classInstance
// here I expect an InstantiationException thrown
}
-
}
View
109 test/unit/grails_akka/LocalAkkaUnitTests.groovy
@@ -16,24 +16,22 @@
*/
package grails_akka
-import static org.junit.Assert.*
-
-import grails.test.mixin.*
-import grails.test.mixin.support.*
-import org.junit.*
-// import org.junit.rules.*
-
-import akka.actor.*
-import akka.routing.*
-import akka.util.Duration
-import akka.testkit.*
-
-// import java.util.concurrent.TimeUnit
-
-import grails_akka.actor.*
-import grails_akka.command.*
-import grails_akka.message.*
-
+import grails.test.mixin.TestMixin
+import grails.test.mixin.support.GrailsUnitTestMixin
+import grails_akka.actor.GreetingActor
+import grails_akka.command.ActorCommand
+import grails_akka.message.GenericMessage
+import grails_akka.message.Greeting
+import grails_akka.message.Stop
+import grails_akka.message.Wait
+
+import org.junit.Before
+import org.junit.Test
+
+import akka.actor.ActorRef
+import akka.actor.ActorSystem
+import akka.actor.Props
+import akka.testkit.TestProbe
/**
* LocalAkkaUnitTests
@@ -46,74 +44,58 @@ import grails_akka.message.*
class LocalAkkaUnitTests
{
// global actor system for this test class, to reuse it in all test methods here
- ActorSystem system = null
- ActorRef actor = null
+ ActorSystem system
+ ActorRef actor
// the supported mode to mock an actor is with something like this:
- TestProbe probe = null
- ActorRef mock = null
-
+ TestProbe probe
+ ActorRef mock
@Before
- public void setUp()
+ void setUp()
{
// creates the local actor system
// system = ActorSystem.apply()
system = ActorSystem.create("LocalActorSystem")
println("Created Local Actor System instance: $system")
// get a reference to the greetingActor
- // actor = TestActorRef.apply(new Props(GreetingActor.class), system) // this is the supported way
- actor = system.actorOf(new Props(GreetingActor.class), "greeting_actor") // this is my way (not test-specific) ...
+ // actor = TestActorRef.apply(new Props(GreetingActor), system) // this is the supported way
+ actor = system.actorOf(new Props(GreetingActor), "greeting_actor") // this is my way (not test-specific) ...
println("Get Actor Reference to GreetingActor: $actor")
// the supported mode to mock an actor is with something like this:
// mock = TestActorRef.apply(new AbstractFunction0() {
// @Override
- // public Pi.Worker apply() {
- // return new Pi.Worker();
+ // Pi.Worker apply() {
+ // return new Pi.Worker()
// }
- // }, system);
+ // }, system)
// and in any test method then use something like this:
// probe = TestProbe.apply(system)
// mock = probe.ref()
// mock.tell("Hello", probe.ref())
}
- @After
- public void tearDown()
- {
- // shutdown the local actor system
- // if (actor != null) {
- // actor.stop()
- // }
- // if (system != null) {
- // println("Shutting down Local Actor System instance: $system")
- // system.shutdown()
- // }
- }
-
@Test
- // @Test(expected = InstantiationException.class)
+ // @Test(expected = InstantiationException)
void testClassAvailable()
{
log.info "testClassAvailable()"
- def className = null;
- def classInstance = null;
-
- className = "akka.actor.ActorSystem" // abstract, so not instantiable ...
- shouldFail(java.lang.InstantiationException) { // more flexible insted of ExpectedException
- classInstance = Class.forName(className).newInstance();
+ def classInstance
+ def className = "akka.actor.ActorSystem" // abstract, so not instantiable ...
+ shouldFail(InstantiationException) { // more flexible insted of ExpectedException
+ classInstance = Class.forName(className).newInstance()
}
println("$className instance is: $classInstance")
// assertNotNull classInstance
// here I expect an InstantiationException thrown
className = "akka.actor.UntypedActor" // abstract, so not instantiable ...
- shouldFail(java.lang.InstantiationException) { // more flexible insted of ExpectedException
- classInstance = Class.forName(className).newInstance();
+ shouldFail(InstantiationException) { // more flexible insted of ExpectedException
+ classInstance = Class.forName(className).newInstance()
}
println("$className instance is: $classInstance")
// assertNotNull classInstance
@@ -131,20 +113,20 @@ class LocalAkkaUnitTests
assertNotNull system
// get a reference to our greeting actor
- // ActorRef actor = system.actorOf(new Props(GreetingActor.class), "greeting_actor") // commented, to reuse the actor reference global in this test class
+ // ActorRef actor = system.actorOf(new Props(GreetingActor), "greeting_actor") // commented, to reuse the actor reference global in this test class
println("Actor Reference instance is: $actor")
assertNotNull actor
// send to the greeting actor a null message
- actor.tell(null);
+ actor.tell(null)
assertNotNull actor // dummy
// send to the greeting actor a Greeting message
- actor.tell(new Greeting("Test Greeting"));
+ actor.tell(new Greeting("Test Greeting"))
assertNotNull actor // dummy
// send to the greeting actor an unknown message
- actor.tell(new String("Test String"));
+ actor.tell(new String("Test String"))
assertNotNull actor // dummy
}
@@ -159,12 +141,12 @@ class LocalAkkaUnitTests
assertNotNull system
// get a reference to our greeting actor
- // ActorRef actor = system.actorOf(new Props(GreetingActor.class), "greeting_actor") // commented, to reuse the actor reference global in this test class
+ // ActorRef actor = system.actorOf(new Props(GreetingActor), "greeting_actor") // commented, to reuse the actor reference global in this test class
println("Actor Reference instance is: $actor")
assertNotNull actor
// send to the greeting actor a sample generic message
- actor.tell(new GenericMessage<String>("simple generic message with a String"));
+ actor.tell(new GenericMessage<String>("simple generic message with a String"))
assertNotNull actor // dummy
}
@@ -180,9 +162,9 @@ class LocalAkkaUnitTests
// send to the greeting actor a Wait message
long sleepTime = 2000 // msec
- long startSleep = System.currentTimeMillis();
- actor.tell(new Wait(sleepTime));
- long stopSleep = System.currentTimeMillis();
+ long startSleep = System.currentTimeMillis()
+ actor.tell(new Wait(sleepTime))
+ long stopSleep = System.currentTimeMillis()
long delta = stopSleep - startSleep
// TODO: enable later and make it working ...
// assertTrue delta >= sleepTime
@@ -200,15 +182,15 @@ class LocalAkkaUnitTests
assertNotNull actor
// send to the greeting actor a stop message
- actor.tell(new Stop());
+ actor.tell(new Stop())
assertNotNull actor // dummy
// // send to the greeting actor a shutdown message
- // actor.tell(new Shutdown());
+ // actor.tell(new Shutdown())
// assertNotNull actor // dummy
// send to the greeting actor an unknown message
- actor.tell(new String("Test String"));
+ actor.tell(new String("Test String"))
assertNotNull actor // dummy
// ok, but note that this actor (after the Shutdown message) will not get this message ...
}
@@ -235,5 +217,4 @@ class LocalAkkaUnitTests
cmd2.execute()
assertNotNull cmd2 // dummy
}
-
}
View
13 test/unit/grails_akka/actor/BaseActor.groovy
@@ -17,21 +17,20 @@
package grails_akka.actor
import akka.actor.UntypedActor
-import akka.event.*
-
+import akka.event.Logging
+import akka.event.LoggingAdapter
/**
* Abstract base actor class, to use (when desired) as base class for all other messages here.
*/
-public abstract class BaseActor extends UntypedActor
+abstract class BaseActor extends UntypedActor
{
- LoggingAdapter log = Logging.getLogger(getContext().system(), this);
+ LoggingAdapter log = Logging.getLogger(getContext().system(), this)
@Override
- public void onReceive(Object message) throws Exception
+ void onReceive(Object message) throws Exception
{
// do nothing here ... but override in subclasses
- // String messageClassName = message?.getClass()?.getName();
+ // String messageClassName = message?.getClass()?.getName()
}
-
}
View
19 test/unit/grails_akka/actor/GreetingActor.groovy
@@ -16,27 +16,27 @@
*/
package grails_akka.actor
+import grails_akka.message.Greeting
+import grails_akka.message.Shutdown
+import grails_akka.message.Stop
+import grails_akka.message.Wait
import akka.actor.UntypedActor
-import akka.event.*
-
-import grails_akka.actor.*
-import grails_akka.command.*
-import grails_akka.message.*
-
+import akka.event.Logging
+import akka.event.LoggingAdapter
/**
* Greeting actor, as a sample.
* <br/>
* This code is derived from Akka Samples.
*/
-public class GreetingActor extends UntypedActor
+class GreetingActor extends UntypedActor
{
LoggingAdapter log = Logging.getLogger(getContext().system(), this)
@Override
- public void onReceive(Object message) throws Exception
+ void onReceive(Object message) throws Exception
{
- String messageClassName = message?.getClass()?.getName();
+ String messageClassName = message?.getClass()?.getName()
if (message == null)
{
@@ -84,5 +84,4 @@ public class GreetingActor extends UntypedActor
unhandled(message)
}
}
-
}
View
32 test/unit/grails_akka/command/ActorCommand.groovy
@@ -16,22 +16,23 @@
*/
package grails_akka.command
-import akka.actor.*
+import groovy.transform.EqualsAndHashCode
+import groovy.transform.ToString
-import groovy.transform.*
+import org.springframework.util.Assert
+import akka.actor.ActorRef
/**
* Command that send the given message to the given actor.
*/
@EqualsAndHashCode
-// @Immutable
@ToString
-public class ActorCommand implements Command
+class ActorCommand implements Command
{
// read only properties, with public getter generated by Groovy, but not setter
- final ActorRef actor;
- final Serializable message;
+ final ActorRef actor
+ final Serializable message
/**
* Constructor
@@ -42,21 +43,16 @@ public class ActorCommand implements Command
* @param message
* The Serializable message to send, must be not null.
*/
- public ActorCommand(ActorRef actor, Serializable message)
+ ActorCommand(ActorRef actor, Serializable message)
{
- if (actor == null)
- throw new IllegalArgumentException("actor must be not null.");
- if (message == null)
- throw new IllegalArgumentException("message must be not null.");
-
- this.actor = actor;
- this.message = message;
+ Assert.notNull(actor, "actor must be not null.")
+ Assert.notNull(message, "message must be not null.")
+ this.actor = actor
+ this.message = message
}
- @Override
- public void execute()
+ void execute()
{
- actor.tell(message);
+ actor.tell(message)
}
-
}
View
4 test/unit/grails_akka/command/Command.groovy
@@ -19,7 +19,7 @@ package grails_akka.command
/**
* The Command pattern.
*/
-public interface Command
+interface Command
{
- public void execute();
+ void execute()
}
View
18 test/unit/grails_akka/command/GenericCommand.groovy
@@ -16,28 +16,26 @@
*/
package grails_akka.command
+import org.springframework.util.Assert
+
/**
* GenericCommand, with command details in the given map.
* <br/>
* Subclass and override the execute method for similar concrete implementation of command.
*/
-public class GenericCommand implements Command
+class GenericCommand implements Command
{
// read only property, with public getter generated by Groovy, but not setter
- final Map arguments;
+ final Map arguments
- public GenericCommand(Map arguments)
+ GenericCommand(Map arguments)
{
- if (arguments == null)
- throw new IllegalArgumentException("arguments Map must be not null.");
-
- this.arguments = arguments;
+ Assert.notNull(arguments, "arguments Map must be not null.")
+ this.arguments = arguments
}
- @Override
- public void execute()
+ void execute()
{
// do nothing here ... but override in subclasses
}
-
}
View
2 test/unit/grails_akka/command/GenericCommandArguments.groovy
@@ -19,7 +19,7 @@ package grails_akka.command
/**
* Enum with standard keys to use as keys (but as Strings) in the GenericCommand arguments map.
*/
-public enum GenericCommandArguments
+enum GenericCommandArguments
{
NAME
}
View
7 test/unit/grails_akka/message/BaseMessage.groovy
@@ -23,11 +23,6 @@ package grails_akka.message
* <br/>
* This code is derived from Akka Samples.
*/
-public abstract class BaseMessage implements Serializable
+abstract class BaseMessage implements Serializable
{
-
- public BaseMessage()
- {
- }
-
}
View
13 test/unit/grails_akka/message/GenericMessage.groovy
@@ -16,8 +16,8 @@
*/
package grails_akka.message
-import groovy.transform.*
-
+import groovy.transform.EqualsAndHashCode
+import groovy.transform.ToString
/**
* GenericMessage.
@@ -26,14 +26,13 @@ import groovy.transform.*
*/
@EqualsAndHashCode
@ToString
-public class GenericMessage<T> extends BaseMessage implements Serializable
+class GenericMessage<T> extends BaseMessage
{
// read only property, with public getter generated by Groovy, but not setter
- final T message;
+ final T message
- public GenericMessage(T message)
+ GenericMessage(T message)
{
- this.message = message;
+ this.message = message
}
-
}
View
8 test/unit/grails_akka/message/Greeting.groovy
@@ -23,13 +23,13 @@ package grails_akka.message
* <br/>
* This code is derived from Akka Samples.
*/
-public class Greeting implements Serializable
+class Greeting implements Serializable
{
- public final String who;
+ final String who
- public Greeting(String who)
+ Greeting(String who)
{
- this.who = who;
+ this.who = who
}
}
View
21 test/unit/grails_akka/message/ImmutableMessage.groovy
@@ -23,23 +23,22 @@ package grails_akka.message
* <br/>
* This code is derived from Akka Samples.
*/
-public class ImmutableMessage
+class ImmutableMessage
{
- private final int sequenceNumber;
- private final List<String> values;
+ private final int sequenceNumber
+ private final List<String> values
- public ImmutableMessage(int sequenceNumber, List<String> values)
+ ImmutableMessage(int sequenceNumber, List<String> values)
{
- this.sequenceNumber = sequenceNumber;
- this.values = Collections.unmodifiableList(new ArrayList<String>(values));
+ this.sequenceNumber = sequenceNumber
+ this.values = Collections.unmodifiableList(new ArrayList<String>(values))
}
- public int getSequenceNumber() {
- return sequenceNumber;
+ int getSequenceNumber() {
+ return sequenceNumber
}
- public List<String> getValues() {
- return values;
+ List<String> getValues() {
+ return values
}
-
}
View
9 test/unit/grails_akka/message/Shutdown.groovy
@@ -16,18 +16,11 @@
*/
package grails_akka.message
-import groovy.transform.*
-
-
/**
* Shutdown message, as a sample.
* <br/>
* Used a kind of message to send to actors.
*/
-// @EqualsAndHashCode
-@Immutable
-// @ToString
-public class Shutdown extends BaseMessage implements Serializable
+class Shutdown extends BaseMessage
{
-
}
View
9 test/unit/grails_akka/message/Stop.groovy
@@ -16,18 +16,11 @@
*/
package grails_akka.message
-import groovy.transform.*
-
-
/**
* Stop message, as a sample.
* <br/>
* Used a kind of message to send to actors.
*/
-// @EqualsAndHashCode
-@Immutable
-// @ToString
-public class Stop extends BaseMessage implements Serializable
+class Stop extends BaseMessage
{
-
}
View
19 test/unit/grails_akka/message/Wait.groovy
@@ -16,28 +16,25 @@
*/
package grails_akka.message
-import groovy.transform.*
+import groovy.transform.EqualsAndHashCode
+import groovy.transform.ToString
+import org.springframework.util.Assert
/**
* Waiting message, as a sample.
* <br/>
* Used a kind of message to send to actors.
*/
@EqualsAndHashCode
-// @Immutable
@ToString
-public class Wait implements Serializable
+class Wait implements Serializable
{
- final long msec;
+ final long msec
- public Wait(long msec)
+ Wait(long msec)
{
- // this.msec = (msec < 0) ? 0l : msec;
- if (msec < 0)
- throw new IllegalArgumentException("Waiting time must be 0 or positive.");
-
- this.msec = msec;
+ Assert.isTrue(msec >= 0, "Waiting time must be 0 or positive.")
+ this.msec = msec
}
-
}
View
18 test/webapp/grails-akka-test/grails-app/conf/BootStrap.groovy
@@ -15,33 +15,19 @@
* limitations under the License.
*/
-import javax.servlet.ServletContext
-
-import org.codehaus.groovy.grails.commons.GrailsApplication
import grails.util.Environment
+import javax.servlet.ServletContext
class BootStrap
{
def grailsApplication
def init = { ServletContext sc ->
-
println "Bootstrap running in Environment " + Environment.current
- def now = new Date()
-
- // final Thread thread = Thread.currentThread();
- // final ClassLoader tccl = thread.getContextClassLoader();
-
println """
Remember that to test the plugin (inline here),
this webapp (other than the usual run-app) could be run even with with run-war ...
- """
-
- }
-
- def destroy = {
+"""
}
-
-
}
View
14 test/webapp/grails-akka-test/grails-app/conf/BuildConfig.groovy
@@ -15,13 +15,10 @@
* limitations under the License.
*/
-grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
-grails.project.class.dir = "target/classes"
-grails.project.test.class.dir = "target/test-classes"
-grails.project.test.reports.dir = "target/test-reports"
+grails.servlet.version = "3.0"
+grails.project.work.dir = "target"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
-//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.plugin.location."akka" = "../../../"
@@ -39,11 +36,8 @@ grails.project.dependency.resolution = {
grailsPlugins()
grailsHome()
grailsCentral()
+ mavenLocal()
mavenCentral()
-
- // uncomment these to enable remote dependency resolution from public Maven repositories
- //mavenCentral()
- //mavenLocal()
}
dependencies {
@@ -67,7 +61,5 @@ grails.project.dependency.resolution = {
//runtime ":yui-minify-resources:0.1.4"
build ":tomcat:$grailsVersion"
-
}
-
}
View
4 test/webapp/grails-akka-test/grails-app/conf/Config.groovy
@@ -53,7 +53,7 @@ grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*']
// The default codec used to encode data with ${}
-grails.views.default.codec = "none" // none, html, base64
+grails.views.default.codec = "html" // none, html, base64
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8"
// enable Sitemesh preprocessing of GSP pages
@@ -74,7 +74,7 @@ grails.web.disable.multipart=false
grails.exceptionresolver.params.exclude = ['password']
// enable query caching by default
-grails.hibernate.cache.queries = true
+grails.hibernate.cache.queries = false
// set per-environment serverURL stem for creating absolute links
environments {
View
13 test/webapp/grails-akka-test/src/groovy/grails_akka/actor/BaseActor.groovy
@@ -17,21 +17,20 @@
package grails_akka.actor
import akka.actor.UntypedActor
-import akka.event.*
-
+import akka.event.Logging
+import akka.event.LoggingAdapter
/**
* Abstract base actor class, to use (when desired) as base class for all other messages here.
*/
-public abstract class BaseActor extends UntypedActor
+abstract class BaseActor extends UntypedActor
{
- LoggingAdapter log = Logging.getLogger(getContext().system(), this);
+ LoggingAdapter log = Logging.getLogger(getContext().system(), this)
@Override
- public void onReceive(Object message) throws Exception
+ void onReceive(Object message) throws Exception
{
// do nothing here ... but override in subclasses
- // String messageClassName = message?.getClass()?.getName();
+ // String messageClassName = message?.getClass()?.getName()
}
-
}
View
19 test/webapp/grails-akka-test/src/groovy/grails_akka/actor/GreetingActor.groovy
@@ -16,27 +16,27 @@
*/
package grails_akka.actor
+import grails_akka.message.Greeting
+import grails_akka.message.Shutdown
+import grails_akka.message.Stop
+import grails_akka.message.Wait
import akka.actor.UntypedActor
-import akka.event.*
-
-import grails_akka.actor.*
-import grails_akka.command.*
-import grails_akka.message.*
-
+import akka.event.Logging
+import akka.event.LoggingAdapter
/**
* Greeting actor, as a sample.
* <br/>
* This code is derived from Akka Samples.
*/
-public class GreetingActor extends UntypedActor
+class GreetingActor extends UntypedActor
{
LoggingAdapter log = Logging.getLogger(getContext().system(), this)
@Override
- public void onReceive(Object message) throws Exception
+ void onReceive(Object message) throws Exception
{
- String messageClassName = message?.getClass()?.getName();
+ String messageClassName = message?.getClass()?.getName()
if (message == null)
{
@@ -84,5 +84,4 @@ public class GreetingActor extends UntypedActor
unhandled(message)
}
}
-
}
View
32 test/webapp/grails-akka-test/src/groovy/grails_akka/command/ActorCommand.groovy
@@ -16,22 +16,23 @@
*/
package grails_akka.command
-import akka.actor.*
+import groovy.transform.EqualsAndHashCode
+import groovy.transform.ToString
-import groovy.transform.*
+import org.springframework.util.Assert
+import akka.actor.ActorRef
/**
* Command that send the given message to the given actor.
*/
@EqualsAndHashCode
-// @Immutable
@ToString
-public class ActorCommand implements Command
+class ActorCommand implements Command
{
// read only properties, with public getter generated by Groovy, but not setter
- final ActorRef actor;
- final Serializable message;
+ final ActorRef actor
+ final Serializable message
/**
* Constructor
@@ -42,21 +43,16 @@ public class ActorCommand implements Command
* @param message
* The Serializable message to send, must be not null.
*/
- public ActorCommand(ActorRef actor, Serializable message)
+ ActorCommand(ActorRef actor, Serializable message)
{
- if (actor == null)
- throw new IllegalArgumentException("actor must be not null.");
- if (message == null)
- throw new IllegalArgumentException("message must be not null.");
-
- this.actor = actor;
- this.message = message;
+ Assert.notNull(actor, "actor must be not null.")
+ Assert.notNull(message, "message must be not null.")
+ this.actor = actor
+ this.message = message
}
- @Override
- public void execute()
+ void execute()
{
- actor.tell(message);
+ actor.tell(message)
}
-
}
View
4 test/webapp/grails-akka-test/src/groovy/grails_akka/command/Command.groovy
@@ -19,7 +19,7 @@ package grails_akka.command
/**
* The Command pattern.
*/
-public interface Command
+interface Command
{
- public void execute();
+ void execute()
}
View
18 test/webapp/grails-akka-test/src/groovy/grails_akka/command/GenericCommand.groovy
@@ -16,28 +16,26 @@
*/
package grails_akka.command
+import org.springframework.util.Assert
+
/**
* GenericCommand, with command details in the given map.
* <br/>
* Subclass and override the execute method for similar concrete implementation of command.
*/
-public class GenericCommand implements Command
+class GenericCommand implements Command
{
// read only property, with public getter generated by Groovy, but not setter
- final Map arguments;
+ final Map arguments
- public GenericCommand(Map arguments)
+ GenericCommand(Map arguments)
{
- if (arguments == null)
- throw new IllegalArgumentException("arguments Map must be not null.");
-
- this.arguments = arguments;
+ Assert.notNull(arguments, "arguments Map must be not null.")
+ this.arguments = arguments
}
- @Override
- public void execute()
+ void execute()
{
// do nothing here ... but override in subclasses
}
-
}
View
2 test/webapp/grails-akka-test/src/groovy/grails_akka/command/GenericCommandArguments.groovy
@@ -19,7 +19,7 @@ package grails_akka.command
/**
* Enum with standard keys to use as keys (but as Strings) in the GenericCommand arguments map.
*/
-public enum GenericCommandArguments
+enum GenericCommandArguments
{
NAME
}
View
7 test/webapp/grails-akka-test/src/groovy/grails_akka/message/BaseMessage.groovy
@@ -23,11 +23,6 @@ package grails_akka.message
* <br/>
* This code is derived from Akka Samples.
*/
-public abstract class BaseMessage implements Serializable
+abstract class BaseMessage implements Serializable
{
-
- public BaseMessage()
- {
- }
-
}
View
13 test/webapp/grails-akka-test/src/groovy/grails_akka/message/GenericMessage.groovy
@@ -16,8 +16,8 @@
*/
package grails_akka.message
-import groovy.transform.*
-
+import groovy.transform.EqualsAndHashCode
+import groovy.transform.ToString
/**
* GenericMessage.
@@ -26,14 +26,13 @@ import groovy.transform.*
*/
@EqualsAndHashCode
@ToString
-public class GenericMessage<T> extends BaseMessage implements Serializable
+class GenericMessage<T> extends BaseMessage
{
// read only property, with public getter generated by Groovy, but not setter
- final T message;
+ final T message
- public GenericMessage(T message)
+ GenericMessage(T message)
{
- this.message = message;
+ this.message = message
}
-
}
View
9 test/webapp/grails-akka-test/src/groovy/grails_akka/message/Greeting.groovy
@@ -23,13 +23,12 @@ package grails_akka.message
* <br/>
* This code is derived from Akka Samples.
*/
-public class Greeting implements Serializable
+class Greeting implements Serializable
{
- public final String who;
+ final String who
- public Greeting(String who)
+ Greeting(String who)
{
- this.who = who;
+ this.who = who
}
-
}
View
21 test/webapp/grails-akka-test/src/groovy/grails_akka/message/ImmutableMessage.groovy
@@ -23,23 +23,22 @@ package grails_akka.message
* <br/>
* This code is derived from Akka Samples.
*/
-public class ImmutableMessage
+class ImmutableMessage
{
- private final int sequenceNumber;
- private final List<String> values;
+ private final int sequenceNumber
+ private final List<String> values
- public ImmutableMessage(int sequenceNumber, List<String> values)
+ ImmutableMessage(int sequenceNumber, List<String> values)
{
- this.sequenceNumber = sequenceNumber;
- this.values = Collections.unmodifiableList(new ArrayList<String>(values));
+ this.sequenceNumber = sequenceNumber
+ this.values = Collections.unmodifiableList(new ArrayList<String>(values))
}
- public int getSequenceNumber() {
- return sequenceNumber;
+ int getSequenceNumber() {
+ return sequenceNumber
}
- public List<String> getValues() {
- return values;
+ List<String> getValues() {
+ return values
}
-
}
View
9 test/webapp/grails-akka-test/src/groovy/grails_akka/message/Shutdown.groovy
@@ -16,18 +16,11 @@
*/
package grails_akka.message
-import groovy.transform.*
-
-
/**
* Shutdown message, as a sample.
* <br/>
* Used a kind of message to send to actors.
*/
-// @EqualsAndHashCode
-@Immutable
-// @ToString
-public class Shutdown extends BaseMessage implements Serializable
+class Shutdown extends BaseMessage
{
-
}
View
9 test/webapp/grails-akka-test/src/groovy/grails_akka/message/Stop.groovy
@@ -16,18 +16,11 @@
*/
package grails_akka.message
-import groovy.transform.*
-
-
/**
* Stop message, as a sample.
* <br/>
* Used a kind of message to send to actors.
*/
-// @EqualsAndHashCode
-@Immutable
-// @ToString
-public class Stop extends BaseMessage implements Serializable
+class Stop extends BaseMessage
{
-
}
View
19 test/webapp/grails-akka-test/src/groovy/grails_akka/message/Wait.groovy
@@ -16,28 +16,25 @@
*/
package grails_akka.message
-import groovy.transform.*
+import groovy.transform.EqualsAndHashCode
+import groovy.transform.ToString
+import org.springframework.util.Assert
/**
* Waiting message, as a sample.
* <br/>
* Used a kind of message to send to actors.
*/
@EqualsAndHashCode
-// @Immutable
@ToString
-public class Wait implements Serializable
+class Wait implements Serializable
{
- final long msec;
+ final long msec
- public Wait(long msec)
+ Wait(long msec)
{
- // this.msec = (msec < 0) ? 0l : msec;
- if (msec < 0)
- throw new IllegalArgumentException("Waiting time must be 0 or positive.");
-
- this.msec = msec;
+ Assert.isTrue(msec >= 0, "Waiting time must be 0 or positive.")
+ this.msec = msec
}
-
}
View
104 test/webapp/grails-akka-test/test/integration/grails_akka/LocalAkkaIntegrationTests.groovy
@@ -17,23 +17,20 @@
package grails_akka
import static org.junit.Assert.*
+import grails_akka.actor.GreetingActor
+import grails_akka.command.ActorCommand
+import grails_akka.message.GenericMessage
+import grails_akka.message.Greeting
+import grails_akka.message.Stop
+import grails_akka.message.Wait
-import grails.test.mixin.*
-import grails.test.mixin.support.*
-import org.junit.*
-import org.junit.rules.*
-
-import akka.actor.*
-import akka.routing.*
-import akka.util.Duration
-import akka.testkit.*
-
-// import java.util.concurrent.TimeUnit
-
-import grails_akka.actor.*
-import grails_akka.command.*
-import grails_akka.message.*
+import org.junit.Before
+import org.junit.Test
+import akka.actor.ActorRef
+import akka.actor.ActorSystem
+import akka.actor.Props
+import akka.testkit.TestProbe
/**
* LocalAkkaIntegrationTests
@@ -43,79 +40,59 @@ import grails_akka.message.*
class LocalAkkaIntegrationTests
{
// global actor system for this test class, to reuse it in all test methods here
- ActorSystem system = null
- ActorRef actor = null
+ ActorSystem system
+ ActorRef actor
// the supported mode to mock an actor is with something like this:
- TestProbe probe = null
- ActorRef mock = null
-
+ TestProbe probe
+ ActorRef mock
@Before
- public void setUp()
+ void setUp()
{
// creates the local actor system
// system = ActorSystem.apply()
system = ActorSystem.create("LocalActorSystem")
println("Created Local Actor System instance: $system")
// get a reference to the greetingActor
- // actor = TestActorRef.apply(new Props(GreetingActor.class), system) // this is the supported way
- actor = system.actorOf(new Props(GreetingActor.class), "greeting_actor") // this is my way (not test-specific) ...
+ // actor = TestActorRef.apply(new Props(GreetingActor), system) // this is the supported way
+ actor = system.actorOf(new Props(GreetingActor), "greeting_actor") // this is my way (not test-specific) ...
println("Get Actor Reference to GreetingActor: $actor")
// the supported mode to mock an actor is with something like this:
// mock = TestActorRef.apply(new AbstractFunction0() {
// @Override
- // public Pi.Worker apply() {
- // return new Pi.Worker();
+ // Pi.Worker apply() {
+ // return new Pi.Worker()
// }
- // }, system);
+ // }, system)
// and in any test method then use something like this:
// probe = TestProbe.apply(system)
// mock = probe.ref()
// mock.tell("Hello", probe.ref())
}
- @After
- public void tearDown()
- {
- // shutdown the local actor system
- // if (actor != null) {
- // actor.stop()
- // }
- // if (system != null) {
- // println("Shutting down Local Actor System instance: $system")
- // system.shutdown()
- // }
- }
-
- @Test(expected = InstantiationException.class)
+ @Test(expected = InstantiationException)
void testClassAvailable_UntypedActor()
{
log.info "testClassAvailable_UntypedActor()"
- def className = null;
- def classInstance = null;
-
- className = "akka.actor.UntypedActor" // abstract, so not instantiable ...
- classInstance = Class.forName(className).newInstance();
+ def className = "akka.actor.UntypedActor" // abstract, so not instantiable ...
+ def classInstance = Class.forName(className).newInstance()
println("$className instance is: $classInstance")
// assertNotNull classInstance
// here I expect an InstantiationException thrown
}
- @Test(expected = InstantiationException.class)
+ @Test(expected = InstantiationException)
void testClassAvailable_ActorSystem()
{
log.info "testClassAvailable_ActorSystem()"
- def className = null;
- def classInstance = null;
-
- className = "akka.actor.ActorSystem" // abstract, so not instantiable ...
- classInstance = Class.forName(className).newInstance();
+ def className = "akka.actor.ActorSystem" // abstract, so not instantiable ...
+ def classInstance = Class.forName(className).newInstance()
println("$className instance is: $classInstance")
// assertNotNull classInstance
// here I expect an InstantiationException thrown
@@ -132,20 +109,20 @@ class LocalAkkaIntegrationTests
assertNotNull system
// get a reference to our greeting actor
- // ActorRef actor = system.actorOf(new Props(GreetingActor.class), "greeting_actor") // commented, to reuse the actor reference global in this test class
+ // ActorRef actor = system.actorOf(new Props(GreetingActor), "greeting_actor") // commented, to reuse the actor reference global in this test class
println("Actor Reference instance is: $actor")
assertNotNull actor
// send to the greeting actor a null message
- actor.tell(null);
+ actor.tell(null)
assertNotNull actor // dummy
// send to the greeting actor a Greeting message
- actor.tell(new Greeting("Test Greeting"));
+ actor.tell(new Greeting("Test Greeting"))
assertNotNull actor // dummy
// send to the greeting actor an unknown message
- actor.tell(new String("Test String"));
+ actor.tell(new String("Test String"))
assertNotNull actor // dummy
}
@@ -160,12 +137,12 @@ class LocalAkkaIntegrationTests
assertNotNull system
// get a reference to our greeting actor
- // ActorRef actor = system.actorOf(new Props(GreetingActor.class), "greeting_actor") // commented, to reuse the actor reference global in this test class
+ // ActorRef actor = system.actorOf(new Props(GreetingActor), "greeting_actor") // commented, to reuse the actor reference global in this test class
println("Actor Reference instance is: $actor")
assertNotNull actor
// send to the greeting actor a sample generic message
- actor.tell(new GenericMessage<String>("simple generic message with a String"));
+ actor.tell(new GenericMessage<String>("simple generic message with a String"))
assertNotNull actor // dummy
}
@@ -181,9 +158,9 @@ class LocalAkkaIntegrationTests
// send to the greeting actor a Wait message
long sleepTime = 2000 // msec
- long startSleep = System.currentTimeMillis();
- actor.tell(new Wait(sleepTime));
- long stopSleep = System.currentTimeMillis();
+ long startSleep = System.currentTimeMillis()
+ actor.tell(new Wait(sleepTime))
+ long stopSleep = System.currentTimeMillis()
long delta = stopSleep - startSleep
// TODO: enable later and make it working ...
// assertTrue delta >= sleepTime
@@ -201,15 +178,15 @@ class LocalAkkaIntegrationTests
assertNotNull actor
// send to the greeting actor a stop message
- actor.tell(new Stop());
+ actor.tell(new Stop())
assertNotNull actor // dummy
// // send to the greeting actor a shutdown message
- // actor.tell(new Shutdown());
+ // actor.tell(new Shutdown())
// assertNotNull actor // dummy
// send to the greeting actor an unknown message
- actor.tell(new String("Test String"));
+ actor.tell(new String("Test String"))
assertNotNull actor // dummy
// ok, but note that this actor (after the Shutdown message) will not get this message ...
}
@@ -236,5 +213,4 @@ class LocalAkkaIntegrationTests
cmd2.execute()
assertNotNull cmd2 // dummy
}
-
}
View
75 test/webapp/grails-akka-test/test/integration/grails_akka/RemoteAkkaIntegrationTests.groovy
@@ -17,23 +17,15 @@
package grails_akka
import static org.junit.Assert.*
+import grails_akka.actor.GreetingActor
-import grails.test.mixin.*
-import grails.test.mixin.support.*
-import org.junit.*
-import org.junit.rules.*
-
-import akka.actor.*
-import akka.routing.*
-import akka.util.Duration
-import akka.testkit.*
-
-// import java.util.concurrent.TimeUnit
-
-import grails_akka.actor.*
-import grails_akka.command.*
-import grails_akka.message.*
+import org.junit.Before
+import org.junit.Test
+import akka.actor.ActorRef
+import akka.actor.ActorSystem
+import akka.actor.Props
+import akka.testkit.TestProbe
/**
* RemoteAkkaIntegrationTests
@@ -43,82 +35,61 @@ import grails_akka.message.*
class RemoteAkkaIntegrationTests
{
// global actor system for this test class, to reuse it in all test methods here
- ActorSystem system = null
- ActorRef actor = null
+ ActorSystem system
+ ActorRef actor
// the supported mode to mock an actor is with something like this:
- TestProbe probe = null
- ActorRef mock = null
-
+ TestProbe probe
+ ActorRef mock
@Before
- public void setUp()
+ void setUp()
{
// creates the local actor system
// system = ActorSystem.apply()
system = ActorSystem.create("LocalActorSystem")
println("Created Local Actor System instance: $system")
// get a reference to the greetingActor
- // actor = TestActorRef.apply(new Props(GreetingActor.class), system) // this is the supported way
- actor = system.actorOf(new Props(GreetingActor.class), "greeting_actor") // this is my way (not test-specific) ...
+ // actor = TestActorRef.apply(new Props(GreetingActor), system) // this is the supported way
+ actor = system.actorOf(new Props(GreetingActor), "greeting_actor") // this is my way (not test-specific) ...
println("Get Actor Reference to GreetingActor: $actor")
// the supported mode to mock an actor is with something like this:
// mock = TestActorRef.apply(new AbstractFunction0() {
// @Override
- // public Pi.Worker apply() {
- // return new Pi.Worker();
+ // Pi.Worker apply() {
+ // return new Pi.Worker()
// }
- // }, system);
+ // }, system)
// and in any test method then use something like this:
// probe = TestProbe.apply(system)
// mock = probe.ref()
// mock.tell("Hello", probe.ref())
}
- @After
- public void tearDown()
- {
- // shutdown the local actor system
- // if (actor != null) {
- // actor.stop()
- // }
- // if (system != null) {
- // println("Shutting down Local Actor System instance: $system")
- // system.shutdown()
- // }
- }
-
- @Test(expected = InstantiationException.class)
+ @Test(expected = InstantiationException)
void testClassAvailable_UntypedActor()
{
log.info "testClassAvailable_UntypedActor()"
- def className = null;
- def classInstance = null;
-
- className = "akka.actor.UntypedActor" // abstract, so not instantiable ...
- classInstance = Class.forName(className).newInstance();
+ def className = "akka.actor.UntypedActor" // abstract, so not instantiable ...
+ def classInstance = Class.forName(className).newInstance()
println("$className instance is: $classInstance")
// assertNotNull classInstance
// here I expect an InstantiationException thrown
}
- @Test(expected = InstantiationException.class)
+ @Test(expected = InstantiationException)
void testClassAvailable_ActorSystem()
{
log.info "testClassAvailable_ActorSystem()"
- def className = null;
- def classInstance = null;
-
- className = "akka.actor.ActorSystem" // abstract, so not instantiable ...
- classInstance = Class.forName(className).newInstance();
+ def className = "akka.actor.ActorSystem" // abstract, so not instantiable ...
+ def classInstance = Class.forName(className).newInstance()
println("$className instance is: $classInstance")
// assertNotNull classInstance
// here I expect an InstantiationException thrown
}
-
}
View
110 test/webapp/grails-akka-test/test/unit/grails_akka/LocalAkkaUnitTests.groovy
@@ -3,7 +3,7 @@
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except in
+ * Version 2.0 (the "License") you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@@ -17,23 +17,22 @@
package grails_akka
import static org.junit.Assert.*
-
-import grails.test.mixin.*
-import grails.test.mixin.support.*
-import org.junit.*
-// import org.junit.rules.*
-
-import akka.actor.*
-import akka.routing.*
-import ak