Skip to content

Instantly share code, notes, and snippets.

@samhendley
Created December 14, 2010 15:51
Show Gist options
  • Save samhendley/740603 to your computer and use it in GitHub Desktop.
Save samhendley/740603 to your computer and use it in GitHub Desktop.
NestedTransactionExceptionTest.scala
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