Skip to content

Commit d1fc0cf

Browse files
committed
Show detailed error message when checking error code
1 parent e3e27c6 commit d1fc0cf

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

clickhouse-client/src/test/java/com/clickhouse/client/ClientIntegrationTest.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,11 +1761,11 @@ public void testErrorDuringInsert() throws ClickHouseException {
17611761
Assert.fail("Insert should be aborted");
17621762
} catch (UncheckedIOException e) {
17631763
ClickHouseException ex = ClickHouseException.of(e, server);
1764-
Assert.assertEquals(ex.getErrorCode(), 395);
1764+
Assert.assertEquals(ex.getErrorCode(), 395, "Expected error code 395 but we got: " + ex.getMessage());
17651765
Assert.assertTrue(ex.getCause() instanceof IOException, "Should end up with IOException");
17661766
success = false;
17671767
} catch (ClickHouseException e) {
1768-
Assert.assertEquals(e.getErrorCode(), 395);
1768+
Assert.assertEquals(e.getErrorCode(), 395, "Expected error code 395 but we got: " + e.getMessage());
17691769
Assert.assertTrue(e.getCause() instanceof IOException, "Should end up with IOException");
17701770
success = false;
17711771
}
@@ -1838,7 +1838,8 @@ public void testSessionLock() throws ClickHouseException {
18381838
try (ClickHouseResponse resp = req2.executeAndWait()) {
18391839
Assert.fail("Should fail due to session is locked by previous query");
18401840
} catch (ClickHouseException e) {
1841-
Assert.assertEquals(e.getErrorCode(), ClickHouseException.ERROR_SESSION_IS_LOCKED);
1841+
Assert.assertEquals(e.getErrorCode(), ClickHouseException.ERROR_SESSION_IS_LOCKED,
1842+
"Expected error code 373 but we got: " + e.getMessage());
18421843
}
18431844
new Thread(() -> {
18441845
try {
@@ -1880,7 +1881,8 @@ public void testAbortTransaction() throws ClickHouseException {
18801881
checkRowCount(txRequest, tableName, 0);
18811882
Assert.fail("Should fail as the transaction is invalid");
18821883
} catch (ClickHouseException e) {
1883-
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION);
1884+
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION,
1885+
"Expected error code 649 but we got: " + e.getMessage());
18841886
}
18851887
}
18861888
}
@@ -2098,7 +2100,8 @@ public void testTransactionSnapshot() throws ClickHouseException {
20982100
try {
20992101
req2.getTransaction().snapshot(5);
21002102
} catch (ClickHouseTransactionException e) {
2101-
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION);
2103+
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION,
2104+
"Expected error code 649 but we got: " + e.getMessage());
21022105
}
21032106

21042107
req1.getTransaction().commit();
@@ -2108,7 +2111,8 @@ public void testTransactionSnapshot() throws ClickHouseException {
21082111
try {
21092112
req1.getTransaction().snapshot(5);
21102113
} catch (ClickHouseTransactionException e) {
2111-
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION);
2114+
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION,
2115+
"Expected error code 649 but we got: " + e.getMessage());
21122116
}
21132117
}
21142118
}
@@ -2142,31 +2146,35 @@ public void testTransactionTimeout() throws ClickHouseException {
21422146
Assert.fail("Query should fail due to session timed out");
21432147
} catch (ClickHouseException e) {
21442148
// session not found(since it's timed out)
2145-
Assert.assertEquals(e.getErrorCode(), ClickHouseException.ERROR_SESSION_NOT_FOUND);
2149+
Assert.assertEquals(e.getErrorCode(), ClickHouseException.ERROR_SESSION_NOT_FOUND,
2150+
"Expected error code 372 but we got: " + e.getMessage());
21462151
}
21472152
Assert.assertEquals(tx.getState(), ClickHouseTransaction.ACTIVE);
21482153

21492154
try {
21502155
tx.commit();
21512156
Assert.fail("Should fail to commit due to session timed out");
21522157
} catch (ClickHouseTransactionException e) {
2153-
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION);
2158+
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION,
2159+
"Expected error code 649 but we got: " + e.getMessage());
21542160
}
21552161
Assert.assertEquals(tx.getState(), ClickHouseTransaction.FAILED);
21562162

