-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
26 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
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
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 |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
import java.util.Properties; | ||
|
||
import com.clickhouse.client.ClickHouseProtocol; | ||
|
||
import org.eclipse.jetty.client.ProxyProtocolClientConnectionFactory.V2.Tag.Protocol; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
|
@@ -12,25 +15,25 @@ public class ClickhouseJdbcUrlParserTest { | |
@Test(groups = "unit") | ||
public void testParseDashes() throws Exception { | ||
Properties props = new Properties(); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse( | ||
"jdbc:clickhouse://foo.yandex:1337/db-name-with-dash", new Properties()); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser | ||
.parse("jdbc:clickhouse://foo.yandex:1337/db-name-with-dash", new Properties()); | ||
Assert.assertEquals(chProps.getDatabase(), "db-name-with-dash"); | ||
} | ||
|
||
@Test(groups = "unit") | ||
public void testParseTrailingSlash() throws Exception { | ||
Properties props = new Properties(); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse( | ||
"jdbc:clickhouse://foo.yandex:1337/", new Properties()); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse("jdbc:clickhouse://foo.yandex:1337/", | ||
new Properties()); | ||
Assert.assertEquals(chProps.getDatabase(), "default"); | ||
} | ||
|
||
@Test(groups = "unit") | ||
public void testParseDbInPathAndProps() throws Exception { | ||
ClickHouseProperties props = new ClickHouseProperties(); | ||
props.setDatabase("database-name"); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse( | ||
"jdbc:clickhouse://foo.yandex:1337/database-name", props.asProperties()); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse("jdbc:clickhouse://foo.yandex:1337/database-name", | ||
props.asProperties()); | ||
Assert.assertEquals(chProps.getDatabase(), "database-name"); | ||
Assert.assertEquals(chProps.getPath(), "/"); | ||
} | ||
|
@@ -40,8 +43,8 @@ public void testParseDbInPathAndProps2() throws Exception { | |
ClickHouseProperties props = new ClickHouseProperties(); | ||
props.setDatabase("database-name"); | ||
props.setUsePathAsDb(false); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse( | ||
"jdbc:clickhouse://foo.yandex:1337/database-name", props.asProperties()); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse("jdbc:clickhouse://foo.yandex:1337/database-name", | ||
props.asProperties()); | ||
Assert.assertEquals(chProps.getDatabase(), "database-name"); | ||
Assert.assertEquals(chProps.getPath(), "/database-name"); | ||
} | ||
|
@@ -50,8 +53,8 @@ public void testParseDbInPathAndProps2() throws Exception { | |
public void testParsePathDefaultDb() throws Exception { | ||
ClickHouseProperties props = new ClickHouseProperties(); | ||
props.setPath("/path"); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse( | ||
"jdbc:clickhouse://foo.yandex:1337/", props.asProperties()); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse("jdbc:clickhouse://foo.yandex:1337/", | ||
props.asProperties()); | ||
Assert.assertEquals(chProps.getDatabase(), "default"); | ||
Assert.assertEquals(chProps.getPath(), "/path"); | ||
} | ||
|
@@ -61,17 +64,17 @@ public void testParsePathDefaultDb2() throws Exception { | |
ClickHouseProperties props = new ClickHouseProperties(); | ||
props.setPath("/path"); | ||
props.setUsePathAsDb(false); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse( | ||
"jdbc:clickhouse://foo.yandex:1337", props.asProperties()); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse("jdbc:clickhouse://foo.yandex:1337", | ||
props.asProperties()); | ||
Assert.assertEquals(chProps.getDatabase(), "default"); | ||
Assert.assertEquals(chProps.getPath(), "/"); //uri takes priority | ||
Assert.assertEquals(chProps.getPath(), "/"); // uri takes priority | ||
} | ||
|
||
@Test(groups = "unit") | ||
public void testParsePathAndDb() throws Exception { | ||
ClickHouseProperties props = new ClickHouseProperties(); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse( | ||
"jdbc:clickhouse://foo.yandex:1337/db?database=dbname", props.asProperties()); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser | ||
.parse("jdbc:clickhouse://foo.yandex:1337/db?database=dbname", props.asProperties()); | ||
Assert.assertEquals(chProps.getDatabase(), "db"); | ||
Assert.assertEquals(chProps.getPath(), "/"); | ||
} | ||
|
@@ -80,10 +83,33 @@ public void testParsePathAndDb() throws Exception { | |
public void testParsePathAndDb2() throws Exception { | ||
ClickHouseProperties props = new ClickHouseProperties(); | ||
props.setUsePathAsDb(false); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse( | ||
"jdbc:clickhouse://foo.yandex:1337/db?database=dbname", props.asProperties()); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser | ||
.parse("jdbc:clickhouse://foo.yandex:1337/db?database=dbname", props.asProperties()); | ||
Assert.assertEquals(chProps.getDatabase(), "dbname"); | ||
Assert.assertEquals(chProps.getPath(), "/db"); | ||
} | ||
|
||
@Test(groups = "unit") | ||
public void testParseCredentials() throws Exception { | ||
ClickHouseProperties props = new ClickHouseProperties(); | ||
props.setUser("default1"); | ||
props.setPassword("password1"); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse("jdbc:clickhouse://user:a:[email protected]/test", | ||
props.asProperties()); | ||
Assert.assertEquals(chProps.getUser(), "user"); | ||
Assert.assertEquals(chProps.getPassword(), "a:passwd"); | ||
} | ||
|
||
@Test(groups = "unit") | ||
public void testParseProtocol() throws Exception { | ||
ClickHouseProperties props = new ClickHouseProperties(); | ||
ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse("jdbc:clickhouse://foo.ch/test", | ||
props.asProperties()); | ||
Assert.assertEquals(chProps.getProtocol(), ClickHouseProtocol.HTTP); | ||
Assert.assertEquals(chProps.getPort(), ClickHouseProtocol.HTTP.getDefaultPort()); | ||
|
||
chProps = ClickhouseJdbcUrlParser.parse("jdbc:clickhouse://foo.ch/test?protocol=grpc", props.asProperties()); | ||
Assert.assertEquals(chProps.getProtocol(), ClickHouseProtocol.GRPC); | ||
Assert.assertEquals(chProps.getPort(), ClickHouseProtocol.GRPC.getDefaultPort()); | ||
} | ||
} |