-
Notifications
You must be signed in to change notification settings - Fork 561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[client-v2] Added options for additional headers and server settings #1841
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package com.clickhouse.client; | ||
|
||
import com.clickhouse.config.ClickHouseOption; | ||
import org.testng.Assert; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import java.net.URI; | ||
|
@@ -438,4 +440,34 @@ public void testToUri() { | |
.toUri().toString(), | ||
"http://server1.dc1:8123/db1?async=false&auto_discovery=true#apj,r1s1"); | ||
} | ||
|
||
@Test(groups = { "unit" }, dataProvider = "testPropertyWithValueList_endpoints") | ||
public void testPropertyWithValueList(String endpoints, int numOfNodes, String[] expectedBaseUris) { | ||
ClickHouseNodes node = ClickHouseNodes.of(endpoints); | ||
Assert.assertEquals(node.nodes.size(), numOfNodes, "Number of nodes does not match"); | ||
|
||
int i = 0; | ||
for (ClickHouseNode n : node.nodes) { | ||
Assert.assertEquals(n.config.getDatabase(), "my_db"); | ||
Assert.assertEquals(expectedBaseUris[i++], n.getBaseUri()); | ||
String customSettings = (String)n.config.getOption(ClickHouseClientOption.CUSTOM_SETTINGS); | ||
String configSettings = (String) n.config.getOption(ClickHouseClientOption.CUSTOM_SETTINGS); | ||
|
||
Arrays.asList(customSettings, configSettings).forEach((settings) -> { | ||
Map<String, String> settingsMap = ClickHouseOption.toKeyValuePairs(settings); | ||
Assert.assertEquals(settingsMap.get("param1"), "value1"); | ||
Assert.assertEquals(settingsMap.get("param2"), "value2"); | ||
}); | ||
} | ||
} | ||
|
||
@DataProvider(name = "testPropertyWithValueList_endpoints") | ||
public static Object[][] endpoints() { | ||
return new Object[][] { | ||
{ "http://server1:9090/my_db?custom_settings=param1=value1,param2=value2", 1, new String[]{"http://server1:9090/"} }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a valid URL? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is not exactly URL - it is client endpoints spec. It may have multiple hosts for example. |
||
{ "http://server1/my_db?custom_settings=param1=value1,param2=value2", 1, new String[]{"http://server1:8123/"} }, | ||
{ "http://server1:9090,server2/my_db?custom_settings=param1=value1,param2=value2", 2, new String[]{"http://server1:9090/", "http://server2:8123/"} }, | ||
{ "http://server1,server2:9090/my_db?custom_settings=param1=value1,param2=value2", 2, new String[]{"http://server1:8123/", "http://server2:9090/"} } | ||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.clickhouse.client.api; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* All known client settings at current version. | ||
* | ||
*/ | ||
public class ClientSettings { | ||
|
||
public static final String HTTP_HEADER_PREFIX = "http_header_"; | ||
|
||
public static final String SERVER_SETTING_PREFIX = "clickhouse_setting_"; | ||
|
||
public static String commaSeparated(Collection<?> values) { | ||
StringBuilder sb = new StringBuilder(); | ||
for (Object value : values) { | ||
sb.append(value.toString().replaceAll(",", "\\,")).append(","); | ||
} | ||
sb.setLength(sb.length() - 1); | ||
return sb.toString(); | ||
} | ||
|
||
public static List<String> valuesFromCommaSeparated(String value) { | ||
return Arrays.stream(value.split(",")).map(s -> s.replaceAll("\\\\,", ",")) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not fully understand if we are planning to remove this module.
why we are changing
ClickHouseNodes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is base module for whole client. I'm changing it to fix a bug in it.
We will use this module for a while because it contains some base classes like ClickhouseClientOptions