21572163
try {
21582164
tx.rollback();
21592165
Assert.fail("Should fail to roll back due to session timed out");
21602166
} catch (ClickHouseTransactionException e) {
2161-
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION);
2167+
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION,
2168+
"Expected error code 649 but we got: " + e.getMessage());
21622169
}
21632170
Assert.assertEquals(tx.getState(), ClickHouseTransaction.FAILED);
21642171

21652172
try {
21662173
tx.begin();
21672174
Assert.fail("Should fail to restart due to session timed out");
21682175
} catch (ClickHouseTransactionException e) {
2169-
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION);
2176+
Assert.assertEquals(e.getErrorCode(), ClickHouseTransactionException.ERROR_INVALID_TRANSACTION,
2177+
"Expected error code 649 but we got: " + e.getMessage());
21702178
}
21712179
Assert.assertEquals(tx.getState(), ClickHouseTransaction.FAILED);
21722180

@@ -2191,7 +2199,8 @@ public void testTransactionTimeout() throws ClickHouseException {
21912199
checkRowCount(request, tableName, 3);
21922200
Assert.fail("Should fail to query due to session timed out");
21932201
} catch (ClickHouseException e) {
2194-
Assert.assertEquals(e.getErrorCode(), ClickHouseException.ERROR_SESSION_NOT_FOUND);
2202+
Assert.assertEquals(e.getErrorCode(), ClickHouseException.ERROR_SESSION_NOT_FOUND,
2203+
"Expected error code 372 but we got: " + e.getMessage());
21952204
}
21962205
Assert.assertEquals(request.getTransaction().getState(), ClickHouseTransaction.ACTIVE);
21972206
}

clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseConnectionTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void testAutoCommitMode() throws SQLException {
8080
+ " from numbers(100000)");
8181
} catch (SQLException e) {
8282
if (i % 3 == 0 || i % 5 == 0) {
83-
Assert.assertEquals(e.getErrorCode(), 395);
83+
Assert.assertEquals(e.getErrorCode(), 395, "Expected error code 395 but we got: " + e.getMessage());
8484
} else {
8585
Assert.fail("Should not have exception");
8686
}
@@ -157,7 +157,7 @@ public void testReadOnly() throws SQLException {
157157
exp = e;
158158
}
159159
Assert.assertNotNull(exp, "Should fail with SQL exception");
160-
Assert.assertEquals(exp.getErrorCode(), 164);
160+
Assert.assertEquals(exp.getErrorCode(), 164, "Expected error code 164 but we got: " + exp.getMessage());
161161
}
162162

163163
conn.setReadOnly(false);
@@ -181,7 +181,7 @@ public void testReadOnly() throws SQLException {
181181
exp = e;
182182
}
183183
Assert.assertNotNull(exp, "Should fail with SQL exception");
184-
Assert.assertEquals(exp.getErrorCode(), 164);
184+
Assert.assertEquals(exp.getErrorCode(), 164, "Expected error code 164 but we got: " + exp.getMessage());
185185

186186
exp = null;
187187
try {
@@ -191,7 +191,7 @@ public void testReadOnly() throws SQLException {
191191
exp = e;
192192
}
193193
Assert.assertNotNull(exp, "Should fail with SQL exception");
194-
Assert.assertEquals(exp.getErrorCode(), 164);
194+
Assert.assertEquals(exp.getErrorCode(), 164, "Expected error code 164 but we got: " + exp.getMessage());
195195
}
196196

197197
props.setProperty("user", "readonly2");
@@ -209,7 +209,7 @@ public void testReadOnly() throws SQLException {
209209
exp = e;
210210
}
211211
Assert.assertNotNull(exp, "Should fail with SQL exception");
212-
Assert.assertEquals(exp.getErrorCode(), 164);
212+
Assert.assertEquals(exp.getErrorCode(), 164, "Expected error code 164 but we got: " + exp.getMessage());
213213

214214
conn.setReadOnly(true);
215215
Assert.assertTrue(conn.isReadOnly(), "Connection should be readonly");
@@ -233,7 +233,7 @@ public void testReadOnly() throws SQLException {
233233
exp = e;
234234
}
235235
Assert.assertNotNull(exp, "Should fail with SQL exception");
236-
Assert.assertEquals(exp.getErrorCode(), 164);
236+
Assert.assertEquals(exp.getErrorCode(), 164, "Expected error code 164 but we got: " + exp.getMessage());
237237
}
238238
}
239239

0 commit comments

Comments
 (0)