Skip to content

Commit

Permalink
Merge pull request #2056 from ClickHouse/fix_jdbc_tests
Browse files Browse the repository at this point in the history
[jdbc-v2] Fixed Tests
  • Loading branch information
chernser authored Dec 28, 2024
2 parents 2703853 + 5673323 commit 590d334
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.clickhouse.jdbc;

import com.clickhouse.client.api.ClientConfigProperties;
import com.clickhouse.client.api.ClientException;
import com.clickhouse.client.api.query.GenericRecord;
import com.clickhouse.client.api.query.QuerySettings;
import org.slf4j.Logger;
Expand All @@ -23,12 +24,16 @@
import java.util.List;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertThrows;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;


public class StatementTest extends JdbcIntegrationTest {
Expand Down Expand Up @@ -503,26 +508,29 @@ public void testConnectionExhaustion() throws Exception {
@Test(groups = { "integration" })
public void testConcurrentCancel() throws Exception {
int maxNumConnections = 3;

Properties p = new Properties();
p.put(ClientConfigProperties.HTTP_MAX_OPEN_CONNECTIONS.getKey(), String.valueOf(maxNumConnections));
try (Connection conn = getJdbcConnection()) {
try (StatementImpl stmt = (StatementImpl) conn.createStatement()) {
stmt.executeQuery("SELECT number FROM system.numbers LIMIT 10000000000");
stmt.executeQuery("SELECT number FROM system.numbers LIMIT 1000000");
stmt.cancel();
}
for (int i = 0; i < maxNumConnections; i++) {
try (StatementImpl stmt = (StatementImpl) conn.createStatement()) {
final int threadNum = i;
log.info("Starting thread {}", threadNum);
new Thread(() -> {
final CountDownLatch latch = new CountDownLatch(1);
Thread t = new Thread(() -> {
try {
ResultSet rs = stmt.executeQuery("SELECT number FROM system.numbers LIMIT 10000000000");
rs.next();
log.info(rs.getObject(1).toString());
latch.countDown();
ResultSet rs = stmt.executeQuery("SELECT number FROM system.numbers LIMIT 10000000");
} catch (SQLException e) {
log.error("Error in thread {}", threadNum, e);
}
}).start();
});
t.start();

latch.await();
stmt.cancel();
}
}
Expand Down

0 comments on commit 590d334

Please sign in to comment.