@@ -369,43 +369,43 @@ class CommonBasicTest(private val path: DatabasePath) {
369369 assertEquals(outerJoinStatementWithOn?.getResults()?.size, books.size)
370370 }
371371
372- fun testConcurrency () = runBlocking(Dispatchers .Default ) {
373- val book1 = Book (name = " The Da Vinci Code" , author = " Dan Brown" , pages = 454 , price = 16.96 )
374- val book2 = Book (name = " The Lost Symbol" , author = " Dan Brown" , pages = 510 , price = 19.95 )
375- val database = Database (getDefaultDBConfig(), true )
376- launch {
377- var statement: SelectStatement <Book >? = null
378- database suspendedScope {
379- statement = BookTable { table ->
380- table INSERT listOf (book1, book2)
381- table SELECT X
382- }
383- }
384-
372+ fun testConcurrency () = Database (getDefaultDBConfig(), true ).databaseAutoClose { database ->
373+ runBlocking(Dispatchers .Default ) {
374+ val book1 = Book (name = " The Da Vinci Code" , author = " Dan Brown" , pages = 454 , price = 16.96 )
375+ val book2 = Book (name = " The Lost Symbol" , author = " Dan Brown" , pages = 510 , price = 19.95 )
385376 launch {
386- val book1NewPrice = 18.96
387- val book2NewPrice = 21.95
388- val newBook1 = Book (name = " The Da Vinci Code" , author = " Dan Brown" , pages = 454 , price = book1NewPrice)
389- val newBook2 = Book (name = " The Lost Symbol" , author = " Dan Brown" , pages = 510 , price = book2NewPrice)
390- var newResult: SelectStatement <Book >? = null
377+ var statement: SelectStatement <Book >? = null
391378 database suspendedScope {
392- newResult = transaction {
393- BookTable { table ->
394- table UPDATE SET { price = book1NewPrice } WHERE (name EQ book1.name AND (price EQ book1.price))
395- table UPDATE SET { price = book2NewPrice } WHERE (name EQ book2.name AND (price EQ book2.price))
396- table SELECT X
379+ statement = BookTable { table ->
380+ table INSERT listOf (book1, book2)
381+ table SELECT X
382+ }
383+ }
384+
385+ launch {
386+ val book1NewPrice = 18.96
387+ val book2NewPrice = 21.95
388+ val newBook1 = Book (name = " The Da Vinci Code" , author = " Dan Brown" , pages = 454 , price = book1NewPrice)
389+ val newBook2 = Book (name = " The Lost Symbol" , author = " Dan Brown" , pages = 510 , price = book2NewPrice)
390+ var newResult: SelectStatement <Book >? = null
391+ database suspendedScope {
392+ newResult = transaction {
393+ BookTable { table ->
394+ table UPDATE SET { price = book1NewPrice } WHERE (name EQ book1.name AND (price EQ book1.price))
395+ table UPDATE SET { price = book2NewPrice } WHERE (name EQ book2.name AND (price EQ book2.price))
396+ table SELECT X
397+ }
397398 }
398399 }
400+
401+ assertEquals(true , newResult!! .getResults().any { it == newBook1 })
402+ assertEquals(true , newResult!! .getResults().any { it == newBook2 })
399403 }
400404
401- assertEquals(true , newResult !! .getResults().any { it == newBook1 })
402- assertEquals(true , newResult !! .getResults().any { it == newBook2 })
405+ assertEquals(true , statement !! .getResults().any { it == book1 })
406+ assertEquals(true , statement !! .getResults().any { it == book2 })
403407 }
404-
405- assertEquals(true , statement!! .getResults().any { it == book1 })
406- assertEquals(true , statement!! .getResults().any { it == book2 })
407408 }
408- Unit
409409 }
410410
411411 fun testPrimitiveTypeForKSP () {
@@ -428,7 +428,7 @@ class CommonBasicTest(private val path: DatabasePath) {
428428 }
429429 }
430430
431- fun testNullInsertAndSelect () {
431+ fun testNullValue () {
432432 val config = DatabaseConfiguration (
433433 name = DATABASE_NAME ,
434434 path = path,
@@ -487,9 +487,9 @@ class CommonBasicTest(private val path: DatabasePath) {
487487 }
488488 val result2 = selectStatement.getResults().first()
489489 assertEquals(1 , selectStatement.getResults().size)
490- assertEquals(8 , result1 .paramInt)
491- assertEquals(null , result1 .paramString)
492- assertEquals(8.8 , result1 .paramDouble)
490+ assertEquals(8 , result2 .paramInt)
491+ assertEquals(null , result2 .paramString)
492+ assertEquals(8.8 , result2 .paramDouble)
493493 }
494494 }
495495
0 commit comments