@@ -37,6 +37,8 @@ import kotlin.reflect.typeOf
3737
3838private const val URL = " jdbc:h2:mem:test5;DB_CLOSE_DELAY=-1;MODE=MySQL;DATABASE_TO_UPPER=false"
3939
40+ private const val MAXIMUM_POOL_SIZE = 5
41+
4042@DataSchema
4143interface Customer {
4244 val id: Int?
@@ -108,7 +110,7 @@ class JdbcTest {
108110 private fun initializeDataSource () {
109111 val config = HikariConfig ().apply {
110112 jdbcUrl = URL
111- maximumPoolSize = 10
113+ maximumPoolSize = MAXIMUM_POOL_SIZE
112114 minimumIdle = 2
113115 }
114116 dataSource = HikariDataSource (config)
@@ -172,7 +174,9 @@ class JdbcTest {
172174 2 -> 1
173175 else -> 1 // for 1 row or other small limits in tests
174176 }
175- casted.filter { it[Customer ::age] != null && it[Customer ::age]!! > 30 }.rowsCount() shouldBe expectedOlderThan30
177+ casted.filter {
178+ it[Customer ::age] != null && it[Customer ::age]!! > 30
179+ }.rowsCount() shouldBe expectedOlderThan30
176180 casted[0 ][1 ] shouldBe " John"
177181 }
178182
@@ -1133,51 +1137,49 @@ class JdbcTest {
11331137
11341138 @Test
11351139 fun `repeated read from table with limit using DataSource` () {
1136- // Verify our DataSource integration handles repeated reads correctly.
1140+ // Verify DataSource integration handles repeated sequential reads correctly.
11371141 // Covers issue #494 where repeated reads with limit produced incorrect results.
1138-
11391142 val tableName = " Customer"
1140-
1141- repeat(10 ) {
1143+ repeat(MAXIMUM_POOL_SIZE * 2 ) {
11421144 val df = DataFrame .readSqlTable(dataSource, tableName, 2 )
11431145 assertCustomerData(df, 2 )
11441146 }
11451147 }
11461148
11471149 @Test
1148- fun `DataSource connection pooling - multiple concurrent reads` () {
1149- // Verify our code properly closes connections and returns them to the pool.
1150- // Would fail on the 11th iteration if connections leak (maximumPoolSize=10).
1151-
1152- repeat(10 ) {
1150+ fun `DataSource sequential reads return connections to pool` () {
1151+ // Verify connections are properly closed and returned to the pool after each read.
1152+ // Would fail on iteration 6 if connections leak (maximumPoolSize=5).
1153+ repeat(MAXIMUM_POOL_SIZE * 2 ) {
11531154 val df = DataFrame .readSqlTable(dataSource, " Customer" , limit = 1 )
11541155 df.rowsCount() shouldBe 1
1156+ assertCustomerData(df, 1 )
11551157 }
11561158 }
11571159
11581160 @Test
1159- fun `DataSource connection pooling - alternating table reads` () {
1160- // Test connection reuse across different table schemas.
1161- // Ensures no state pollution when switching between tables.
1162-
1163- repeat(10 ) { i ->
1161+ fun `DataSource sequential reads with alternating tables` () {
1162+ // Test connection reuse when sequentially reading from different tables.
1163+ // Ensures no state pollution when switching between table schemas.
1164+ repeat(MAXIMUM_POOL_SIZE * 2 ) { i ->
11641165 val tableName = if (i % 2 == 0 ) " Customer" else " Sale"
11651166 val df = DataFrame .readSqlTable(dataSource, tableName, limit = 1 )
11661167 df.rowsCount() shouldBe 1
11671168 }
11681169 }
11691170
11701171 @Test
1171- fun `DataSource connection pooling - query and table mix` () {
1172- // Verify both readSqlTable and readSqlQuery manage the connection lifecycle correctly.
1173- // Tests that different code paths can alternate without resource leaks.
1174-
1175- repeat(5 ) {
1172+ fun `DataSource sequential reads with mixed query and table operations` () {
1173+ // Verify both readSqlTable and readSqlQuery properly manage the connection lifecycle.
1174+ // Tests that different code paths can alternate sequentially without resource leaks.
1175+ repeat(MAXIMUM_POOL_SIZE * 2 ) {
11761176 val dfTable = DataFrame .readSqlTable(dataSource, " Customer" , limit = 1 )
11771177 dfTable.rowsCount() shouldBe 1
1178+ assertCustomerData(dfTable, 1 )
11781179
11791180 val dfQuery = DataFrame .readSqlQuery(dataSource, CUSTOMER_SALES_QUERY , limit = 1 )
11801181 dfQuery.rowsCount() shouldBe 1
1182+ assertCustomerSalesData(dfQuery, 1 )
11811183 }
11821184 }
11831185}
0 commit comments