|
1 | 1 | package com.clickhouse.jdbc; |
2 | 2 |
|
3 | 3 | import com.clickhouse.client.api.ClientConfigProperties; |
| 4 | +import com.clickhouse.client.api.ClientException; |
4 | 5 | import com.clickhouse.client.api.query.GenericRecord; |
5 | 6 | import com.clickhouse.client.api.query.QuerySettings; |
6 | 7 | import org.slf4j.Logger; |
|
23 | 24 | import java.util.List; |
24 | 25 | import java.util.Properties; |
25 | 26 | import java.util.UUID; |
| 27 | +import java.util.concurrent.CountDownLatch; |
| 28 | +import java.util.concurrent.atomic.AtomicReference; |
26 | 29 |
|
27 | 30 | import static org.testng.Assert.assertEquals; |
28 | 31 | import static org.testng.Assert.assertFalse; |
| 32 | +import static org.testng.Assert.assertNotNull; |
29 | 33 | import static org.testng.Assert.assertNull; |
30 | 34 | import static org.testng.Assert.assertThrows; |
31 | 35 | import static org.testng.Assert.assertTrue; |
| 36 | +import static org.testng.Assert.fail; |
32 | 37 |
|
33 | 38 |
|
34 | 39 | public class StatementTest extends JdbcIntegrationTest { |
@@ -503,26 +508,29 @@ public void testConnectionExhaustion() throws Exception { |
503 | 508 | @Test(groups = { "integration" }) |
504 | 509 | public void testConcurrentCancel() throws Exception { |
505 | 510 | int maxNumConnections = 3; |
506 | | - |
| 511 | + Properties p = new Properties(); |
| 512 | + p.put(ClientConfigProperties.HTTP_MAX_OPEN_CONNECTIONS.getKey(), String.valueOf(maxNumConnections)); |
507 | 513 | try (Connection conn = getJdbcConnection()) { |
508 | 514 | try (StatementImpl stmt = (StatementImpl) conn.createStatement()) { |
509 | | - stmt.executeQuery("SELECT number FROM system.numbers LIMIT 10000000000"); |
| 515 | + stmt.executeQuery("SELECT number FROM system.numbers LIMIT 1000000"); |
510 | 516 | stmt.cancel(); |
511 | 517 | } |
512 | 518 | for (int i = 0; i < maxNumConnections; i++) { |
513 | 519 | try (StatementImpl stmt = (StatementImpl) conn.createStatement()) { |
514 | 520 | final int threadNum = i; |
515 | 521 | log.info("Starting thread {}", threadNum); |
516 | | - new Thread(() -> { |
| 522 | + final CountDownLatch latch = new CountDownLatch(1); |
| 523 | + Thread t = new Thread(() -> { |
517 | 524 | try { |
518 | | - ResultSet rs = stmt.executeQuery("SELECT number FROM system.numbers LIMIT 10000000000"); |
519 | | - rs.next(); |
520 | | - log.info(rs.getObject(1).toString()); |
| 525 | + latch.countDown(); |
| 526 | + ResultSet rs = stmt.executeQuery("SELECT number FROM system.numbers LIMIT 10000000"); |
521 | 527 | } catch (SQLException e) { |
522 | 528 | log.error("Error in thread {}", threadNum, e); |
523 | 529 | } |
524 | | - }).start(); |
| 530 | + }); |
| 531 | + t.start(); |
525 | 532 |
|
| 533 | + latch.await(); |
526 | 534 | stmt.cancel(); |
527 | 535 | } |
528 | 536 | } |
|
0 commit comments