2009-02-16 19:50:50 +01:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009 Scalable Solutions.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-03-23 19:17:49 +01:00
|
|
|
package se.scalablesolutions.akka.kernel
|
2009-02-16 19:50:50 +01:00
|
|
|
|
2009-02-19 15:57:59 +01:00
|
|
|
import org.specs.runner.JUnit4
|
|
|
|
|
import org.specs.Specification
|
2009-03-23 19:17:49 +01:00
|
|
|
|
|
|
|
|
import se.scalablesolutions.akka.annotation.oneway
|
2009-02-16 19:50:50 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
|
|
|
|
|
2009-02-19 15:57:59 +01:00
|
|
|
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 ")
|
|
|
|
|
// }
|
2009-02-16 19:50:50 +01:00
|
|
|
|
|
|
|
|
|
2009-02-19 15:57:59 +01:00
|
|
|
}
|
2009-02-16 19:50:50 +01:00
|
|
|
// @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)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2009-02-19 15:57:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|