Skip to content

Commit

Permalink
Merge pull request #1883 from ClickHouse/error_handling_tests
Browse files Browse the repository at this point in the history
Error handling tests
  • Loading branch information
chernser authored Oct 24, 2024
2 parents a0ab761 + 6429d6f commit d994f91
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,25 @@ public static Map<String, Serializable> toRequestSettings(Map<String, Object> se
Map<String, Serializable> requestSettings = new HashMap<>();

for (Map.Entry<String, Object> entry : settings.entrySet()) {
if (REQUEST_OPTIONS.get(entry.getKey()) != null) {
String key = entry.getKey();
boolean isServerSetting = key.startsWith("clickhouse_setting_");
if (!isServerSetting && REQUEST_OPTIONS.get(key) != null) {
// This definitely is a request option
continue;
}

if (isServerSetting) {
key = key.substring("clickhouse_setting_".length());
}

if (entry.getValue() instanceof Map<?,?>) {
Map<String, String> map = (Map<String, String>) entry.getValue();
requestSettings.put(entry.getKey(), convertMapToStringValue(map));
requestSettings.put(key, convertMapToStringValue(map));
} else if (entry.getValue() instanceof Collection<?>) {
Collection<?> collection = (Collection<?>) entry.getValue();
requestSettings.put(entry.getKey(), convertCollectionToStringValue(collection));
requestSettings.put(key, convertCollectionToStringValue(collection));
} else {
requestSettings.put(entry.getKey(), (Serializable) entry.getValue());
requestSettings.put(key, (Serializable) entry.getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,30 @@ public void testSSLAuthentication_invalidConfig() throws Exception {
Assert.assertTrue(e.getMessage().startsWith("Only one of password, access token or SSL authentication"));
}
}

@Test(groups = { "integration" })
public void testErrorWithSendProgressHeaders() throws Exception {
ClickHouseNode server = getServer(ClickHouseProtocol.HTTP);
try (Client client = new Client.Builder().addEndpoint(Protocol.HTTP, "localhost",server.getPort(), false)
.setUsername("default")
.setPassword("")
.useNewImplementation(false)
.build()) {

try (CommandResponse resp = client.execute("DROP TABLE IF EXISTS test_omm_table").get()) {
}
try (CommandResponse resp = client.execute("CREATE TABLE test_omm_table ( val String) Engine = MergeTree ORDER BY () ").get()) {
}

QuerySettings settings = new QuerySettings()
.serverSetting("send_progress_in_http_headers", "1")
.serverSetting("max_memory_usage", "54M");

try (QueryResponse resp = client.query("INSERT INTO test_omm_table SELECT randomString(16) FROM numbers(300000000)", settings).get()) {

} catch (ServerException e) {
Assert.assertEquals(e.getCode(), 241);
}
}
}
}

0 comments on commit d994f91

Please sign in to comment.