fixed bugs regarding oneway transaction managament

This commit is contained in:
Jonas Boner 2009-06-30 16:01:50 +02:00
parent 6359920fa4
commit 2cfeda0ce0
23 changed files with 1095 additions and 2694 deletions

View file

@ -1,24 +1,29 @@
package se.scalablesolutions.akka.kernel.actor
import java.util.concurrent.locks.ReentrantLock
import java.util.concurrent.TimeUnit
import junit.framework.TestCase
import kernel.state.TransactionalState
import kernel.reactor._
import org.junit.{Test, Before}
import org.junit.Assert._
case class SetMapState(key: String, value: String)
case class SetVectorState(key: String)
case class SetRefState(key: String)
case class GetMapState(key: String)
case object GetVectorState
case object GetRefState
case class SetMapState(key: String, value: String)
case class SetVectorState(key: String)
case class SetRefState(key: String)
case class Success(key: String, value: String)
case class Failure(key: String, value: String, failer: Actor)
case class SetMapStateOneWay(key: String, value: String)
case class SetVectorStateOneWay(key: String)
case class SetRefStateOneWay(key: String)
case class SuccessOneWay(key: String, value: String)
case class FailureOneWay(key: String, value: String, failer: Actor)
class InMemStatefulActor extends Actor {
timeout = 100000
makeTransactional
private val mapState = TransactionalState.newInMemoryMap[String, String]
private val vectorState = TransactionalState.newInMemoryVector[String]
@ -51,6 +56,22 @@ class InMemStatefulActor extends Actor {
refState.swap(msg)
failer !! "Failure"
reply(msg)
case SetMapStateOneWay(key, msg) =>
mapState.put(key, msg)
case SetVectorStateOneWay(msg) =>
vectorState.add(msg)
case SetRefStateOneWay(msg) =>
refState.swap(msg)
case SuccessOneWay(key, msg) =>
mapState.put(key, msg)
vectorState.add(msg)
refState.swap(msg)
case FailureOneWay(key, msg, failer) =>
mapState.put(key, msg)
vectorState.add(msg)
refState.swap(msg)
failer ! "Failure"
}
}
@ -61,8 +82,19 @@ class InMemFailerActor extends Actor {
throw new RuntimeException("expected")
}
}
class InMemoryActorSpec extends TestCase {
@Test
def testOneWayMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
val stateful = new InMemStatefulActor
stateful.start
stateful ! SetMapStateOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init") // set init state
Thread.sleep(100)
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactional
Thread.sleep(100)
assertEquals("new state", (stateful !! GetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess")).get)
}
class InMemoryActorSpec {
@Test
def testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
val stateful = new InMemStatefulActor
@ -72,6 +104,19 @@ class InMemoryActorSpec {
assertEquals("new state", (stateful !! GetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess")).get)
}
@Test
def testOneWayMapShouldRollbackStateForStatefulServerInCaseOfFailure = {
val stateful = new InMemStatefulActor
stateful.start
val failer = new InMemFailerActor
failer.start
stateful ! SetMapStateOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init") // set init state
Thread.sleep(100)
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactional method
Thread.sleep(100)
assertEquals("init", (stateful !! GetMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")).get) // check that state is == init state
}
@Test
def testMapShouldRollbackStateForStatefulServerInCaseOfFailure = {
val stateful = new InMemStatefulActor
@ -86,16 +131,39 @@ class InMemoryActorSpec {
assertEquals("init", (stateful !! GetMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")).get) // check that state is == init state
}
@Test
def testOneWayVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
val stateful = new InMemStatefulActor
stateful.start
stateful ! SetVectorStateOneWay("init") // set init state
Thread.sleep(100)
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactional
Thread.sleep(100)
assertEquals("new state", (stateful !! GetVectorState).get)
}
@Test
def testVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
val stateful = new InMemStatefulActor
stateful.start
stateful !! SetVectorState("init") // set init state
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactional
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // to trigger commit
assertEquals("new state", (stateful !! GetVectorState).get)
}
@Test
def testOneWayVectorShouldRollbackStateForStatefulServerInCaseOfFailure = {
val stateful = new InMemStatefulActor
stateful.start
stateful ! SetVectorStateOneWay("init") // set init state
Thread.sleep(100)
val failer = new InMemFailerActor
failer.start
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactional method
Thread.sleep(100)
assertEquals("init", (stateful !! GetVectorState).get) // check that state is == init state
}
@Test
def testVectorShouldRollbackStateForStatefulServerInCaseOfFailure = {
val stateful = new InMemStatefulActor
@ -110,16 +178,39 @@ class InMemoryActorSpec {
assertEquals("init", (stateful !! GetVectorState).get) // check that state is == init state
}
@Test
def testOneWayRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
val stateful = new InMemStatefulActor
stateful.start
stateful ! SetRefStateOneWay("init") // set init state
Thread.sleep(100)
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactional
Thread.sleep(100)
assertEquals("new state", (stateful !! GetRefState).get)
}
@Test
def testRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess = {
val stateful = new InMemStatefulActor
stateful.start
stateful !! SetRefState("init") // set init state
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactional
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // to trigger commit
assertEquals("new state", (stateful !! GetRefState).get)
}
@Test
def testOneWayRefShouldRollbackStateForStatefulServerInCaseOfFailure = {
val stateful = new InMemStatefulActor
stateful.start
stateful ! SetRefStateOneWay("init") // set init state
Thread.sleep(100)
val failer = new InMemFailerActor
failer.start
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactional method
Thread.sleep(100)
assertEquals("init", (stateful !! GetRefState).get) // check that state is == init state
}
@Test
def testRefShouldRollbackStateForStatefulServerInCaseOfFailure = {
val stateful = new InMemStatefulActor