/** * Copyright (C) 2009 Scalable Solutions. */ package se.scalablesolutions.akka.kernel import org.specs.runner.JUnit4 import org.specs.Specification import se.scalablesolutions.akka.annotation.oneway /** * @author Jonas Bonér */ class activeObjectSpecTest extends JUnit4(activeObjectSpec) // for JUnit4 and Maven object activeObjectSpec extends Specification { private var messageLog = "" trait Foo { def foo(msg: String): String @oneway def bar(msg: String) def longRunning def throwsException } class FooImpl extends Foo { val bar: Bar = new BarImpl def foo(msg: String): String = { messageLog += msg "return_foo " } def bar(msg: String) = bar.bar(msg) def longRunning = Thread.sleep(10000) def throwsException = error("expected") } trait Bar { @oneway def bar(msg: String) } class BarImpl extends Bar { def bar(msg: String) = { Thread.sleep(100) messageLog += msg } } // "make sure default supervisor works correctly" in { // val foo = ActiveObject.newInstance[Foo](classOf[Foo], classOf[FooImpl], 1000) // // val result = foo.foo("foo ") // messageLog += result // // foo.bar("bar ") // messageLog += "before_bar " // // Thread.sleep(500) // messageLog must equalIgnoreCase("foo return_foo before_bar bar ") // } } // @Test { val groups=Array("unit") } // def testCreateGenericServerBasedComponentUsingCustomSupervisorConfiguration = { // val proxy = new ActiveObjectProxy(new FooImpl, 1000) // val supervisor = // ActiveObject.supervise( // RestartStrategy(AllForOne, 3, 100), // Component( // proxy, // LifeCycle(Permanent, 100)) // :: Nil) // val foo = ActiveObject.newInstance[Foo](classOf[Foo], proxy) // val result = foo.foo("foo ") // messageLog += result // foo.bar("bar ") // messageLog += "before_bar " // Thread.sleep(500) // assert(messageLog === "foo return_foo before_bar bar ") // supervisor ! Stop // } // @Test { val groups=Array("unit") } // def testCreateTwoGenericServerBasedComponentUsingCustomSupervisorConfiguration = { // val fooProxy = new ActiveObjectProxy(new FooImpl, 1000) // val barProxy = new ActiveObjectProxy(new BarImpl, 1000) // val supervisor = // ActiveObject.supervise( // RestartStrategy(AllForOne, 3, 100), // Component( // fooProxy, // LifeCycle(Permanent, 100)) :: // Component( // barProxy, // LifeCycle(Permanent, 100)) // :: Nil) // val foo = ActiveObject.newInstance[Foo](classOf[Foo], fooProxy) // val bar = ActiveObject.newInstance[Bar](classOf[Bar], barProxy) // val result = foo.foo("foo ") // messageLog += result // bar.bar("bar ") // messageLog += "before_bar " // Thread.sleep(500) // assert(messageLog === "foo return_foo before_bar bar ") // supervisor ! Stop // } // @Test { val groups=Array("unit") } // def testCreateGenericServerBasedComponentUsingDefaultSupervisorAndForcedTimeout = { // val foo = ActiveObject.newInstance[Foo](classOf[Foo], new FooImpl, 1000) // intercept(classOf[ActiveObjectInvocationTimeoutException]) { // foo.longRunning // } // assert(true === true) // } // @Test { val groups=Array("unit") } // def testCreateGenericServerBasedComponentUsingDefaultSupervisorAndForcedException = { // val foo = ActiveObject.newInstance[Foo](classOf[Foo], new FooImpl, 10000) // intercept(classOf[RuntimeException]) { // foo.throwsException // } // assert(true === true) // } // }