This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
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
3 changed files
with
63 additions
and
25 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 was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
src/test/java/com/sina/bip/hangout/outputs/BlancedClickhouseDataSourceTest.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,43 @@ | ||
package com.sina.bip.hangout.outputs; | ||
|
||
import ru.yandex.clickhouse.BalancedClickhouseDataSource; | ||
import ru.yandex.clickhouse.settings.ClickHouseProperties; | ||
|
||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static ru.yandex.clickhouse.ClickhouseJdbcUrlParser.JDBC_CLICKHOUSE_PREFIX; | ||
|
||
public class BlancedClickhouseDataSourceTest { | ||
public static void main(String args[]) throws Exception { | ||
|
||
String h = "localhost:8123"; | ||
String db = "test"; | ||
ClickHouseProperties properties = new ClickHouseProperties(); | ||
//String jdbcLink = String.format("jdbc:clickhouse://%s/%s", h, db); | ||
String jdbcLink = "jdbc:clickhouse://10.19.0.120:8123,10.13.56.170:8123,10.13.0.235:8123,10.13.0.232:8123/test"; | ||
|
||
Pattern URL_TEMPLATE = Pattern.compile(JDBC_CLICKHOUSE_PREFIX + "//([a-zA-Z0-9_:,.]+)(/[a-zA-Z0-9_]+)?"); | ||
Matcher m = URL_TEMPLATE.matcher(jdbcLink); | ||
if (!m.matches()) { | ||
throw new IllegalArgumentException("Incorrect url"); | ||
} | ||
String database = m.group(2); | ||
if (database == null) { | ||
database = ""; | ||
} | ||
String[] hosts = m.group(1).split(","); | ||
final List<String> result = new ArrayList<String>(hosts.length); | ||
for (final String host : hosts) { | ||
result.add(JDBC_CLICKHOUSE_PREFIX + "//" + host + database); | ||
} | ||
|
||
String JDBC_PREFIX = "jdbc:"; | ||
String strUri = result.get(0).substring(JDBC_PREFIX.length()); | ||
URI uri = new URI(strUri); | ||
System.out.println(uri.getHost()); | ||
} | ||
} |