Created
December 14, 2010 15:51
-
-
Save samhendley/740603 to your computer and use it in GitHub Desktop.
NestedTransactionExceptionTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo(val value: String) extends KeyedEntity[Long] { | |
val id: Long = 0 | |
} | |
object FooSchema extends Schema { | |
val foos = table[Foo] | |
def reset() = { | |
drop // its protected for some reason | |
create | |
} | |
} | |
def doSomething(except: Boolean) : Int = { | |
transaction{ | |
if(except) throw new Exception() | |
return 1 | |
} | |
} | |
test("Excepting out of nested transaction") { | |
transaction{ | |
FooSchema.reset | |
val foo1 = FooSchema.foos.insert(new Foo("test")) | |
FooSchema.foos.where(f => f.value === "test").size should equal(1) | |
intercept[Exception]{ | |
doSomething(true) | |
} | |
// fails with "no session exception" | |
FooSchema.foos.where(f => f.value === "test").size should equal(1) | |
} | |
} | |
test("Returning out of nested transaction") { | |
transaction{ | |
FooSchema.reset | |
val foo1 = FooSchema.foos.insert(new Foo("test")) | |
FooSchema.foos.where(f => f.value === "test").size should equal(1) | |
doSomething(false) | |
// fails with "no session exception" | |
FooSchema.foos.where(f => f.value === "test").size should equal(1) | |
} | |
} | |
test("Returning out of sibling transaction") { | |
transaction{ | |
FooSchema.reset | |
val foo1 = FooSchema.foos.insert(new Foo("test")) | |
FooSchema.foos.where(f => f.value === "test").size should equal(1) | |
doSomething(false) | |
} | |
transaction{ | |
// works! | |
FooSchema.foos.where(f => f.value === "test").size should equal(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment