Skip to content

Commit a886510

Browse files
authored
Merge pull request #370 from databendlabs/feat/drop-stage-test
feat: add drop stage test
2 parents 1d15179 + ab5252a commit a886510

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendPresignClientV1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ private void uploadFromStream(InputStream inputStream, String stageName, String
124124
private void uploadFromStream(InputStream inputStream, Headers headers, String presignedUrl, long fileSize)
125125
throws IOException
126126
{
127-
logger.info("Starting upload: size=" + fileSize + " bytes, url=" + presignedUrl);
127+
logger.fine("Starting upload: size=" + fileSize + " bytes, url=" + presignedUrl);
128128
long startTime = System.currentTimeMillis();
129129
try {
130130
Request r = putRequest(headers, presignedUrl, inputStream, fileSize);
131131
executeInternal(r, true);
132-
logger.info("Upload completed in " + (System.currentTimeMillis() - startTime) + "ms");
132+
logger.fine("Upload completed in " + (System.currentTimeMillis() - startTime) + "ms");
133133
}
134134
catch (IOException e) {
135135
logger.severe("Upload failed after " + (System.currentTimeMillis() - startTime) + "ms: " + e.getMessage());

databend-jdbc/src/test/java/com/databend/jdbc/TestPrepareStatement.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import java.sql.Statement;
1717
import java.sql.Timestamp;
1818
import java.sql.Types;
19+
import java.util.HashSet;
20+
import java.util.Set;
21+
import java.util.UUID;
1922
import java.util.Arrays;
2023
import java.util.Properties;
2124
import java.util.TimeZone;
@@ -431,6 +434,52 @@ public void testAllPreparedStatement() throws SQLException {
431434
}
432435
}
433436

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+
434483
@Test(groups = "IT")
435484
public void shouldBuildStageAttachmentWithFileFormatOptions() throws SQLException {
436485
Connection conn = Utils.createConnection();

0 commit comments

Comments
 (0)