Skip to content

Commit 590d334

Browse files
authored
Merge pull request #2056 from ClickHouse/fix_jdbc_tests
[jdbc-v2] Fixed Tests
2 parents 2703853 + 5673323 commit 590d334

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.clickhouse.jdbc;
22

33
import com.clickhouse.client.api.ClientConfigProperties;
4+
import com.clickhouse.client.api.ClientException;
45
import com.clickhouse.client.api.query.GenericRecord;
56
import com.clickhouse.client.api.query.QuerySettings;
67
import org.slf4j.Logger;
@@ -23,12 +24,16 @@
2324
import java.util.List;
2425
import java.util.Properties;
2526
import java.util.UUID;
27+
import java.util.concurrent.CountDownLatch;
28+
import java.util.concurrent.atomic.AtomicReference;
2629

2730
import static org.testng.Assert.assertEquals;
2831
import static org.testng.Assert.assertFalse;
32+
import static org.testng.Assert.assertNotNull;
2933
import static org.testng.Assert.assertNull;
3034
import static org.testng.Assert.assertThrows;
3135
import static org.testng.Assert.assertTrue;
36+
import static org.testng.Assert.fail;
3237

3338

3439
public class StatementTest extends JdbcIntegrationTest {
@@ -503,26 +508,29 @@ public void testConnectionExhaustion() throws Exception {
503508
@Test(groups = { "integration" })
504509
public void testConcurrentCancel() throws Exception {
505510
int maxNumConnections = 3;
506-
511+
Properties p = new Properties();
512+
p.put(ClientConfigProperties.HTTP_MAX_OPEN_CONNECTIONS.getKey(), String.valueOf(maxNumConnections));
507513
try (Connection conn = getJdbcConnection()) {
508514
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");
510516
stmt.cancel();
511517
}
512518
for (int i = 0; i < maxNumConnections; i++) {
513519
try (StatementImpl stmt = (StatementImpl) conn.createStatement()) {
514520
final int threadNum = i;
515521
log.info("Starting thread {}", threadNum);
516-
new Thread(() -> {
522+
final CountDownLatch latch = new CountDownLatch(1);
523+
Thread t = new Thread(() -> {
517524
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");
521527
} catch (SQLException e) {
522528
log.error("Error in thread {}", threadNum, e);
523529
}
524-
}).start();
530+
});
531+
t.start();
525532

533+
latch.await();
526534
stmt.cancel();
527535
}
528536
}

0 commit comments

Comments
 (0)