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-1 #1815

Merged
merged 7 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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 @@ -19,6 +19,8 @@
import net.snowflake.client.ConditionalIgnoreRule;
import net.snowflake.client.RunningOnGithubAction;
import net.snowflake.client.category.TestCategoryResultSet;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -53,9 +55,21 @@ public ResultSetMultiTimeZoneLatestIT(String queryResultFormat, String timeZone)
System.setProperty("user.timezone", timeZone);
}

public Connection init() throws SQLException {
Connection connection = BaseJDBCTest.getConnection();
private static Connection connection;

@BeforeClass
public static void setUpConnection() throws SQLException {
connection = BaseJDBCTest.getConnection();
}

@AfterClass
public static void closeConnection() throws SQLException {
if (connection != null && !connection.isClosed()) {
connection.close();
}
}

public Connection init() throws SQLException {
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
try (Statement statement = connection.createStatement()) {
statement.execute(
"alter session set "
Expand All @@ -78,8 +92,8 @@ public Connection init() throws SQLException {
*/
@Test
public void testTimesWithGetTimestamp() throws SQLException {
try (Connection connection = init();
Statement statement = connection.createStatement()) {
Connection connection = init();
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
try (Statement statement = connection.createStatement()) {
String timeStringValue = "10:30:50.123456789";
String timestampStringValue = "1970-01-01 " + timeStringValue;
int length = timestampStringValue.length();
Expand Down Expand Up @@ -113,8 +127,8 @@ public void testTimesWithGetTimestamp() throws SQLException {
*/
@Test
public void testTimestampNTZWithDaylightSavings() throws SQLException {
try (Connection connection = init();
Statement statement = connection.createStatement()) {
Connection connection = init();
try (Statement statement = connection.createStatement()) {
statement.execute(
"alter session set TIMESTAMP_TYPE_MAPPING='TIMESTAMP_NTZ'," + "TIMEZONE='Europe/London'");
try (ResultSet rs = statement.executeQuery("select TIMESTAMP '2011-09-04 00:00:00'")) {
Expand All @@ -135,8 +149,8 @@ public void testDateAndTimestampWithTimezone() throws SQLException {
Calendar cal = null;
SimpleDateFormat sdf = null;

try (Connection connection = init();
Statement statement = connection.createStatement()) {
Connection connection = init();
try (Statement statement = connection.createStatement()) {
statement.execute("alter session set JDBC_FORMAT_DATE_WITH_TIMEZONE=true");
try (ResultSet rs =
statement.executeQuery(
Expand Down Expand Up @@ -232,8 +246,8 @@ public void testUseSessionTimeZoneOverrides() throws SQLException {
* @throws SQLException
*/
private void testUseSessionTimeZoneHelper(boolean useDefaultParamSettings) throws SQLException {
try (Connection connection = init();
Statement statement = connection.createStatement()) {
Connection connection = init();
try (Statement statement = connection.createStatement()) {
try {
// create table with all timestamp types, time, and date
statement.execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.util.Arrays;
import java.util.List;
import net.snowflake.client.category.TestCategoryResultSet;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -42,10 +44,23 @@ public static List<String> queryResultFormats() {
return Arrays.asList("json", "arrow");
}

private static Connection con;
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved

@BeforeClass
public static void setUpConnection() throws SQLException {
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
con = BaseJDBCTest.getConnection();
}

@AfterClass
public static void closeConnection() throws SQLException {
if (con != null && !con.isClosed()) {
con.close();
}
}

@Test
public void testGetIntVectorAsIntArray() throws SQLException {
try (Connection con = BaseJDBCTest.getConnection();
Statement stmt = con.createStatement()) {
try (Statement stmt = con.createStatement()) {
enforceQueryResultFormat(stmt);
Integer[] vector = {-1, 5};
try (ResultSet resultSet = stmt.executeQuery("select " + vectorToString(vector, "int"))) {
Expand All @@ -60,8 +75,7 @@ public void testGetIntVectorAsIntArray() throws SQLException {

@Test
public void testGetIntVectorAsLongArray() throws SQLException {
try (Connection con = BaseJDBCTest.getConnection();
Statement stmt = con.createStatement()) {
try (Statement stmt = con.createStatement()) {
enforceQueryResultFormat(stmt);
Long[] vector = {-1L, 5L};
try (ResultSet resultSet = stmt.executeQuery("select " + vectorToString(vector, "int"))) {
Expand All @@ -75,8 +89,7 @@ public void testGetIntVectorAsLongArray() throws SQLException {

@Test
public void testGetFloatVectorAsFloatArray() throws SQLException {
try (Connection con = BaseJDBCTest.getConnection();
Statement stmt = con.createStatement()) {
try (Statement stmt = con.createStatement()) {
enforceQueryResultFormat(stmt);
Float[] vector = {-1.2f, 5.1f, 15.87f};
try (ResultSet resultSet = stmt.executeQuery("select " + vectorToString(vector, "float"))) {
Expand All @@ -90,8 +103,7 @@ public void testGetFloatVectorAsFloatArray() throws SQLException {

@Test
public void testGetNullAsIntVector() throws SQLException {
try (Connection con = BaseJDBCTest.getConnection();
Statement stmt = con.createStatement()) {
try (Statement stmt = con.createStatement()) {
enforceQueryResultFormat(stmt);
try (ResultSet resultSet = stmt.executeQuery("select null::vector(int, 2)")) {
assertTrue(resultSet.next());
Expand All @@ -105,8 +117,7 @@ public void testGetNullAsIntVector() throws SQLException {

@Test
public void testGetNullAsFloatVector() throws SQLException {
try (Connection con = BaseJDBCTest.getConnection();
Statement stmt = con.createStatement()) {
try (Statement stmt = con.createStatement()) {
enforceQueryResultFormat(stmt);
try (ResultSet resultSet = stmt.executeQuery("select null::vector(float, 2)")) {
assertTrue(resultSet.next());
Expand All @@ -120,8 +131,7 @@ public void testGetNullAsFloatVector() throws SQLException {

@Test
public void testGetIntVectorFromTable() throws SQLException {
try (Connection con = BaseJDBCTest.getConnection();
Statement stmt = con.createStatement()) {
try (Statement stmt = con.createStatement()) {
enforceQueryResultFormat(stmt);
stmt.execute("create or replace table test_vector_int(x vector(int, 2), y int)");
stmt.execute("insert into test_vector_int select [3, 7]::vector(int, 2), 15");
Expand All @@ -137,8 +147,7 @@ public void testGetIntVectorFromTable() throws SQLException {

@Test
public void testGetFloatVectorFromTable() throws SQLException {
try (Connection con = BaseJDBCTest.getConnection();
Statement stmt = con.createStatement()) {
try (Statement stmt = con.createStatement()) {
enforceQueryResultFormat(stmt);
stmt.execute("create or replace table test_vector_float(x vector(float, 2), y float)");
stmt.execute("insert into test_vector_float select [-3, 7.1]::vector(float, 2), 20.3");
Expand All @@ -154,8 +163,7 @@ public void testGetFloatVectorFromTable() throws SQLException {
/** Added in > 3.16.1 */
@Test
public void testGetVectorViaGetStringIsEqualToTheGetObject() throws SQLException {
try (Connection con = BaseJDBCTest.getConnection();
Statement stmt = con.createStatement()) {
try (Statement stmt = con.createStatement()) {
enforceQueryResultFormat(stmt);
Integer[] intVector = {-1, 5};
Float[] floatVector = {-1.2f, 5.1f, 15.87f};
Expand Down
Loading
Loading