|
14 | 14 | import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader; |
15 | 15 | import com.clickhouse.client.api.enums.Protocol; |
16 | 16 | import com.clickhouse.client.api.enums.ProxyType; |
| 17 | +import com.clickhouse.client.api.http.ClickHouseHttpProto; |
17 | 18 | import com.clickhouse.client.api.insert.InsertResponse; |
18 | 19 | import com.clickhouse.client.api.insert.InsertSettings; |
19 | 20 | import com.clickhouse.client.api.internal.DataTypeConverter; |
@@ -2084,6 +2085,55 @@ public void testConcurrentTokenChange() throws Exception { |
2084 | 2085 | } |
2085 | 2086 | } |
2086 | 2087 |
|
| 2088 | + @Test(groups = {"integration"}, dataProvider = "testErrorWhenResponseIsOk_Dp") |
| 2089 | + public void testErrorWhenResponseIsOk(boolean hasMsg) throws Exception { |
| 2090 | + WireMockServer mockServer = new WireMockServer(WireMockConfiguration |
| 2091 | + .options().port(9090).notifier(new ConsoleNotifier(false))); |
| 2092 | + mockServer.start(); |
| 2093 | + |
| 2094 | + try (Client client = new Client.Builder().addEndpoint(Protocol.HTTP, "localhost", mockServer.port(), false) |
| 2095 | + .setUsername("default") |
| 2096 | + .setPassword(ClickHouseServerForTest.getPassword()) |
| 2097 | + .build()) { |
| 2098 | + |
| 2099 | + final String errorMsg = hasMsg ? "Code: 60. DB::Exception: Unknown table expression identifier" : ""; |
| 2100 | + mockServer.addStubMapping(WireMock.post(WireMock.anyUrl()) |
| 2101 | + .willReturn(WireMock.aResponse() |
| 2102 | + .withStatus(HttpStatus.SC_OK) |
| 2103 | + .withHeader(ClickHouseHttpProto.HEADER_EXCEPTION_CODE, "60") |
| 2104 | + .withBody(errorMsg)) |
| 2105 | + .build()); |
| 2106 | + |
| 2107 | + |
| 2108 | + try (QueryResponse response = client.query("SELECT * FROM not_existing_table").get(1, TimeUnit.SECONDS)) { |
| 2109 | + Assert.fail("Expected exception"); |
| 2110 | + } catch (Exception e) { |
| 2111 | + ServerException se = null; |
| 2112 | + if (e instanceof ServerException) { |
| 2113 | + se = (ServerException) e; |
| 2114 | + } else if (e.getCause() instanceof ServerException) { |
| 2115 | + se = (ServerException) e.getCause(); |
| 2116 | + } else { |
| 2117 | + Assert.fail("Unexpected exception type", e); |
| 2118 | + } |
| 2119 | + |
| 2120 | + Assert.assertEquals(se.getCode(), 60); |
| 2121 | + if (hasMsg) { |
| 2122 | + Assert.assertEquals(se.getMessage().substring(0, errorMsg.length()), errorMsg); |
| 2123 | + } else { |
| 2124 | + Assert.assertTrue(se.getMessage().contains("<Unreadable error message>"), "Error message was " + se.getMessage()); |
| 2125 | + } |
| 2126 | + } |
| 2127 | + } finally { |
| 2128 | + mockServer.stop(); |
| 2129 | + } |
| 2130 | + } |
| 2131 | + |
| 2132 | + @DataProvider |
| 2133 | + public static Object[][] testErrorWhenResponseIsOk_Dp() { |
| 2134 | + return new Object[][]{{true}, {false}}; |
| 2135 | + } |
| 2136 | + |
2087 | 2137 | protected Client.Builder newClient() { |
2088 | 2138 | ClickHouseNode node = getServer(ClickHouseProtocol.HTTP); |
2089 | 2139 | boolean isSecure = isCloud(); |
|
0 commit comments