|
5 | 5 | import java.io.IOException;
|
6 | 6 | import java.io.InputStream;
|
7 | 7 | import java.io.InputStreamReader;
|
| 8 | +import java.io.UncheckedIOException; |
8 | 9 | import java.math.BigDecimal;
|
9 | 10 | import java.math.BigInteger;
|
10 | 11 | import java.net.Inet4Address;
|
@@ -1256,4 +1257,50 @@ public void testTempTable() throws Exception {
|
1256 | 1257 | Assert.assertEquals(count, 2);
|
1257 | 1258 | }
|
1258 | 1259 | }
|
| 1260 | + |
| 1261 | + @Test(groups = "integration") |
| 1262 | + public void testErrorDuringInsert() throws Exception { |
| 1263 | + ClickHouseNode server = getServer(); |
| 1264 | + ClickHouseClient.send(server, "drop table if exists error_during_insert", |
| 1265 | + "create table error_during_insert(n UInt64, flag UInt8)engine=Null").get(); |
| 1266 | + boolean success = true; |
| 1267 | + try (ClickHouseClient client = getClient(); |
| 1268 | + ClickHouseResponse resp = client.connect(getServer()).write() |
| 1269 | + .format(ClickHouseFormat.RowBinary) |
| 1270 | + .query("insert into error_during_insert select number, throwIf(number>=100000000) from numbers(500000000)") |
| 1271 | + .executeAndWait()) { |
| 1272 | + for (ClickHouseRecord r : resp.records()) { |
| 1273 | + Assert.fail("Should have no record"); |
| 1274 | + } |
| 1275 | + Assert.fail("Insert should be aborted"); |
| 1276 | + } catch (ClickHouseException e) { |
| 1277 | + Assert.assertEquals(e.getErrorCode(), 395); |
| 1278 | + Assert.assertTrue(e.getCause() instanceof IOException, "Should end up with IOException"); |
| 1279 | + success = false; |
| 1280 | + } |
| 1281 | + |
| 1282 | + Assert.assertFalse(success, "Should fail due insert error"); |
| 1283 | + } |
| 1284 | + |
| 1285 | + @Test(groups = "integration") |
| 1286 | + public void testErrorDuringQuery() throws Exception { |
| 1287 | + String query = "select number, throwIf(number>=100000000) from numbers(500000000)"; |
| 1288 | + long count = 0L; |
| 1289 | + try (ClickHouseClient client = getClient(); |
| 1290 | + ClickHouseResponse resp = client.connect(getServer()) |
| 1291 | + .format(ClickHouseFormat.RowBinaryWithNamesAndTypes).query(query).executeAndWait()) { |
| 1292 | + for (ClickHouseRecord r : resp.records()) { |
| 1293 | + // does not work which may relate to deserialization failure |
| 1294 | + // java.lang.AssertionError: expected [99764115] but found [4121673519155408707] |
| 1295 | + // Assert.assertEquals(r.getValue(0).asLong(), count++); |
| 1296 | + Assert.assertTrue((count = r.getValue(0).asLong()) >= 0); |
| 1297 | + } |
| 1298 | + Assert.fail("Query should be terminated before all rows returned"); |
| 1299 | + } catch (UncheckedIOException e) { |
| 1300 | + Assert.assertTrue(e.getCause() instanceof IOException, |
| 1301 | + "Should end up with IOException due to deserialization failure"); |
| 1302 | + } |
| 1303 | + |
| 1304 | + Assert.assertNotEquals(count, 0L, "Should have read at least one record"); |
| 1305 | + } |
1259 | 1306 | }
|
0 commit comments