Test for RequiresNew propagation

This commit is contained in:
Peter Vlugter 2010-08-21 12:04:08 +12:00
parent ee0969383f
commit 9007c771ec

View file

@ -3,6 +3,8 @@ package se.scalablesolutions.akka.stm
import se.scalablesolutions.akka.actor.{Actor, Transactor}
import Actor._
import org.multiverse.api.exceptions.ReadonlyException
import org.scalatest.WordSpec
import org.scalatest.matchers.MustMatchers
@ -75,6 +77,54 @@ class StmSpec extends WordSpec with MustMatchers {
total must be (0)
}
"use the outer transaction settings by default" in {
val readonlyFactory = TransactionFactory(readonly = true)
val writableFactory = TransactionFactory(readonly = false)
val ref = Ref(0)
def writableOuter =
atomic(writableFactory) {
atomic(readonlyFactory) {
ref alter (_ + 1)
}
}
def readonlyOuter =
atomic(readonlyFactory) {
atomic(writableFactory) {
ref alter (_ + 1)
}
}
writableOuter must be (1)
evaluating { readonlyOuter } must produce [ReadonlyException]
}
"allow propagation settings for nested transactions" in {
val readonlyFactory = TransactionFactory(readonly = true)
val writableRequiresNewFactory = TransactionFactory(readonly = false, propagation = Propagation.RequiresNew)
val ref = Ref(0)
def writableOuter =
atomic(writableRequiresNewFactory) {
atomic(readonlyFactory) {
ref alter (_ + 1)
}
}
def readonlyOuter =
atomic(readonlyFactory) {
atomic(writableRequiresNewFactory) {
ref alter (_ + 1)
}
}
writableOuter must be (1)
readonlyOuter must be (2)
}
}
"Global STM" should {