From 0a64c77044b6bd1ee347f65ae43e760abbe02586 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Mon, 8 Jul 2024 20:02:09 -0700 Subject: [PATCH 1/9] Batch 3 - shared connection --- .../jdbc/DatabaseMetaDataResultsetIT.java | 17 +- .../client/jdbc/MultiStatementLatestIT.java | 37 ++-- .../client/jdbc/OpenGroupCLIFuncIT.java | 195 +++++++++--------- .../client/jdbc/PreparedMultiStmtIT.java | 31 ++- 4 files changed, 160 insertions(+), 120 deletions(-) diff --git a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java index febcd4501..2d124db25 100644 --- a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java +++ b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java @@ -19,6 +19,8 @@ import java.util.Arrays; import java.util.List; import net.snowflake.client.category.TestCategoryOthers; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -68,6 +70,20 @@ public class DatabaseMetaDataResultsetIT extends BaseJDBCTest { {0, null, null, 0, null, null, false, null, 0} }; + private static Connection con; + + @BeforeClass + public static void setUpConnection() throws SQLException { + con = getConnection(); + } + + @AfterClass + public static void closeConnection() throws SQLException { + if (con != null && !con.isClosed()) { + con.close(); + } + } + @Test public void testRowIndex() throws SQLException { try (ResultSet resultSet = getResultSet(false)) { @@ -98,7 +114,6 @@ public void testRowIndex() throws SQLException { } private ResultSet getResultSet(boolean doNext) throws SQLException { - Connection con = getConnection(); Statement st = con.createStatement(); ResultSet resultSet = new SnowflakeDatabaseMetaDataResultSet(columnNames, columnTypeNames, columnTypes, rows, st); diff --git a/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java b/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java index 59f5ba795..12a9230e9 100644 --- a/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java @@ -14,6 +14,8 @@ import java.sql.SQLException; import java.sql.Statement; import net.snowflake.client.category.TestCategoryStatement; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -27,6 +29,20 @@ public class MultiStatementLatestIT extends BaseJDBCTest { protected static String queryResultFormat = "json"; + private static Connection connection; + + @BeforeClass + public static void setUpConnection() throws SQLException { + connection = getConnection(); + } + + @AfterClass + public static void closeConnection() throws SQLException { + if (connection != null && !connection.isClosed()) { + connection.close(); + } + } + public static Connection getConnection() throws SQLException { Connection conn = BaseJDBCTest.getConnection(); try (Statement stmt = conn.createStatement()) { @@ -37,8 +53,7 @@ public static Connection getConnection() throws SQLException { @Test public void testMultiStmtExecute() throws SQLException { - try (Connection connection = getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { statement.unwrap(SnowflakeStatement.class).setParameter("MULTI_STATEMENT_COUNT", 3); String multiStmtQuery = "create or replace temporary table test_multi (cola int);\n" @@ -74,8 +89,7 @@ public void testMultiStmtExecute() throws SQLException { @Test public void testMultiStmtTransaction() throws SQLException { - try (Connection connection = getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { try { statement.execute( "create or replace table test_multi_txn(c1 number, c2 string)" + " as select 10, 'z'"); @@ -120,8 +134,7 @@ public void testMultiStmtTransaction() throws SQLException { @Test public void testMultiStmtExecuteUpdate() throws SQLException { - try (Connection connection = getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { String multiStmtQuery = "create or replace temporary table test_multi (cola int);\n" + "insert into test_multi VALUES (1), (2);\n" @@ -157,8 +170,7 @@ public void testMultiStmtExecuteUpdate() throws SQLException { @Test public void testMultiStmtTransactionRollback() throws SQLException { - try (Connection connection = getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { try { statement.execute( "create or replace table test_multi_txn_rb(c1 number, c2 string)" @@ -207,8 +219,7 @@ public void testMultiStmtTransactionRollback() throws SQLException { @Test public void testMultiStmtExecuteQuery() throws SQLException { - try (Connection connection = getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { String multiStmtQuery = "select 1;\n" + "create or replace temporary table test_multi (cola int);\n" @@ -254,8 +265,7 @@ public void testMultiStmtExecuteQuery() throws SQLException { @Test public void testMultiStmtUpdateCount() throws SQLException { - try (Connection connection = getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { statement.unwrap(SnowflakeStatement.class).setParameter("MULTI_STATEMENT_COUNT", 2); boolean isResultSet = statement.execute( @@ -280,8 +290,7 @@ public void testMultiStmtUpdateCount() throws SQLException { /** Test use of anonymous blocks (SNOW-758262) */ @Test public void testAnonymousBlocksUse() throws SQLException { - try (Connection connection = getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { statement.execute("create or replace table tab758262(c1 number)"); // Test anonymous block with multistatement int multistatementcount = 2; diff --git a/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java b/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java index d767456a2..2ae53eb69 100644 --- a/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java +++ b/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java @@ -13,12 +13,29 @@ import net.snowflake.client.AbstractDriverIT; import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryOthers; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; /** Test OpenGroup CLI */ @Category(TestCategoryOthers.class) public class OpenGroupCLIFuncIT extends BaseJDBCTest { + + private static Connection connection; + + @BeforeClass + public static void setUpConnection() throws SQLException { + connection = getConnection(); + } + + @AfterClass + public static void closeConnection() throws SQLException { + if (connection != null && !connection.isClosed()) { + connection.close(); + } + } + public static Connection getConnection() throws SQLException { Connection connection = AbstractDriverIT.getConnection(); try (Statement statement = connection.createStatement()) { @@ -36,109 +53,97 @@ public static Connection getConnection() throws SQLException { @Test public void testStringFunction() throws SQLException { - try (Connection connection = getConnection()) { - testFunction(connection, "select {fn ASCII('snowflake')}", "115"); - testFunction(connection, "select {fn CHAR(115)}", "s"); - testFunction(connection, "select {fn CONCAT('snow', 'flake')}", "snowflake"); - // DIFFERENCE is not supported - // testFunction(connection, "select {fn DIFFERENCE('snow', 'flake')}", "snowflake"); - testFunction(connection, "select {fn INSERT('snowflake', 2, 3, 'insert')}", "sinsertflake"); - testFunction(connection, "select {fn LCASE('SNOWflake')}", "snowflake"); - testFunction(connection, "select {fn LEFT('snowflake', 4)}", "snow"); - testFunction(connection, "select {fn LENGTH(' snowflake ')}", "11"); - testFunction(connection, "select {fn LOCATE('str', 'strstrstr', 2)}", "4"); - testFunction(connection, "select {fn LTRIM(' snowflake ')}", "snowflake "); - testFunction(connection, "select {fn REPEAT('snow', 3)}", "snowsnowsnow"); - testFunction(connection, "select {fn REPLACE('snowssnowsn', 'sn', 'aa')}", "aaowsaaowaa"); - testFunction(connection, "select {fn RIGHT('snowflake', 5)}", "flake"); - testFunction(connection, "select {fn RTRIM(' snowflake ')}", " snowflake"); - // SOUNDEX is not supported - // testFunction(connection, "select {fn SOUNDEX('snowflake')}", " snowflake"); - testFunction(connection, "select {fn SPACE(4)}", " "); - testFunction(connection, "select {fn SUBSTRING('snowflake', 2, 3)}", "now"); - testFunction(connection, "select {fn UCASE('snowflake')}", "SNOWFLAKE"); - } + testFunction(connection, "select {fn ASCII('snowflake')}", "115"); + testFunction(connection, "select {fn CHAR(115)}", "s"); + testFunction(connection, "select {fn CONCAT('snow', 'flake')}", "snowflake"); + // DIFFERENCE is not supported + // testFunction(connection, "select {fn DIFFERENCE('snow', 'flake')}", "snowflake"); + testFunction(connection, "select {fn INSERT('snowflake', 2, 3, 'insert')}", "sinsertflake"); + testFunction(connection, "select {fn LCASE('SNOWflake')}", "snowflake"); + testFunction(connection, "select {fn LEFT('snowflake', 4)}", "snow"); + testFunction(connection, "select {fn LENGTH(' snowflake ')}", "11"); + testFunction(connection, "select {fn LOCATE('str', 'strstrstr', 2)}", "4"); + testFunction(connection, "select {fn LTRIM(' snowflake ')}", "snowflake "); + testFunction(connection, "select {fn REPEAT('snow', 3)}", "snowsnowsnow"); + testFunction(connection, "select {fn REPLACE('snowssnowsn', 'sn', 'aa')}", "aaowsaaowaa"); + testFunction(connection, "select {fn RIGHT('snowflake', 5)}", "flake"); + testFunction(connection, "select {fn RTRIM(' snowflake ')}", " snowflake"); + // SOUNDEX is not supported + // testFunction(connection, "select {fn SOUNDEX('snowflake')}", " snowflake"); + testFunction(connection, "select {fn SPACE(4)}", " "); + testFunction(connection, "select {fn SUBSTRING('snowflake', 2, 3)}", "now"); + testFunction(connection, "select {fn UCASE('snowflake')}", "SNOWFLAKE"); } @Test public void testDateTimeFunction() throws SQLException { - try (Connection connection = getConnection()) { - // testFunction(connection, "select {fn CURDATE()}",""); - // testFunction(connection, "select {fn CURTIME()}",""); - testFunction(connection, "select {fn DAYNAME('2016-5-25')}", "Wed"); - testFunction(connection, "select {fn DAYOFMONTH(to_date('2016-5-25'))}", "25"); - testFunction(connection, "select {fn DAYOFWEEK(to_date('2016-5-25'))}", "3"); - testFunction(connection, "select {fn DAYOFYEAR(to_date('2016-5-25'))}", "146"); - testFunction(connection, "select {fn HOUR(to_timestamp('2016-5-25 12:34:56.789789'))}", "12"); - testFunction( - connection, "select {fn MINUTE(to_timestamp('2016-5-25 12:34:56.789789'))}", "34"); - testFunction(connection, "select {fn MONTH(to_date('2016-5-25'))}", "5"); - testFunction(connection, "select {fn MONTHNAME(to_date('2016-5-25'))}", "May"); - // testFunction(connection, "select {fn NOW()}", "May"); - testFunction(connection, "select {fn QUARTER(to_date('2016-5-25'))}", "2"); - testFunction( - connection, "select {fn SECOND(to_timestamp('2016-5-25 12:34:56.789789'))}", "56"); - testFunction( - connection, - "select {fn TIMESTAMPADD(SQL_TSI_FRAC_SECOND, 1000, " - + "to_timestamp('2016-5-25 12:34:56.789789'))}", - "Wed, 25 May 2016 12:34:56 -0700"); - testFunction( - connection, - "select {fn TIMESTAMPADD(SQL_TSI_SECOND, 1, " - + "to_timestamp('2016-5-25 12:34:56.789789'))}", - "Wed, 25 May 2016 12:34:57 -0700"); - testFunction( - connection, - "select {fn TIMESTAMPADD(SQL_TSI_MINUTE, 1, " - + "to_timestamp('2016-5-25 12:34:56.789789'))}", - "Wed, 25 May 2016 12:35:56 -0700"); - testFunction( - connection, - "select {fn TIMESTAMPADD(SQL_TSI_HOUR, 1, " - + "to_timestamp('2016-5-25 12:34:56.789789'))}", - "Wed, 25 May 2016 13:34:56 -0700"); - testFunction( - connection, - "select {fn TIMESTAMPADD(SQL_TSI_DAY, 1, " - + "to_timestamp('2016-5-25 12:34:56.789789'))}", - "Thu, 26 May 2016 12:34:56 -0700"); - testFunction( - connection, - "select {fn TIMESTAMPADD(SQL_TSI_MONTH, 1, " - + "to_timestamp('2016-5-25 12:34:56.789789'))}", - "Sat, 25 Jun 2016 12:34:56 -0700"); - testFunction( - connection, - "select {fn TIMESTAMPADD(SQL_TSI_QUARTER, 1, " - + "to_timestamp('2016-5-25 12:34:56.789789'))}", - "Thu, 25 Aug 2016 12:34:56 -0700"); - testFunction( - connection, - "select {fn TIMESTAMPADD(SQL_TSI_YEAR, 1, " - + "to_timestamp('2016-5-25 12:34:56.789789'))}", - "Thu, 25 May 2017 12:34:56 -0700"); - testFunction( - connection, - "select {fn TIMESTAMPDIFF(SQL_TSI_SECOND, " - + "to_timestamp('2016-5-25 12:34:56.789789'), to_timestamp('2016-5-25 12:34:57.789789'))}", - "1"); - testFunction(connection, "select {fn WEEK(to_timestamp('2016-5-25 12:34:56.789789'))}", "21"); - testFunction( - connection, "select {fn YEAR(to_timestamp('2016-5-25 12:34:56.789789'))}", "2016"); - } + // testFunction(connection, "select {fn CURDATE()}",""); + // testFunction(connection, "select {fn CURTIME()}",""); + testFunction(connection, "select {fn DAYNAME('2016-5-25')}", "Wed"); + testFunction(connection, "select {fn DAYOFMONTH(to_date('2016-5-25'))}", "25"); + testFunction(connection, "select {fn DAYOFWEEK(to_date('2016-5-25'))}", "3"); + testFunction(connection, "select {fn DAYOFYEAR(to_date('2016-5-25'))}", "146"); + testFunction(connection, "select {fn HOUR(to_timestamp('2016-5-25 12:34:56.789789'))}", "12"); + testFunction(connection, "select {fn MINUTE(to_timestamp('2016-5-25 12:34:56.789789'))}", "34"); + testFunction(connection, "select {fn MONTH(to_date('2016-5-25'))}", "5"); + testFunction(connection, "select {fn MONTHNAME(to_date('2016-5-25'))}", "May"); + // testFunction(connection, "select {fn NOW()}", "May"); + testFunction(connection, "select {fn QUARTER(to_date('2016-5-25'))}", "2"); + testFunction(connection, "select {fn SECOND(to_timestamp('2016-5-25 12:34:56.789789'))}", "56"); + testFunction( + connection, + "select {fn TIMESTAMPADD(SQL_TSI_FRAC_SECOND, 1000, " + + "to_timestamp('2016-5-25 12:34:56.789789'))}", + "Wed, 25 May 2016 12:34:56 -0700"); + testFunction( + connection, + "select {fn TIMESTAMPADD(SQL_TSI_SECOND, 1, " + + "to_timestamp('2016-5-25 12:34:56.789789'))}", + "Wed, 25 May 2016 12:34:57 -0700"); + testFunction( + connection, + "select {fn TIMESTAMPADD(SQL_TSI_MINUTE, 1, " + + "to_timestamp('2016-5-25 12:34:56.789789'))}", + "Wed, 25 May 2016 12:35:56 -0700"); + testFunction( + connection, + "select {fn TIMESTAMPADD(SQL_TSI_HOUR, 1, " + "to_timestamp('2016-5-25 12:34:56.789789'))}", + "Wed, 25 May 2016 13:34:56 -0700"); + testFunction( + connection, + "select {fn TIMESTAMPADD(SQL_TSI_DAY, 1, " + "to_timestamp('2016-5-25 12:34:56.789789'))}", + "Thu, 26 May 2016 12:34:56 -0700"); + testFunction( + connection, + "select {fn TIMESTAMPADD(SQL_TSI_MONTH, 1, " + + "to_timestamp('2016-5-25 12:34:56.789789'))}", + "Sat, 25 Jun 2016 12:34:56 -0700"); + testFunction( + connection, + "select {fn TIMESTAMPADD(SQL_TSI_QUARTER, 1, " + + "to_timestamp('2016-5-25 12:34:56.789789'))}", + "Thu, 25 Aug 2016 12:34:56 -0700"); + testFunction( + connection, + "select {fn TIMESTAMPADD(SQL_TSI_YEAR, 1, " + "to_timestamp('2016-5-25 12:34:56.789789'))}", + "Thu, 25 May 2017 12:34:56 -0700"); + testFunction( + connection, + "select {fn TIMESTAMPDIFF(SQL_TSI_SECOND, " + + "to_timestamp('2016-5-25 12:34:56.789789'), to_timestamp('2016-5-25 12:34:57.789789'))}", + "1"); + testFunction(connection, "select {fn WEEK(to_timestamp('2016-5-25 12:34:56.789789'))}", "21"); + testFunction(connection, "select {fn YEAR(to_timestamp('2016-5-25 12:34:56.789789'))}", "2016"); } @Test public void testSystemFunctions() throws SQLException { - try (Connection connection = getConnection()) { - testFunction(connection, "select {fn DATABASE()}", connection.getCatalog()); - testFunction(connection, "select {fn IFNULL(NULL, 1)}", "1"); - testFunction( - connection, - "select {fn USER()}", - TestUtil.systemGetEnv("SNOWFLAKE_TEST_USER").toUpperCase()); - } + testFunction(connection, "select {fn DATABASE()}", connection.getCatalog()); + testFunction(connection, "select {fn IFNULL(NULL, 1)}", "1"); + testFunction( + connection, + "select {fn USER()}", + TestUtil.systemGetEnv("SNOWFLAKE_TEST_USER").toUpperCase()); } static void testFunction(Connection connection, String sql, String expected) throws SQLException { diff --git a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java index 3d1997193..071b7fa47 100644 --- a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java @@ -11,7 +11,9 @@ import java.sql.SQLException; import java.sql.Statement; import net.snowflake.client.category.TestCategoryStatement; +import org.junit.AfterClass; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -20,6 +22,20 @@ public class PreparedMultiStmtIT extends BaseJDBCTest { protected static String queryResultFormat = "json"; + private static SnowflakeConnectionV1 connection; + + @BeforeClass + public static void setUpConnection() throws SQLException { + connection = (SnowflakeConnectionV1) getConnection(); + } + + @AfterClass + public static void closeConnection() throws SQLException { + if (connection != null && !connection.isClosed()) { + connection.close(); + } + } + public static Connection getConnection() throws SQLException { Connection conn = BaseJDBCTest.getConnection(); try (Statement stmt = conn.createStatement()) { @@ -30,8 +46,7 @@ public static Connection getConnection() throws SQLException { @Test public void testExecuteUpdateCount() throws Exception { - try (SnowflakeConnectionV1 connection = (SnowflakeConnectionV1) getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); statement.execute("create or replace table test_multi_bind(c1 number)"); @@ -76,8 +91,7 @@ public void testExecuteUpdateCount() throws Exception { /** Less bindings than expected in statement */ @Test public void testExecuteLessBindings() throws Exception { - try (SnowflakeConnectionV1 connection = (SnowflakeConnectionV1) getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); statement.execute("create or replace table test_multi_bind(c1 number)"); @@ -109,8 +123,7 @@ public void testExecuteLessBindings() throws Exception { @Test public void testExecuteMoreBindings() throws Exception { - try (SnowflakeConnectionV1 connection = (SnowflakeConnectionV1) getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); statement.execute("create or replace table test_multi_bind(c1 number)"); @@ -156,8 +169,7 @@ public void testExecuteMoreBindings() throws Exception { @Test public void testExecuteQueryBindings() throws Exception { - try (SnowflakeConnectionV1 connection = (SnowflakeConnectionV1) getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); try (PreparedStatement preparedStatement = @@ -199,8 +211,7 @@ public void testExecuteQueryBindings() throws Exception { @Test public void testExecuteQueryNoBindings() throws Exception { - try (SnowflakeConnectionV1 connection = (SnowflakeConnectionV1) getConnection(); - Statement statement = connection.createStatement()) { + try (Statement statement = connection.createStatement()) { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); try (PreparedStatement preparedStatement = From 0b998ff11637401bc6d1234d0f131b948fd378c3 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Thu, 11 Jul 2024 00:14:17 -0700 Subject: [PATCH 2/9] PR changes --- .../snowflake/client/jdbc/BaseJDBCTest.java | 16 +++++++ .../jdbc/DatabaseMetaDataResultsetIT.java | 19 +------- .../client/jdbc/MultiStatementLatestIT.java | 25 ++--------- .../client/jdbc/OpenGroupCLIFuncIT.java | 23 ++-------- .../client/jdbc/PreparedMultiStmtIT.java | 45 ++++++------------- 5 files changed, 38 insertions(+), 90 deletions(-) diff --git a/src/test/java/net/snowflake/client/jdbc/BaseJDBCTest.java b/src/test/java/net/snowflake/client/jdbc/BaseJDBCTest.java index a326dea12..6c239b8c3 100644 --- a/src/test/java/net/snowflake/client/jdbc/BaseJDBCTest.java +++ b/src/test/java/net/snowflake/client/jdbc/BaseJDBCTest.java @@ -36,11 +36,27 @@ import javax.xml.transform.Source; import net.snowflake.client.AbstractDriverIT; import net.snowflake.client.core.SFException; +import org.junit.AfterClass; +import org.junit.BeforeClass; public class BaseJDBCTest extends AbstractDriverIT { // Test UUID unique per session static final String TEST_UUID = UUID.randomUUID().toString(); + protected static Connection connection; + + @BeforeClass + public static void setUpConnection() throws SQLException { + connection = getConnection(); + } + + @AfterClass + public static void closeConnection() throws SQLException { + if (connection != null && !connection.isClosed()) { + connection.close(); + } + } + protected interface MethodRaisesSQLException { void run() throws SQLException; } diff --git a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java index 2d124db25..d0b5e6edd 100644 --- a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java +++ b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java @@ -8,7 +8,6 @@ import static org.junit.Assert.assertTrue; import java.math.BigDecimal; -import java.sql.Connection; import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; @@ -19,8 +18,6 @@ import java.util.Arrays; import java.util.List; import net.snowflake.client.category.TestCategoryOthers; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -70,20 +67,6 @@ public class DatabaseMetaDataResultsetIT extends BaseJDBCTest { {0, null, null, 0, null, null, false, null, 0} }; - private static Connection con; - - @BeforeClass - public static void setUpConnection() throws SQLException { - con = getConnection(); - } - - @AfterClass - public static void closeConnection() throws SQLException { - if (con != null && !con.isClosed()) { - con.close(); - } - } - @Test public void testRowIndex() throws SQLException { try (ResultSet resultSet = getResultSet(false)) { @@ -114,7 +97,7 @@ public void testRowIndex() throws SQLException { } private ResultSet getResultSet(boolean doNext) throws SQLException { - Statement st = con.createStatement(); + Statement st = connection.createStatement(); ResultSet resultSet = new SnowflakeDatabaseMetaDataResultSet(columnNames, columnTypeNames, columnTypes, rows, st); if (doNext) { diff --git a/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java b/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java index 12a9230e9..5e04d183c 100644 --- a/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java @@ -9,13 +9,11 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import net.snowflake.client.category.TestCategoryStatement; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -29,26 +27,11 @@ public class MultiStatementLatestIT extends BaseJDBCTest { protected static String queryResultFormat = "json"; - private static Connection connection; - - @BeforeClass - public static void setUpConnection() throws SQLException { - connection = getConnection(); - } - - @AfterClass - public static void closeConnection() throws SQLException { - if (connection != null && !connection.isClosed()) { - connection.close(); - } - } - - public static Connection getConnection() throws SQLException { - Connection conn = BaseJDBCTest.getConnection(); - try (Statement stmt = conn.createStatement()) { + @Before + public void setQueryResultFormat() throws SQLException { + try (Statement stmt = connection.createStatement()) { stmt.execute("alter session set jdbc_query_result_format = '" + queryResultFormat + "'"); } - return conn; } @Test diff --git a/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java b/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java index 2ae53eb69..1d87a589c 100644 --- a/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java +++ b/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java @@ -10,11 +10,9 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import net.snowflake.client.AbstractDriverIT; import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryOthers; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -22,22 +20,8 @@ @Category(TestCategoryOthers.class) public class OpenGroupCLIFuncIT extends BaseJDBCTest { - private static Connection connection; - - @BeforeClass - public static void setUpConnection() throws SQLException { - connection = getConnection(); - } - - @AfterClass - public static void closeConnection() throws SQLException { - if (connection != null && !connection.isClosed()) { - connection.close(); - } - } - - public static Connection getConnection() throws SQLException { - Connection connection = AbstractDriverIT.getConnection(); + @Before + public void setSessionTimezone() throws SQLException { try (Statement statement = connection.createStatement()) { statement.execute( "alter session set " @@ -48,7 +32,6 @@ public static Connection getConnection() throws SQLException { + "TIMESTAMP_LTZ_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM'," + "TIMESTAMP_NTZ_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM'"); } - return connection; } @Test diff --git a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java index 071b7fa47..26ce69231 100644 --- a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java @@ -5,16 +5,12 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; -import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import net.snowflake.client.category.TestCategoryStatement; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.*; import org.junit.experimental.categories.Category; @Category(TestCategoryStatement.class) @@ -22,31 +18,18 @@ public class PreparedMultiStmtIT extends BaseJDBCTest { protected static String queryResultFormat = "json"; - private static SnowflakeConnectionV1 connection; + private static SnowflakeConnectionV1 sfConnectionV1 = (SnowflakeConnectionV1) connection; - @BeforeClass - public static void setUpConnection() throws SQLException { - connection = (SnowflakeConnectionV1) getConnection(); - } - - @AfterClass - public static void closeConnection() throws SQLException { - if (connection != null && !connection.isClosed()) { - connection.close(); - } - } - - public static Connection getConnection() throws SQLException { - Connection conn = BaseJDBCTest.getConnection(); - try (Statement stmt = conn.createStatement()) { + @Before + public void setSessionResultFormat() throws SQLException { + try (Statement stmt = sfConnectionV1.createStatement()) { stmt.execute("alter session set jdbc_query_result_format = '" + queryResultFormat + "'"); } - return conn; } @Test public void testExecuteUpdateCount() throws Exception { - try (Statement statement = connection.createStatement()) { + try (Statement statement = sfConnectionV1.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); statement.execute("create or replace table test_multi_bind(c1 number)"); @@ -91,13 +74,13 @@ public void testExecuteUpdateCount() throws Exception { /** Less bindings than expected in statement */ @Test public void testExecuteLessBindings() throws Exception { - try (Statement statement = connection.createStatement()) { + try (Statement statement = sfConnectionV1.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); statement.execute("create or replace table test_multi_bind(c1 number)"); try (PreparedStatement preparedStatement = - connection.prepareStatement( + sfConnectionV1.prepareStatement( "insert into test_multi_bind(c1) values(?); insert into " + "test_multi_bind values (?), (?)")) { @@ -123,13 +106,13 @@ public void testExecuteLessBindings() throws Exception { @Test public void testExecuteMoreBindings() throws Exception { - try (Statement statement = connection.createStatement()) { + try (Statement statement = sfConnectionV1.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); statement.execute("create or replace table test_multi_bind(c1 number)"); try (PreparedStatement preparedStatement = - connection.prepareStatement( + sfConnectionV1.prepareStatement( "insert into test_multi_bind(c1) values(?); insert into " + "test_multi_bind values (?), (?)")) { @@ -169,11 +152,11 @@ public void testExecuteMoreBindings() throws Exception { @Test public void testExecuteQueryBindings() throws Exception { - try (Statement statement = connection.createStatement()) { + try (Statement statement = sfConnectionV1.createStatement()) { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); try (PreparedStatement preparedStatement = - connection.prepareStatement("select ?; select ?, ?; select ?, ?, ?")) { + sfConnectionV1.prepareStatement("select ?; select ?, ?; select ?, ?, ?")) { assertThat(preparedStatement.getParameterMetaData().getParameterCount(), is(6)); @@ -211,11 +194,11 @@ public void testExecuteQueryBindings() throws Exception { @Test public void testExecuteQueryNoBindings() throws Exception { - try (Statement statement = connection.createStatement()) { + try (Statement statement = sfConnectionV1.createStatement()) { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); try (PreparedStatement preparedStatement = - connection.prepareStatement("select 10; select 20, 30; select 40, 50, 60")) { + sfConnectionV1.prepareStatement("select 10; select 20, 30; select 40, 50, 60")) { assertThat(preparedStatement.getParameterMetaData().getParameterCount(), is(0)); From 0fed16d12d3a8feee97e87db8805eef1c4a79b55 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Wed, 17 Jul 2024 16:02:23 -0700 Subject: [PATCH 3/9] Checkstyle fix --- .../java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java index 26ce69231..a0ab9c54a 100644 --- a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java @@ -10,7 +10,9 @@ import java.sql.SQLException; import java.sql.Statement; import net.snowflake.client.category.TestCategoryStatement; -import org.junit.*; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.junit.experimental.categories.Category; @Category(TestCategoryStatement.class) From 5ae6f5798dd518923a5a17ce3b2fd58cc46a4efb Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Mon, 22 Jul 2024 18:15:47 -0700 Subject: [PATCH 4/9] Added changes from PR-1 to add BaseJDBCWithSharedConnection --- .../net/snowflake/client/jdbc/BaseJDBCTest.java | 16 ---------------- .../client/jdbc/DatabaseMetaDataResultsetIT.java | 2 +- .../client/jdbc/MultiStatementLatestIT.java | 2 +- .../client/jdbc/OpenGroupCLIFuncIT.java | 2 +- .../client/jdbc/PreparedMultiStmtIT.java | 2 +- 5 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/test/java/net/snowflake/client/jdbc/BaseJDBCTest.java b/src/test/java/net/snowflake/client/jdbc/BaseJDBCTest.java index 6c239b8c3..a326dea12 100644 --- a/src/test/java/net/snowflake/client/jdbc/BaseJDBCTest.java +++ b/src/test/java/net/snowflake/client/jdbc/BaseJDBCTest.java @@ -36,27 +36,11 @@ import javax.xml.transform.Source; import net.snowflake.client.AbstractDriverIT; import net.snowflake.client.core.SFException; -import org.junit.AfterClass; -import org.junit.BeforeClass; public class BaseJDBCTest extends AbstractDriverIT { // Test UUID unique per session static final String TEST_UUID = UUID.randomUUID().toString(); - protected static Connection connection; - - @BeforeClass - public static void setUpConnection() throws SQLException { - connection = getConnection(); - } - - @AfterClass - public static void closeConnection() throws SQLException { - if (connection != null && !connection.isClosed()) { - connection.close(); - } - } - protected interface MethodRaisesSQLException { void run() throws SQLException; } diff --git a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java index d0b5e6edd..ccc984e3c 100644 --- a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java +++ b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java @@ -22,7 +22,7 @@ import org.junit.experimental.categories.Category; @Category(TestCategoryOthers.class) -public class DatabaseMetaDataResultsetIT extends BaseJDBCTest { +public class DatabaseMetaDataResultsetIT extends BaseJDBCWithSharedConnectionIT { private static final int columnCount = 9; private static final int INT_DATA = 1; private static final String TEXT_DATA = "TEST"; diff --git a/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java b/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java index 5e04d183c..eedf56114 100644 --- a/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java @@ -24,7 +24,7 @@ * both the latest and oldest supported driver run the tests. */ @Category(TestCategoryStatement.class) -public class MultiStatementLatestIT extends BaseJDBCTest { +public class MultiStatementLatestIT extends BaseJDBCWithSharedConnectionIT { protected static String queryResultFormat = "json"; @Before diff --git a/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java b/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java index 1d87a589c..4b6e081c6 100644 --- a/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java +++ b/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java @@ -18,7 +18,7 @@ /** Test OpenGroup CLI */ @Category(TestCategoryOthers.class) -public class OpenGroupCLIFuncIT extends BaseJDBCTest { +public class OpenGroupCLIFuncIT extends BaseJDBCWithSharedConnectionIT { @Before public void setSessionTimezone() throws SQLException { diff --git a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java index a0ab9c54a..bc669b37d 100644 --- a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java @@ -16,7 +16,7 @@ import org.junit.experimental.categories.Category; @Category(TestCategoryStatement.class) -public class PreparedMultiStmtIT extends BaseJDBCTest { +public class PreparedMultiStmtIT extends BaseJDBCWithSharedConnectionIT { protected static String queryResultFormat = "json"; From d128744eaeef1764991f28a3d1699aa612fb40c8 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Mon, 22 Jul 2024 23:12:34 -0700 Subject: [PATCH 5/9] fix for closed connection --- .../java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java index bc669b37d..db143be7d 100644 --- a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java @@ -24,7 +24,7 @@ public class PreparedMultiStmtIT extends BaseJDBCWithSharedConnectionIT { @Before public void setSessionResultFormat() throws SQLException { - try (Statement stmt = sfConnectionV1.createStatement()) { + try (Statement stmt = connection.createStatement()) { stmt.execute("alter session set jdbc_query_result_format = '" + queryResultFormat + "'"); } } @@ -37,7 +37,7 @@ public void testExecuteUpdateCount() throws Exception { statement.execute("create or replace table test_multi_bind(c1 number)"); try (PreparedStatement preparedStatement = - connection.prepareStatement( + sfConnectionV1.prepareStatement( "insert into test_multi_bind(c1) values(?); insert into " + "test_multi_bind values (?), (?)")) { From 91699f54793a6ab0e15758a41cb296a6171fbf86 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Tue, 23 Jul 2024 00:24:45 -0700 Subject: [PATCH 6/9] Trying to debug github tests with print stmt since I can't repro locally --- .../snowflake/client/jdbc/PreparedMultiStmtIT.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java index db143be7d..d3c137350 100644 --- a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java @@ -24,13 +24,16 @@ public class PreparedMultiStmtIT extends BaseJDBCWithSharedConnectionIT { @Before public void setSessionResultFormat() throws SQLException { + System.out.println("sfConnection is closed? " + sfConnectionV1.isClosed()); try (Statement stmt = connection.createStatement()) { stmt.execute("alter session set jdbc_query_result_format = '" + queryResultFormat + "'"); } + System.out.println("sfConnection is closed after? " + sfConnectionV1.isClosed()); } @Test public void testExecuteUpdateCount() throws Exception { + System.out.println("sfConnection is closed in test? " + sfConnectionV1.isClosed()); try (Statement statement = sfConnectionV1.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); @@ -71,11 +74,13 @@ public void testExecuteUpdateCount() throws Exception { statement.execute("drop table if exists test_multi_bind"); } } + System.out.println("sfConnection is closed after test? " + sfConnectionV1.isClosed()); } /** Less bindings than expected in statement */ @Test public void testExecuteLessBindings() throws Exception { + System.out.println("sfConnection is closed in test? " + sfConnectionV1.isClosed()); try (Statement statement = sfConnectionV1.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); @@ -104,10 +109,12 @@ public void testExecuteLessBindings() throws Exception { statement.execute("drop table if exists test_multi_bind"); } } + System.out.println("sfConnection is closed after test? " + sfConnectionV1.isClosed()); } @Test public void testExecuteMoreBindings() throws Exception { + System.out.println("sfConnection is closed in test? " + sfConnectionV1.isClosed()); try (Statement statement = sfConnectionV1.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); @@ -150,10 +157,12 @@ public void testExecuteMoreBindings() throws Exception { statement.execute("drop table if exists test_multi_bind"); } } + System.out.println("sfConnection is closed after test? " + sfConnectionV1.isClosed()); } @Test public void testExecuteQueryBindings() throws Exception { + System.out.println("sfConnection is closed in test? " + sfConnectionV1.isClosed()); try (Statement statement = sfConnectionV1.createStatement()) { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); @@ -192,10 +201,12 @@ public void testExecuteQueryBindings() throws Exception { } } } + System.out.println("sfConnection is closed after test? " + sfConnectionV1.isClosed()); } @Test public void testExecuteQueryNoBindings() throws Exception { + System.out.println("sfConnection is closed in test? " + sfConnectionV1.isClosed()); try (Statement statement = sfConnectionV1.createStatement()) { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); @@ -228,5 +239,6 @@ public void testExecuteQueryNoBindings() throws Exception { } } } + System.out.println("sfConnection is closed after test? " + sfConnectionV1.isClosed()); } } From 3de4cb3304a23618875af9042006136bced7ed0e Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Tue, 23 Jul 2024 00:51:39 -0700 Subject: [PATCH 7/9] testing theory that connection is getting closed by arrow test --- .../snowflake/client/jdbc/PreparedMultiStmtIT.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java index d3c137350..87f89e754 100644 --- a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java @@ -12,6 +12,7 @@ import net.snowflake.client.category.TestCategoryStatement; import org.junit.Assert; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -20,7 +21,16 @@ public class PreparedMultiStmtIT extends BaseJDBCWithSharedConnectionIT { protected static String queryResultFormat = "json"; - private static SnowflakeConnectionV1 sfConnectionV1 = (SnowflakeConnectionV1) connection; + private static SnowflakeConnectionV1 sfConnectionV1; + + @BeforeClass + public static void setUpPreparedStatementConnection() throws SQLException { + if (!connection.isClosed()) { + sfConnectionV1 = (SnowflakeConnectionV1) connection; + } else { + sfConnectionV1 = (SnowflakeConnectionV1) getConnection(); + } + } @Before public void setSessionResultFormat() throws SQLException { From 2f456177872a8a6296ad3e2f997671796eed9291 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Tue, 23 Jul 2024 01:25:52 -0700 Subject: [PATCH 8/9] Removed print stmts from debugging --- .../snowflake/client/jdbc/PreparedMultiStmtIT.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java index 87f89e754..70681fe14 100644 --- a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java @@ -34,16 +34,13 @@ public static void setUpPreparedStatementConnection() throws SQLException { @Before public void setSessionResultFormat() throws SQLException { - System.out.println("sfConnection is closed? " + sfConnectionV1.isClosed()); try (Statement stmt = connection.createStatement()) { stmt.execute("alter session set jdbc_query_result_format = '" + queryResultFormat + "'"); } - System.out.println("sfConnection is closed after? " + sfConnectionV1.isClosed()); } @Test public void testExecuteUpdateCount() throws Exception { - System.out.println("sfConnection is closed in test? " + sfConnectionV1.isClosed()); try (Statement statement = sfConnectionV1.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); @@ -84,13 +81,11 @@ public void testExecuteUpdateCount() throws Exception { statement.execute("drop table if exists test_multi_bind"); } } - System.out.println("sfConnection is closed after test? " + sfConnectionV1.isClosed()); } /** Less bindings than expected in statement */ @Test public void testExecuteLessBindings() throws Exception { - System.out.println("sfConnection is closed in test? " + sfConnectionV1.isClosed()); try (Statement statement = sfConnectionV1.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); @@ -119,12 +114,10 @@ public void testExecuteLessBindings() throws Exception { statement.execute("drop table if exists test_multi_bind"); } } - System.out.println("sfConnection is closed after test? " + sfConnectionV1.isClosed()); } @Test public void testExecuteMoreBindings() throws Exception { - System.out.println("sfConnection is closed in test? " + sfConnectionV1.isClosed()); try (Statement statement = sfConnectionV1.createStatement()) { try { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); @@ -167,12 +160,10 @@ public void testExecuteMoreBindings() throws Exception { statement.execute("drop table if exists test_multi_bind"); } } - System.out.println("sfConnection is closed after test? " + sfConnectionV1.isClosed()); } @Test public void testExecuteQueryBindings() throws Exception { - System.out.println("sfConnection is closed in test? " + sfConnectionV1.isClosed()); try (Statement statement = sfConnectionV1.createStatement()) { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); @@ -211,12 +202,10 @@ public void testExecuteQueryBindings() throws Exception { } } } - System.out.println("sfConnection is closed after test? " + sfConnectionV1.isClosed()); } @Test public void testExecuteQueryNoBindings() throws Exception { - System.out.println("sfConnection is closed in test? " + sfConnectionV1.isClosed()); try (Statement statement = sfConnectionV1.createStatement()) { statement.execute("alter session set MULTI_STATEMENT_COUNT=0"); @@ -249,6 +238,5 @@ public void testExecuteQueryNoBindings() throws Exception { } } } - System.out.println("sfConnection is closed after test? " + sfConnectionV1.isClosed()); } } From 426d93c84f125326742ce908025f54afc3f8f0f5 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Tue, 30 Jul 2024 17:56:30 -0700 Subject: [PATCH 9/9] Parameterized PreparedMultiStmtIT --- .../client/jdbc/PreparedMultiStmtArrowIT.java | 12 ----------- .../client/jdbc/PreparedMultiStmtIT.java | 21 +++++++++++-------- 2 files changed, 12 insertions(+), 21 deletions(-) delete mode 100644 src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtArrowIT.java diff --git a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtArrowIT.java b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtArrowIT.java deleted file mode 100644 index 54a3e8ec1..000000000 --- a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtArrowIT.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.snowflake.client.jdbc; - -import net.snowflake.client.category.TestCategoryArrow; -import org.junit.experimental.categories.Category; - -@Category(TestCategoryArrow.class) -public class PreparedMultiStmtArrowIT extends PreparedMultiStmtIT { - public PreparedMultiStmtArrowIT() { - super(); - queryResultFormat = "arrow"; - } -} diff --git a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java index 70681fe14..224c538d0 100644 --- a/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java @@ -12,24 +12,27 @@ import net.snowflake.client.category.TestCategoryStatement; import org.junit.Assert; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +@RunWith(Parameterized.class) @Category(TestCategoryStatement.class) public class PreparedMultiStmtIT extends BaseJDBCWithSharedConnectionIT { - protected static String queryResultFormat = "json"; + @Parameterized.Parameters(name = "format={0}") + public static Object[][] data() { + // all tests in this class need to run for both query result formats json and arrow + return new Object[][] {{"JSON"}, {"Arrow"}}; + } + protected String queryResultFormat; private static SnowflakeConnectionV1 sfConnectionV1; - @BeforeClass - public static void setUpPreparedStatementConnection() throws SQLException { - if (!connection.isClosed()) { - sfConnectionV1 = (SnowflakeConnectionV1) connection; - } else { - sfConnectionV1 = (SnowflakeConnectionV1) getConnection(); - } + public PreparedMultiStmtIT(String queryResultFormat) { + this.queryResultFormat = queryResultFormat; + this.sfConnectionV1 = (SnowflakeConnectionV1) connection; } @Before