Skip to content

Commit dbf5b5c

Browse files
author
Paultagoras
committed
Removed old defaults and replaced new ones
1 parent f01a30e commit dbf5b5c

File tree

2 files changed

+47
-41
lines changed

2 files changed

+47
-41
lines changed

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -255,47 +255,6 @@ public static class Builder {
255255
public Builder() {
256256
this.endpoints = new HashSet<>();
257257
this.configuration = new HashMap<String, String>();
258-
// TODO: set defaults configuration values
259-
this.setConnectTimeout(30, SECONDS)
260-
.setSocketTimeout(2, SECONDS)
261-
.setSocketRcvbuf(804800)
262-
.setSocketSndbuf(804800)
263-
.compressServerResponse(true)
264-
.compressClientRequest(false);
265-
}
266-
267-
/**
268-
* Builds a client object with the provided configuration through URL parameters.
269-
* (e.g. http://localhost:8123/someDatabase?user=default)
270-
* @param urlString - URL formatted string with protocol, host, port, and client configuration settings.
271-
* @return Client - a client object
272-
*/
273-
public Builder fromUrl(String urlString) {
274-
try {
275-
URL url = new URL(urlString);
276-
Map<String, String> urlProperties = HttpAPIClientHelper.parseUrlParameters(url);
277-
278-
// Add the endpoint
279-
boolean secure = url.getProtocol().equalsIgnoreCase("https");
280-
int port = url.getPort();
281-
if (port == -1) {
282-
port = secure ? ClickHouseHttpProto.DEFAULT_HTTPS_PORT : ClickHouseHttpProto.DEFAULT_HTTP_PORT;
283-
}
284-
this.addEndpoint(Protocol.HTTP, url.getHost(), port, secure);
285-
286-
for (ClientConfigProperties properties: ClientConfigProperties.values()) {
287-
String value = urlProperties.get(properties.getKey());
288-
if (value != null) {
289-
this.configuration.put(properties.getKey(), value);
290-
}
291-
}
292-
293-
// Set the database
294-
} catch (java.net.MalformedURLException e) {
295-
throw new IllegalArgumentException("Configuration via URL should be done with a valid URL string", e);
296-
}
297-
298-
return this;
299258
}
300259

301260
/**
@@ -1076,6 +1035,7 @@ public Client build() {
10761035
* Default size for a buffers used in networking.
10771036
*/
10781037
public static final int DEFAULT_BUFFER_SIZE = 8192;
1038+
public static final int DEFAULT_SOCKET_BUFFER_SIZE = 804800;
10791039

10801040
private void setDefaults() {
10811041

@@ -1169,6 +1129,18 @@ private void setDefaults() {
11691129
if (!configuration.containsKey(ClientConfigProperties.APP_COMPRESSED_DATA.getKey())) {
11701130
appCompressedData(false);
11711131
}
1132+
1133+
if (!configuration.containsKey(ClientConfigProperties.SOCKET_OPERATION_TIMEOUT.getKey())) {
1134+
setSocketTimeout(0, SECONDS);
1135+
}
1136+
1137+
if (!configuration.containsKey(ClientConfigProperties.SOCKET_RCVBUF_OPT.getKey())) {
1138+
setSocketRcvbuf(DEFAULT_SOCKET_BUFFER_SIZE);
1139+
}
1140+
1141+
if (!configuration.containsKey(ClientConfigProperties.SOCKET_SNDBUF_OPT.getKey())) {
1142+
setSocketSndbuf(DEFAULT_SOCKET_BUFFER_SIZE);
1143+
}
11721144
}
11731145
}
11741146

client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import java.io.ByteArrayInputStream;
4141
import java.net.Socket;
42+
import java.net.SocketTimeoutException;
4243
import java.nio.ByteBuffer;
4344
import java.nio.charset.StandardCharsets;
4445
import java.time.temporal.ChronoUnit;
@@ -52,6 +53,7 @@
5253
import java.util.concurrent.CompletableFuture;
5354
import java.util.concurrent.ExecutionException;
5455
import java.util.concurrent.TimeUnit;
56+
import java.util.concurrent.TimeoutException;
5557
import java.util.concurrent.atomic.AtomicInteger;
5658
import java.util.regex.Pattern;
5759
import java.util.function.Supplier;
@@ -1025,6 +1027,38 @@ public void testJWTWithCloud() throws Exception {
10251027
}
10261028
}
10271029

1030+
@Test(groups = { "integration" })
1031+
public void testWithDefaultTimeouts() {
1032+
if (isCloud()) {
1033+
return; // mocked server
1034+
}
1035+
1036+
int proxyPort = new Random().nextInt(1000) + 10000;
1037+
WireMockServer proxy = new WireMockServer(WireMockConfiguration
1038+
.options().port(proxyPort)
1039+
.notifier(new Slf4jNotifier(true)));
1040+
proxy.start();
1041+
proxy.addStubMapping(WireMock.post(WireMock.anyUrl())
1042+
.willReturn(WireMock.aResponse().withFixedDelay(5000)
1043+
.withStatus(HttpStatus.SC_OK)
1044+
.withHeader("X-ClickHouse-Summary", "{ \"read_bytes\": \"10\", \"read_rows\": \"1\"}")).build());
1045+
1046+
try (Client client = new Client.Builder().addEndpoint(Protocol.HTTP, "localhost", proxyPort, false)
1047+
.setUsername("default")
1048+
.setPassword("")
1049+
.useNewImplementation(true)
1050+
.build()) {
1051+
int startTime = (int) System.currentTimeMillis();
1052+
try {
1053+
client.query("SELECT 1").get();
1054+
} catch (Exception e) {
1055+
Assert.fail("Elapsed Time: " + (System.currentTimeMillis() - startTime), e);
1056+
}
1057+
} finally {
1058+
proxy.stop();
1059+
}
1060+
}
1061+
10281062
protected Client.Builder newClient() {
10291063
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
10301064
boolean isSecure = isCloud();

0 commit comments

Comments
 (0)