Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1213120: Reuse connections in tests 3 #1819

Merged
merged 22 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0a64c77
Batch 3 - shared connection
sfc-gh-ext-simba-jf Jul 9, 2024
0b998ff
PR changes
sfc-gh-ext-simba-jf Jul 11, 2024
0fed16d
Checkstyle fix
sfc-gh-ext-simba-jf Jul 17, 2024
41f7176
Merge branch 'master' into Snow-1213120-Reuse-Connections-3
sfc-gh-ext-simba-jf Jul 23, 2024
5ae6f57
Added changes from PR-1 to add BaseJDBCWithSharedConnection
sfc-gh-ext-simba-jf Jul 23, 2024
d128744
fix for closed connection
sfc-gh-ext-simba-jf Jul 23, 2024
91699f5
Trying to debug github tests with print stmt since I can't repro locally
sfc-gh-ext-simba-jf Jul 23, 2024
3de4cb3
testing theory that connection is getting closed by arrow test
sfc-gh-ext-simba-jf Jul 23, 2024
2f45617
Removed print stmts from debugging
sfc-gh-ext-simba-jf Jul 23, 2024
426d93c
Parameterized PreparedMultiStmtIT
sfc-gh-ext-simba-jf Jul 31, 2024
8e27bb0
Merge branch 'master' into Snow-1213120-Reuse-Connections-3
sfc-gh-ext-simba-jf Aug 8, 2024
8e72c34
Merge branch 'master' into Snow-1213120-Reuse-Connections-3
sfc-gh-ext-simba-jf Aug 13, 2024
d56c6b6
Merge branch 'master' into Snow-1213120-Reuse-Connections-3
sfc-gh-ext-simba-jf Aug 28, 2024
8ccd17c
Merge branch 'master' into Snow-1213120-Reuse-Connections-3
sfc-gh-pbulawa Sep 3, 2024
4471bb3
Merge branch 'master' into Snow-1213120-Reuse-Connections-3
sfc-gh-ext-simba-jf Sep 26, 2024
bd17186
Merge branch 'master' into Snow-1213120-Reuse-Connections-3
sfc-gh-ext-simba-jf Oct 8, 2024
37c7174
Merge branch 'master' into Snow-1213120-Reuse-Connections-3
sfc-gh-ext-simba-jf Oct 15, 2024
49e79d6
Merge branch 'master' into Snow-1213120-Reuse-Connections-3
sfc-gh-ext-simba-jf Oct 16, 2024
53fa33f
Add beforeClass
sfc-gh-ext-simba-jf Oct 17, 2024
e6ae253
make beforeclass static
sfc-gh-ext-simba-jf Oct 22, 2024
079b9db
Merge branch 'master' into Snow-1213120-Reuse-Connections-3
sfc-gh-ext-simba-jf Oct 22, 2024
5e2a1b7
Merge branch 'master' into Snow-1213120-Reuse-Connections-3
sfc-gh-ext-simba-jf Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,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";
Expand Down Expand Up @@ -98,8 +97,7 @@ public void testRowIndex() throws SQLException {
}

private ResultSet getResultSet(boolean doNext) throws SQLException {
Connection con = getConnection();
Statement st = con.createStatement();
Statement st = connection.createStatement();
ResultSet resultSet =
new SnowflakeDatabaseMetaDataResultSet(columnNames, columnTypeNames, columnTypes, rows, st);
if (doNext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +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.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand All @@ -24,21 +24,19 @@
* 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";

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
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"
Expand Down Expand Up @@ -74,8 +72,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'");
Expand Down Expand Up @@ -120,8 +117,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"
Expand Down Expand Up @@ -157,8 +153,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)"
Expand Down Expand Up @@ -207,8 +202,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"
Expand Down Expand Up @@ -254,8 +248,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(
Expand All @@ -280,8 +273,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;
Expand Down
188 changes: 88 additions & 100 deletions src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
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.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

/** Test OpenGroup CLI */
@Category(TestCategoryOthers.class)
public class OpenGroupCLIFuncIT extends BaseJDBCTest {
public static Connection getConnection() throws SQLException {
Connection connection = AbstractDriverIT.getConnection();
public class OpenGroupCLIFuncIT extends BaseJDBCWithSharedConnectionIT {

@Before
public void setSessionTimezone() throws SQLException {
sfc-gh-ext-simba-jf marked this conversation as resolved.
Show resolved Hide resolved
try (Statement statement = connection.createStatement()) {
statement.execute(
"alter session set "
Expand All @@ -31,114 +32,101 @@ 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
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 {
Expand Down

This file was deleted.

Loading
Loading