Skip to content

Commit bf2b08c

Browse files
committed
Add tests & fix logic in edge case
1 parent 4158b00 commit bf2b08c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDriver.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ public boolean isV2(String url) {
5555
return false;
5656
}
5757

58-
if (url != null && url.contains("clickhouse.jdbc.v1")) {
58+
if (url != null && url.contains("clickhouse.jdbc.v")) {
5959
urlFlagSent = true;
6060

6161
if (url.contains("clickhouse.jdbc.v1=true")) {
6262
log.info("V1 driver is requested through URL.");
6363
return false;
64+
} if (url.contains("clickhouse.jdbc.v2=false")) {
65+
log.info("V1 driver is requested through URL.");
66+
return false;
6467
} else {
6568
log.info("V2 driver is requested through URL.");
6669
return true;

clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseDriverTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ public void testConnect() throws SQLException {
2828
Connection conn = driver.connect("jdbc:clickhouse://" + address, null);
2929
conn.close();
3030
}
31+
@Test(groups = "integration")
32+
public void testV2Driver() {
33+
ClickHouseDriver driver = new ClickHouseDriver();
34+
Boolean V1 = false;
35+
Boolean V2 = true;
36+
Assert.assertEquals(driver.isV2("jdbc:clickhouse://localhost:8123"), V2);
37+
Assert.assertEquals(driver.isV2("jdbc:clickhouse://localhost:8123?clickhouse.jdbc.v1=true"), V1);
38+
Assert.assertEquals(driver.isV2("jdbc:clickhouse://localhost:8123?clickhouse.jdbc.v1=false"), V2);
39+
Assert.assertEquals(driver.isV2("jdbc:clickhouse://localhost:8123?clickhouse.jdbc.v2=true"), V2);
40+
Assert.assertEquals(driver.isV2("jdbc:clickhouse://localhost:8123?clickhouse.jdbc.v2=false"), V1);
41+
42+
}
3143
}

0 commit comments

Comments
 (0)