2010-06-28 22:22:41 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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.config.Config
|
|
|
|
|
import se.scalablesolutions.akka.config._
|
|
|
|
|
import se.scalablesolutions.akka.config.ActiveObjectConfigurator
|
|
|
|
|
import se.scalablesolutions.akka.config.JavaConfig._
|
|
|
|
|
import se.scalablesolutions.akka.actor._
|
2010-06-29 15:19:09 +02:00
|
|
|
/*
|
2010-06-28 22:22:41 +02:00
|
|
|
@RunWith(classOf[JUnitRunner])
|
2010-06-29 15:19:09 +02:00
|
|
|
class TransactionalActiveObjectSpec extends
|
2010-06-30 16:26:15 +02:00
|
|
|
Spec with
|
|
|
|
|
ShouldMatchers with
|
|
|
|
|
BeforeAndAfterAll {
|
2010-06-28 22:22:41 +02:00
|
|
|
|
|
|
|
|
private val conf = new ActiveObjectConfigurator
|
|
|
|
|
private var messageLog = ""
|
2010-06-30 16:26:15 +02:00
|
|
|
|
2010-06-28 22:22:41 +02:00
|
|
|
override def beforeAll {
|
|
|
|
|
Config.config
|
|
|
|
|
conf.configure(
|
|
|
|
|
new RestartStrategy(new AllForOne, 3, 5000, List(classOf[Exception]).toArray),
|
|
|
|
|
List(
|
2010-06-29 15:19:09 +02:00
|
|
|
new Component(classOf[TransactionalActiveObject],
|
2010-06-28 22:22:41 +02:00
|
|
|
new LifeCycle(new Permanent),
|
|
|
|
|
//new RestartCallbacks("preRestart", "postRestart")),
|
|
|
|
|
10000),
|
2010-06-29 15:19:09 +02:00
|
|
|
new Component(classOf[ActiveObjectFailer],
|
2010-06-28 22:22:41 +02:00
|
|
|
new LifeCycle(new Permanent),
|
|
|
|
|
10000)).toArray
|
|
|
|
|
).supervise
|
|
|
|
|
}
|
2010-06-30 16:26:15 +02:00
|
|
|
|
2010-06-28 22:22:41 +02:00
|
|
|
override def afterAll {
|
|
|
|
|
conf.stop
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe("Transactional in-memory Active Object ") {
|
|
|
|
|
|
|
|
|
|
it("map should not rollback state for stateful server in case of success") {
|
2010-06-29 15:19:09 +02:00
|
|
|
val stateful = conf.getInstance(classOf[TransactionalActiveObject])
|
2010-06-28 22:22:41 +02:00
|
|
|
stateful.init
|
|
|
|
|
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init")
|
|
|
|
|
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state")
|
|
|
|
|
stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess") should equal("new state")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it("map should rollback state for stateful server in case of failure") {
|
2010-06-29 15:19:09 +02:00
|
|
|
val stateful = conf.getInstance(classOf[TransactionalActiveObject])
|
2010-06-28 22:22:41 +02:00
|
|
|
stateful.init
|
|
|
|
|
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init")
|
2010-06-29 15:19:09 +02:00
|
|
|
val failer = conf.getInstance(classOf[ActiveObjectFailer])
|
2010-06-28 22:22:41 +02:00
|
|
|
try {
|
2010-06-30 16:26:15 +02:00
|
|
|
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer)
|
2010-06-28 22:22:41 +02:00
|
|
|
fail("should have thrown an exception")
|
|
|
|
|
} catch { case e => {} }
|
|
|
|
|
stateful.getMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure") should equal("init")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it("vector should rollback state for stateful server in case of failure") {
|
2010-06-29 15:19:09 +02:00
|
|
|
val stateful = conf.getInstance(classOf[TransactionalActiveObject])
|
2010-06-28 22:22:41 +02:00
|
|
|
stateful.init
|
|
|
|
|
stateful.setVectorState("init") // set init state
|
2010-06-29 15:19:09 +02:00
|
|
|
val failer = conf.getInstance(classOf[ActiveObjectFailer])
|
2010-06-28 22:22:41 +02:00
|
|
|
try {
|
2010-06-30 16:26:15 +02:00
|
|
|
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer)
|
2010-06-28 22:22:41 +02:00
|
|
|
fail("should have thrown an exception")
|
|
|
|
|
} catch { case e => {} }
|
|
|
|
|
stateful.getVectorState should equal("init")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it("vector should not rollback state for stateful server in case of success") {
|
2010-06-29 15:19:09 +02:00
|
|
|
val stateful = conf.getInstance(classOf[TransactionalActiveObject])
|
2010-06-28 22:22:41 +02:00
|
|
|
stateful.init
|
|
|
|
|
stateful.setVectorState("init") // set init state
|
|
|
|
|
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state")
|
|
|
|
|
stateful.getVectorState should equal("new state")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it("ref should rollback state for stateful server in case of failure") {
|
2010-06-29 15:19:09 +02:00
|
|
|
val stateful = conf.getInstance(classOf[TransactionalActiveObject])
|
2010-06-28 22:22:41 +02:00
|
|
|
stateful.init
|
|
|
|
|
stateful.setRefState("init") // set init state
|
2010-06-29 15:19:09 +02:00
|
|
|
val failer = conf.getInstance(classOf[ActiveObjectFailer])
|
2010-06-28 22:22:41 +02:00
|
|
|
try {
|
2010-06-30 16:26:15 +02:00
|
|
|
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer)
|
2010-06-28 22:22:41 +02:00
|
|
|
fail("should have thrown an exception")
|
|
|
|
|
} catch { case e => {} }
|
|
|
|
|
stateful.getRefState should equal("init")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it("ref should not rollback state for stateful server in case of success") {
|
2010-06-29 15:19:09 +02:00
|
|
|
val stateful = conf.getInstance(classOf[TransactionalActiveObject])
|
2010-06-28 22:22:41 +02:00
|
|
|
stateful.init
|
|
|
|
|
stateful.setRefState("init") // set init state
|
2010-06-30 16:26:15 +02:00
|
|
|
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state")
|
2010-06-28 22:22:41 +02:00
|
|
|
stateful.getRefState should equal("new state")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-06-30 16:26:15 +02:00
|
|
|
*/
|