diff --git a/akka-core/src/test/scala/stm/StmSpec.scala b/akka-core/src/test/scala/stm/StmSpec.scala index 133725bb98..cadd419554 100644 --- a/akka-core/src/test/scala/stm/StmSpec.scala +++ b/akka-core/src/test/scala/stm/StmSpec.scala @@ -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 {