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-4 #1817

Merged
merged 15 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -21,7 +21,7 @@
* @author azhan attempts to test the CLIENT_MEMORY_LIMIT working in multi-threading
*/
@Category(TestCategoryOthers.class)
public class ClientMemoryLimitParallelIT {
public class ClientMemoryLimitParallelIT extends BaseJDBCWithSharedConnectionIT {
private static Logger LOGGER =
LoggerFactory.getLogger(ClientMemoryLimitParallelIT.class.getName());

Expand Down Expand Up @@ -64,16 +64,14 @@ public class ClientMemoryLimitParallelIT {

@Before
public void setUp() throws SQLException {
try (Connection con = getConnection();
Statement statement = con.createStatement()) {
try (Statement statement = connection.createStatement()) {
statement.execute(createTestTableSQL);
}
}

@After
public void tearDown() throws SQLException {
try (Connection con = getConnection();
Statement statement = con.createStatement()) {
try (Statement statement = connection.createStatement()) {
statement.execute("drop table if exists testtable_cml");
}
}
Expand Down Expand Up @@ -126,8 +124,7 @@ public void run() {
@Test
public void testQueryNotHanging() throws SQLException {
Properties paramProperties = new Properties();
try (Connection connection = getConnection(paramProperties);
Statement statement = connection.createStatement()) {
try (Statement statement = connection.createStatement()) {
queryRows(statement, 100, 160);
}
}
Expand Down
102 changes: 46 additions & 56 deletions src/test/java/net/snowflake/client/jdbc/ConnectionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

/** Connection integration tests */
@Category(TestCategoryConnection.class)
public class ConnectionIT extends BaseJDBCTest {
public class ConnectionIT extends BaseJDBCWithSharedConnectionIT {
// create a local constant for this code for testing purposes (already defined in GS)
public static final int INVALID_CONNECTION_INFO_CODE = 390100;
private static final int SESSION_CREATION_OBJECT_DOES_NOT_EXIST_NOT_AUTHORIZED = 390201;
Expand Down Expand Up @@ -90,10 +90,9 @@ public void testSimpleConnection() throws SQLException {
public void test300ConnectionsWithSingleClientInstance() throws SQLException {
// concurrent testing
int size = 300;
try (Connection con = getConnection();
Statement statement = con.createStatement()) {
String database = con.getCatalog();
String schema = con.getSchema();
try (Statement statement = connection.createStatement()) {
String database = connection.getCatalog();
String schema = connection.getSchema();
statement.execute(
"create or replace table bigTable(rowNum number,rando "
+ "number) as (select seq4(),"
Expand Down Expand Up @@ -168,8 +167,7 @@ public void testProdConnectivity() throws SQLException {

@Test
public void testSetCatalogSchema() throws Throwable {
try (Connection connection = getConnection();
Statement statement = connection.createStatement()) {
try (Statement statement = connection.createStatement()) {
String db = connection.getCatalog();
String schema = connection.getSchema();
connection.setCatalog(db);
Expand Down Expand Up @@ -220,31 +218,30 @@ public void testDataCompletenessInLowMemory() throws Exception {
public void testConnectionGetAndSetDBAndSchema() throws SQLException {
final String SECOND_DATABASE = "SECOND_DATABASE";
final String SECOND_SCHEMA = "SECOND_SCHEMA";
try (Connection con = getConnection();
Statement statement = con.createStatement()) {
try (Statement statement = connection.createStatement()) {
try {
final String database = TestUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE").toUpperCase();
final String schema = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA").toUpperCase();

assertEquals(database, con.getCatalog());
assertEquals(schema, con.getSchema());
assertEquals(database, connection.getCatalog());
assertEquals(schema, connection.getSchema());

statement.execute(String.format("create or replace database %s", SECOND_DATABASE));
statement.execute(String.format("create or replace schema %s", SECOND_SCHEMA));
statement.execute(String.format("use database %s", database));

con.setCatalog(SECOND_DATABASE);
assertEquals(SECOND_DATABASE, con.getCatalog());
assertEquals("PUBLIC", con.getSchema());
connection.setCatalog(SECOND_DATABASE);
assertEquals(SECOND_DATABASE, connection.getCatalog());
assertEquals("PUBLIC", connection.getSchema());

con.setSchema(SECOND_SCHEMA);
assertEquals(SECOND_SCHEMA, con.getSchema());
connection.setSchema(SECOND_SCHEMA);
assertEquals(SECOND_SCHEMA, connection.getSchema());

statement.execute(String.format("use database %s", database));
statement.execute(String.format("use schema %s", schema));

assertEquals(database, con.getCatalog());
assertEquals(schema, con.getSchema());
assertEquals(database, connection.getCatalog());
assertEquals(schema, connection.getSchema());
} finally {
statement.execute(String.format("drop database if exists %s", SECOND_DATABASE));
}
Expand All @@ -253,40 +250,39 @@ public void testConnectionGetAndSetDBAndSchema() throws SQLException {

@Test
public void testConnectionClientInfo() throws SQLException {
try (Connection con = getConnection()) {
Properties property = con.getClientInfo();
assertEquals(0, property.size());
Properties clientInfo = new Properties();
clientInfo.setProperty("name", "Peter");
clientInfo.setProperty("description", "SNOWFLAKE JDBC");
try {
con.setClientInfo(clientInfo);
fail("setClientInfo should fail for any parameter.");
} catch (SQLClientInfoException e) {
assertEquals(SqlState.INVALID_PARAMETER_VALUE, e.getSQLState());
assertEquals(200047, e.getErrorCode());
assertEquals(2, e.getFailedProperties().size());
}
try {
con.setClientInfo("ApplicationName", "valueA");
fail("setClientInfo should fail for any parameter.");
} catch (SQLClientInfoException e) {
assertEquals(SqlState.INVALID_PARAMETER_VALUE, e.getSQLState());
assertEquals(200047, e.getErrorCode());
assertEquals(1, e.getFailedProperties().size());
}
Properties property = connection.getClientInfo();
assertEquals(0, property.size());
Properties clientInfo = new Properties();
clientInfo.setProperty("name", "Peter");
clientInfo.setProperty("description", "SNOWFLAKE JDBC");
try {
connection.setClientInfo(clientInfo);
fail("setClientInfo should fail for any parameter.");
} catch (SQLClientInfoException e) {
assertEquals(SqlState.INVALID_PARAMETER_VALUE, e.getSQLState());
assertEquals(200047, e.getErrorCode());
assertEquals(2, e.getFailedProperties().size());
}
try {
connection.setClientInfo("ApplicationName", "valueA");
fail("setClientInfo should fail for any parameter.");
} catch (SQLClientInfoException e) {
assertEquals(SqlState.INVALID_PARAMETER_VALUE, e.getSQLState());
assertEquals(200047, e.getErrorCode());
assertEquals(1, e.getFailedProperties().size());
}
}

// only support get and set
@Test
public void testNetworkTimeout() throws SQLException {
try (Connection con = getConnection()) {
int millis = con.getNetworkTimeout();
assertEquals(0, millis);
con.setNetworkTimeout(null, 200);
assertEquals(200, con.getNetworkTimeout());
}
int millis = connection.getNetworkTimeout();
assertEquals(0, millis);
connection.setNetworkTimeout(null, 200);
assertEquals(200, connection.getNetworkTimeout());
// Reset timeout to 0 since we are reusing connection in tests
connection.setNetworkTimeout(null, 0);
assertEquals(0, millis);
}

@Test
Expand Down Expand Up @@ -725,18 +721,14 @@ public void testHeartbeatFrequencyTooLarge() throws Exception {

@Test
public void testNativeSQL() throws Throwable {
try (Connection connection = getConnection()) {
// today returning the source SQL.
assertEquals("select 1", connection.nativeSQL("select 1"));
}
// today returning the source SQL.
assertEquals("select 1", connection.nativeSQL("select 1"));
}

@Test
public void testGetTypeMap() throws Throwable {
try (Connection connection = getConnection()) {
// return an empty type map. setTypeMap is not supported.
assertEquals(Collections.emptyMap(), connection.getTypeMap());
}
// return an empty type map. setTypeMap is not supported.
assertEquals(Collections.emptyMap(), connection.getTypeMap());
}

@Test
Expand Down Expand Up @@ -829,7 +821,6 @@ public void testReadDateAfterSplittingResultSet() throws Exception {

@Test
public void testResultSetsClosedByStatement() throws SQLException {
Connection connection = getConnection();
Statement statement2 = connection.createStatement();
ResultSet rs1 = statement2.executeQuery("select 2;");
ResultSet rs2 = statement2.executeQuery("select 2;");
Expand All @@ -846,7 +837,6 @@ public void testResultSetsClosedByStatement() throws SQLException {
assertTrue(rs2.isClosed());
assertTrue(rs3.isClosed());
assertTrue(rs4.isClosed());
connection.close();
}

@Test
Expand Down
Loading
Loading