Skip to content

Commit be0e9f6

Browse files
committed
fixed tests after changing exceptions
1 parent cdf11ce commit be0e9f6

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,8 @@ private TableSchema getTableSchemaImpl(String describeQuery, String name, String
18071807
throw new ClientException("Operation has likely timed out after " + getOperationTimeout() + " seconds.", e);
18081808
} catch (ExecutionException e) {
18091809
throw new ClientException("Failed to get table schema", e.getCause());
1810+
} catch (ServerException e) {
1811+
throw e;
18101812
} catch (Exception e) {
18111813
throw new ClientException("Failed to get table schema", e);
18121814
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,11 @@ public void testServerErrorHandling(ClickHouseFormat format) {
321321
try (QueryResponse response =
322322
client.query("SELECT invalid;statement", querySettings).get(1, TimeUnit.SECONDS)) {
323323
Assert.fail("Expected exception");
324-
} catch (ClientException e) {
324+
} catch (ServerException e) {
325325
e.printStackTrace();
326-
ServerException serverException = (ServerException) e.getCause();
327-
Assert.assertEquals(serverException.getCode(), 62);
328-
Assert.assertTrue(serverException.getMessage().startsWith("Code: 62. DB::Exception: Syntax error (Multi-statements are not allowed): failed at position 15 (end of query)"),
329-
"Unexpected error message: " + serverException.getMessage());
326+
Assert.assertEquals(e.getCode(), 62);
327+
Assert.assertTrue(e.getMessage().startsWith("Code: 62. DB::Exception: Syntax error (Multi-statements are not allowed): failed at position 15 (end of query)"),
328+
"Unexpected error message: " + e.getMessage());
330329
}
331330
} catch (Exception e) {
332331
e.printStackTrace();

client-v2/src/test/java/com/clickhouse/client/command/CommandTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.clickhouse.client.ClickHouseProtocol;
66
import com.clickhouse.client.api.Client;
77
import com.clickhouse.client.api.ClientException;
8+
import com.clickhouse.client.api.ServerException;
89
import com.clickhouse.client.api.command.CommandResponse;
910
import com.clickhouse.client.api.enums.Protocol;
1011
import org.testng.Assert;
@@ -45,8 +46,10 @@ public void testCreateTable() throws Exception {
4546
public void testInvalidCommandExecution() throws Exception {
4647
try {
4748
client.execute("ALTER TABLE non_existing_table ADD COLUMN id2 UInt32").get(10, TimeUnit.SECONDS);
49+
} catch (ServerException e) {
50+
Assert.assertEquals(e.getCode(), 60);
4851
} catch (ExecutionException e) {
49-
Assert.assertTrue(e.getCause() instanceof ClientException);
52+
Assert.assertTrue(e.getCause() instanceof ServerException);
5053
} catch (ClientException e) {
5154
// expected
5255
}

client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,10 @@ public void testQueryExceptionHandling() throws Exception {
550550
try {
551551
client.queryRecords("SELECT * FROM unknown_table").get(3, TimeUnit.SECONDS);
552552
Assert.fail("expected exception");
553+
} catch (ServerException e) {
554+
Assert.assertTrue(e.getMessage().contains("Unknown table"));
553555
} catch (ExecutionException e) {
554-
Assert.assertTrue(e.getCause() instanceof ClientException);
556+
Assert.assertTrue(e.getCause() instanceof ServerException);
555557
} catch (ClientException e) {
556558
// expected
557559
}

0 commit comments

Comments
 (0)