|
16 | 16 | import java.sql.Statement; |
17 | 17 | import java.sql.Timestamp; |
18 | 18 | import java.sql.Types; |
| 19 | +import java.util.HashSet; |
| 20 | +import java.util.Set; |
| 21 | +import java.util.UUID; |
19 | 22 | import java.util.Arrays; |
20 | 23 | import java.util.Properties; |
21 | 24 | import java.util.TimeZone; |
@@ -431,6 +434,52 @@ public void testAllPreparedStatement() throws SQLException { |
431 | 434 | } |
432 | 435 | } |
433 | 436 |
|
| 437 | + @Test(groups = "IT") |
| 438 | + public void TestStageFileRemovedAfterBatchInsert() throws SQLException { |
| 439 | + String dbName = ("stage_cleanup_" + UUID.randomUUID()).replace("-", ""); |
| 440 | + try (Connection c = Utils.createConnection(); |
| 441 | + Statement s = c.createStatement()) { |
| 442 | + c.setAutoCommit(false); |
| 443 | + s.execute("create or replace database " + dbName); |
| 444 | + s.execute("use " + dbName); |
| 445 | + s.execute("create or replace table t_stage_cleanup(a int, b string)"); |
| 446 | + |
| 447 | + Set<String> before = new HashSet<>(); |
| 448 | + try (ResultSet rs = s.executeQuery("LIST @~/")) { |
| 449 | + while (rs.next()) { |
| 450 | + before.add(rs.getString(1)); |
| 451 | + } |
| 452 | + } |
| 453 | + |
| 454 | + try (PreparedStatement ps = c.prepareStatement("insert into t_stage_cleanup values")) { |
| 455 | + ps.setInt(1, 1); |
| 456 | + ps.setString(2, "hello"); |
| 457 | + ps.addBatch(); |
| 458 | + int[] counts = ps.executeBatch(); |
| 459 | + Assert.assertEquals(counts, new int[] {1}); |
| 460 | + } |
| 461 | + |
| 462 | + try (ResultSet rs = s.executeQuery("SELECT a, b FROM t_stage_cleanup")) { |
| 463 | + Assert.assertTrue(rs.next()); |
| 464 | + Assert.assertEquals(rs.getInt(1), 1); |
| 465 | + Assert.assertEquals(rs.getString(2), "hello"); |
| 466 | + Assert.assertFalse(rs.next()); |
| 467 | + } |
| 468 | + |
| 469 | + Set<String> after = new HashSet<>(); |
| 470 | + try (ResultSet rs = s.executeQuery("LIST @~/")) { |
| 471 | + while (rs.next()) { |
| 472 | + after.add(rs.getString(1)); |
| 473 | + } |
| 474 | + } |
| 475 | + Set<String> diff = new HashSet<>(after); |
| 476 | + diff.removeAll(before); |
| 477 | + if (!diff.isEmpty()) { |
| 478 | + Assert.fail("Stage has unexpected leftover entries: " + diff); |
| 479 | + } |
| 480 | + } |
| 481 | + } |
| 482 | + |
434 | 483 | @Test(groups = "IT") |
435 | 484 | public void shouldBuildStageAttachmentWithFileFormatOptions() throws SQLException { |
436 | 485 | Connection conn = Utils.createConnection(); |
|
0 commit comments