Test for RequiresNew propagation
This commit is contained in:
parent
ee0969383f
commit
9007c771ec
1 changed files with 50 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue