@@ -24,9 +24,11 @@ import com.ctrip.sqllin.dsl.sql.clause.*
2424import com.ctrip.sqllin.dsl.sql.clause.OrderByWay.ASC
2525import com.ctrip.sqllin.dsl.sql.clause.OrderByWay.DESC
2626import com.ctrip.sqllin.dsl.sql.statement.SelectStatement
27- import kotlinx.coroutines.Dispatchers
27+ import kotlinx.coroutines.DelicateCoroutinesApi
28+ import kotlinx.coroutines.ExperimentalCoroutinesApi
2829import kotlinx.coroutines.launch
29- import kotlinx.coroutines.runBlocking
30+ import kotlinx.coroutines.newSingleThreadContext
31+ import kotlinx.coroutines.test.runTest
3032import kotlin.test.assertEquals
3133import kotlin.test.assertNotEquals
3234
@@ -77,7 +79,7 @@ class CommonBasicTest(private val path: DatabasePath) {
7779 }
7880 }
7981 assertEquals(true , statement!! .getResults().any { it == book1 })
80- assertEquals(true , statement!! .getResults().any { it == book2 })
82+ assertEquals(true , statement.getResults().any { it == book2 })
8183
8284 var statement1: SelectStatement <Book >? = null
8385 var statement2: SelectStatement <Book >? = null
@@ -105,7 +107,7 @@ class CommonBasicTest(private val path: DatabasePath) {
105107 }
106108
107109 assertEquals(true , statement!! .getResults().any { it == book1 })
108- assertEquals(true , statement!! .getResults().any { it == book2 })
110+ assertEquals(true , statement.getResults().any { it == book2 })
109111
110112 val book1NewPrice = 18.96
111113 val book2NewPrice = 21.95
@@ -124,7 +126,7 @@ class CommonBasicTest(private val path: DatabasePath) {
124126 }
125127
126128 assertEquals(true , newResult!! .getResults().any { it == newBook1 })
127- assertEquals(true , newResult!! .getResults().any { it == newBook2 })
129+ assertEquals(true , newResult.getResults().any { it == newBook2 })
128130 }
129131
130132 fun testSelectWhereClause () = Database (getDefaultDBConfig(), true ).databaseAutoClose { database ->
@@ -281,10 +283,10 @@ class CommonBasicTest(private val path: DatabasePath) {
281283 }
282284 }
283285 assertEquals(7 , statement!! .getResults().size)
284- assertEquals(2 , statement!! .getResults().count { it == book0 })
285- assertEquals(2 , statement!! .getResults().count { it == book1 })
286- assertEquals(1 , statement!! .getResults().count { it == book2 })
287- assertEquals(2 , statement!! .getResults().count { it == book3 })
286+ assertEquals(2 , statement.getResults().count { it == book0 })
287+ assertEquals(2 , statement.getResults().count { it == book1 })
288+ assertEquals(1 , statement.getResults().count { it == book2 })
289+ assertEquals(2 , statement.getResults().count { it == book3 })
288290 }
289291
290292 fun testFunction () = Database (getDefaultDBConfig(), true ).databaseAutoClose { database ->
@@ -370,11 +372,12 @@ class CommonBasicTest(private val path: DatabasePath) {
370372 assertEquals(outerJoinStatementWithOn?.getResults()?.size, books.size)
371373 }
372374
375+ @OptIn(DelicateCoroutinesApi ::class , ExperimentalCoroutinesApi ::class )
373376 fun testConcurrency () = Database (getDefaultDBConfig(), true ).databaseAutoClose { database ->
374- runBlocking( Dispatchers . Default ) {
377+ runTest {
375378 val book1 = Book (name = " The Da Vinci Code" , author = " Dan Brown" , pages = 454 , price = 16.96 )
376379 val book2 = Book (name = " The Lost Symbol" , author = " Dan Brown" , pages = 510 , price = 19.95 )
377- launch {
380+ launch(newSingleThreadContext( " test0 " )) {
378381 lateinit var statement: SelectStatement <Book >
379382 database suspendedScope {
380383 statement = BookTable { table ->
@@ -385,7 +388,7 @@ class CommonBasicTest(private val path: DatabasePath) {
385388 assertEquals(true , statement.getResults().any { it == book1 })
386389 assertEquals(true , statement.getResults().any { it == book2 })
387390 }
388- launch {
391+ launch(newSingleThreadContext( " test1 " )) {
389392 val book1NewPrice = 18.96
390393 val book2NewPrice = 21.95
391394 val newBook1 = Book (name = " The Da Vinci Code" , author = " Dan Brown" , pages = 454 , price = book1NewPrice)
@@ -407,7 +410,7 @@ class CommonBasicTest(private val path: DatabasePath) {
407410
408411 fun testPrimitiveTypeForKSP () {
409412 TestPrimitiveTypeForKSPTable {
410- SET < TestPrimitiveTypeForKSP > {
413+ SET {
411414 assertEquals(0 , testInt)
412415 assertEquals(0L , testLong)
413416 assertEquals(0 , testShort)
0 commit comments