|
|
@ -44,6 +44,19 @@ class DatabaseTest { |
|
|
|
assertEquals(0, elapsed) |
|
|
|
assertEquals(0, elapsed) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun testSuccessfulOnce() { |
|
|
|
|
|
|
|
val result = database.executeOnce { connection -> |
|
|
|
|
|
|
|
connection.prepareStatement("VALUES 12345").use { stmt -> |
|
|
|
|
|
|
|
val rows = stmt.executeQuery() |
|
|
|
|
|
|
|
assertTrue(rows.next()) |
|
|
|
|
|
|
|
return@executeOnce rows.getInt(1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(12345, result) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testDeadlockRetry() = runBlockingTest { |
|
|
|
fun testDeadlockRetry() = runBlockingTest { |
|
|
|
var attempts = 0 |
|
|
|
var attempts = 0 |
|
|
@ -68,6 +81,20 @@ class DatabaseTest { |
|
|
|
assertEquals(10, elapsed) |
|
|
|
assertEquals(10, elapsed) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun testDeadlockOnce() { |
|
|
|
|
|
|
|
var attempts = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertFailsWith<DeadlockException> { |
|
|
|
|
|
|
|
database.executeOnce<Unit> { |
|
|
|
|
|
|
|
attempts++ |
|
|
|
|
|
|
|
throw DeadlockException() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(1, attempts) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testDeadlockFailure() { |
|
|
|
fun testDeadlockFailure() { |
|
|
|
var attempts = 0 |
|
|
|
var attempts = 0 |
|
|
@ -100,6 +127,20 @@ class DatabaseTest { |
|
|
|
assertEquals(1, attempts) |
|
|
|
assertEquals(1, attempts) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun testNonDeadlockFailureOnce() { |
|
|
|
|
|
|
|
var attempts = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertFailsWith<TestException> { |
|
|
|
|
|
|
|
database.executeOnce<Unit> { |
|
|
|
|
|
|
|
attempts++ |
|
|
|
|
|
|
|
throw TestException() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(1, attempts) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testDeadlockCauseChain() = runBlockingTest { |
|
|
|
fun testDeadlockCauseChain() = runBlockingTest { |
|
|
|
var attempts = 0 |
|
|
|
var attempts = 0 |
|
|
|