-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix custom properties lost issue and add more tests
- Loading branch information
Showing
4 changed files
with
130 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseDataSourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.clickhouse.jdbc; | ||
|
||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.Properties; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import com.clickhouse.client.ClickHouseProtocol; | ||
import com.clickhouse.client.config.ClickHouseClientOption; | ||
import com.clickhouse.client.config.ClickHouseDefaults; | ||
|
||
public class ClickHouseDataSourceTest extends JdbcIntegrationTest { | ||
@Test(groups = "integration") | ||
public void testGetConnection() throws SQLException { | ||
String url = "jdbc:ch://" + getServerAddress(DEFAULT_PROTOCOL); | ||
String urlWithCredentials = "jdbc:ch://default@" + getServerAddress(ClickHouseProtocol.HTTP); | ||
String clientName = "client1"; | ||
int maxExecuteTime = 1234; | ||
boolean continueBatchOnError = true; | ||
|
||
Properties properties = new Properties(); | ||
properties.setProperty(ClickHouseDefaults.USER.getKey(), "default"); | ||
properties.setProperty(ClickHouseDefaults.PASSWORD.getKey(), ""); | ||
properties.setProperty(ClickHouseClientOption.CLIENT_NAME.getKey(), clientName); | ||
properties.setProperty(ClickHouseClientOption.MAX_EXECUTION_TIME.getKey(), Integer.toString(maxExecuteTime)); | ||
properties.setProperty(JdbcConfig.PROP_CONTINUE_BATCH, Boolean.toString(continueBatchOnError)); | ||
String params = String.format("?%s=%s&%s=%d&%s", ClickHouseClientOption.CLIENT_NAME.getKey(), clientName, | ||
ClickHouseClientOption.MAX_EXECUTION_TIME.getKey(), maxExecuteTime, JdbcConfig.PROP_CONTINUE_BATCH); | ||
|
||
for (ClickHouseDataSource ds : new ClickHouseDataSource[] { | ||
new ClickHouseDataSource(url, properties), | ||
new ClickHouseDataSource(urlWithCredentials, properties), | ||
new ClickHouseDataSource(url + params), | ||
new ClickHouseDataSource(urlWithCredentials + params), | ||
}) { | ||
for (ClickHouseConnection connection : new ClickHouseConnection[] { | ||
ds.getConnection(), | ||
ds.getConnection("default", ""), | ||
new ClickHouseDriver().connect(url, properties), | ||
new ClickHouseDriver().connect(urlWithCredentials, properties), | ||
new ClickHouseDriver().connect(url + params, new Properties()), | ||
new ClickHouseDriver().connect(urlWithCredentials + params, new Properties()), | ||
(ClickHouseConnection) DriverManager.getConnection(url, properties), | ||
(ClickHouseConnection) DriverManager.getConnection(urlWithCredentials, properties), | ||
(ClickHouseConnection) DriverManager.getConnection(url + params), | ||
(ClickHouseConnection) DriverManager.getConnection(urlWithCredentials + params), | ||
(ClickHouseConnection) DriverManager.getConnection(url + params, "default", ""), | ||
(ClickHouseConnection) DriverManager.getConnection(urlWithCredentials + params, "default", ""), | ||
}) { | ||
try (ClickHouseConnection conn = connection; Statement stmt = conn.createStatement()) { | ||
Assert.assertEquals(conn.getClientInfo(ClickHouseConnection.PROP_APPLICATION_NAME), clientName); | ||
Assert.assertEquals(stmt.getQueryTimeout(), maxExecuteTime); | ||
Assert.assertEquals(conn.getJdbcConfig().isContinueBatchOnError(), continueBatchOnError); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters