From 9843769ac0b872430ca7cb3cad7212949a13de41 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 3 Nov 2022 14:26:04 +0100 Subject: [PATCH] [misc] test suite stability improvement --- .../jdbc/integration/UpdateResultSetTest.java | 147 +++++++++--------- 1 file changed, 76 insertions(+), 71 deletions(-) diff --git a/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java b/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java index b7e3b9cc8..b4bb025a0 100644 --- a/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java @@ -609,78 +609,83 @@ public void updateBlobClob() throws SQLException, IOException { Statement stmt = sharedConn.createStatement(); stmt.execute("DROP TABLE IF EXISTS updateBlob"); stmt.execute("CREATE TABLE updateBlob(id int not null primary key, strm blob)"); - PreparedStatement prep = - sharedConn.prepareStatement("insert into updateBlob (id, strm) values (?,?)"); - byte[] theBlob = {1, 2, 3, 4, 5, 6}; - InputStream stream = new ByteArrayInputStream(theBlob); - - prep.setInt(1, 1); - prep.setBlob(2, stream); - prep.execute(); - - byte[] updatedBlob = "abcdef".getBytes(StandardCharsets.UTF_8); - - try (PreparedStatement preparedStatement = - sharedConn.prepareStatement( - "select * from updateBlob", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { - ResultSet rs = preparedStatement.executeQuery(); - assertTrue(rs.next()); - - rs.updateBlob(2, new ByteArrayInputStream(updatedBlob)); - rs.updateRow(); - checkResult(rs, updatedBlob); - - rs.updateBlob("strm", new ByteArrayInputStream(updatedBlob)); - rs.updateRow(); - checkResult(rs, updatedBlob); - - rs.updateBlob(2, new ByteArrayInputStream(updatedBlob), 20L); - rs.updateRow(); - checkResult(rs, updatedBlob); - - rs.updateBlob("strm", new ByteArrayInputStream(updatedBlob), 20L); - rs.updateRow(); - checkResult(rs, updatedBlob); - - rs.updateClob(2, new StringReader("abcdef")); - rs.updateRow(); - checkResult(rs, updatedBlob); - - rs.updateClob("strm", new StringReader("abcdef")); - rs.updateRow(); - checkResult(rs, updatedBlob); - - rs.updateClob(2, new StringReader("abcdef"), 20L); - rs.updateRow(); - checkResult(rs, updatedBlob); - - rs.updateClob("strm", new StringReader("abcdef"), 20L); - rs.updateRow(); - checkResult(rs, updatedBlob); - - rs.updateNClob(2, new StringReader("abcdef")); - rs.updateRow(); - checkResult(rs, updatedBlob); - - rs.updateNClob("strm", new StringReader("abcdef")); - rs.updateRow(); - checkResult(rs, updatedBlob); - - rs.updateNClob(2, new StringReader("abcdef"), 20L); - rs.updateRow(); - checkResult(rs, updatedBlob); - - rs.updateNClob("strm", new StringReader("abcdef"), 20L); - rs.updateRow(); - checkResult(rs, updatedBlob); - } + stmt.execute("START TRANSACTION "); + try { + PreparedStatement prep = + sharedConn.prepareStatement("insert into updateBlob (id, strm) values (?,?)"); + byte[] theBlob = {1, 2, 3, 4, 5, 6}; + InputStream stream = new ByteArrayInputStream(theBlob); + + prep.setInt(1, 1); + prep.setBlob(2, stream); + prep.execute(); + + byte[] updatedBlob = "abcdef".getBytes(StandardCharsets.UTF_8); + + try (PreparedStatement preparedStatement = + sharedConn.prepareStatement( + "select * from updateBlob", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { + ResultSet rs = preparedStatement.executeQuery(); + assertTrue(rs.next()); + + rs.updateBlob(2, new ByteArrayInputStream(updatedBlob)); + rs.updateRow(); + checkResult(rs, updatedBlob); + + rs.updateBlob("strm", new ByteArrayInputStream(updatedBlob)); + rs.updateRow(); + checkResult(rs, updatedBlob); + + rs.updateBlob(2, new ByteArrayInputStream(updatedBlob), 20L); + rs.updateRow(); + checkResult(rs, updatedBlob); + + rs.updateBlob("strm", new ByteArrayInputStream(updatedBlob), 20L); + rs.updateRow(); + checkResult(rs, updatedBlob); + + rs.updateClob(2, new StringReader("abcdef")); + rs.updateRow(); + checkResult(rs, updatedBlob); + + rs.updateClob("strm", new StringReader("abcdef")); + rs.updateRow(); + checkResult(rs, updatedBlob); + + rs.updateClob(2, new StringReader("abcdef"), 20L); + rs.updateRow(); + checkResult(rs, updatedBlob); + + rs.updateClob("strm", new StringReader("abcdef"), 20L); + rs.updateRow(); + checkResult(rs, updatedBlob); + + rs.updateNClob(2, new StringReader("abcdef")); + rs.updateRow(); + checkResult(rs, updatedBlob); + + rs.updateNClob("strm", new StringReader("abcdef")); + rs.updateRow(); + checkResult(rs, updatedBlob); + + rs.updateNClob(2, new StringReader("abcdef"), 20L); + rs.updateRow(); + checkResult(rs, updatedBlob); + + rs.updateNClob("strm", new StringReader("abcdef"), 20L); + rs.updateRow(); + checkResult(rs, updatedBlob); + } - try (PreparedStatement preparedStatement = - sharedConn.prepareStatement( - "select * from updateBlob", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { - ResultSet rs = preparedStatement.executeQuery(); - assertTrue(rs.next()); - checkResult(rs, updatedBlob); + try (PreparedStatement preparedStatement = + sharedConn.prepareStatement( + "select * from updateBlob", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { + ResultSet rs = preparedStatement.executeQuery(); + assertTrue(rs.next()); + checkResult(rs, updatedBlob); + } + } finally { + sharedConn.rollback(); } }