Skip to content
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
7 changes: 0 additions & 7 deletions src/test/java/net/snowflake/client/AbstractDriverIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ public class AbstractDriverIT {

protected final int ERROR_CODE_BIND_VARIABLE_NOT_ALLOWED_IN_VIEW_OR_UDF_DEF = 2210;

protected final int ERROR_CODE_DOMAIN_OBJECT_DOES_NOT_EXIST = 2003;

private static String getConnPropKeyFromEnv(String connectionType, String propKey) {
String envKey = String.format("SNOWFLAKE_%s_%s", connectionType, propKey);
return envKey;
}

private static String getConnPropValueFromEnv(String connectionType, String propKey) {
String envKey = String.format("SNOWFLAKE_%s_%s", connectionType, propKey);
return TestUtil.systemGetEnv(envKey);
Expand Down
22 changes: 10 additions & 12 deletions src/test/java/net/snowflake/client/jdbc/ConnectionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@
@Tag(TestTags.CONNECTION)
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;
private static final int ROLE_IN_CONNECT_STRING_DOES_NOT_EXIST = 390189;
public static final int BAD_REQUEST_GS_CODE = 390400;
public static final int NETWORK_ERROR_CODE = 200015;

public static final int WAIT_FOR_TELEMETRY_REPORT_IN_MILLISECS = 5000;

Expand Down Expand Up @@ -229,7 +226,7 @@ public void testConnectionClientInfo() throws SQLException {
connection.setClientInfo(clientInfo);
});
assertEquals(SqlState.INVALID_PARAMETER_VALUE, e.getSQLState());
assertEquals(200047, e.getErrorCode());
assertEquals(ErrorCode.INVALID_PARAMETER_VALUE.getMessageCode(), e.getErrorCode());
assertEquals(2, e.getFailedProperties().size());

e =
Expand All @@ -239,7 +236,7 @@ public void testConnectionClientInfo() throws SQLException {
connection.setClientInfo("ApplicationName", "valueA");
});
assertEquals(SqlState.INVALID_PARAMETER_VALUE, e.getSQLState());
assertEquals(200047, e.getErrorCode());
assertEquals(ErrorCode.INVALID_PARAMETER_VALUE.getMessageCode(), e.getErrorCode());
assertEquals(1, e.getFailedProperties().size());
}

Expand Down Expand Up @@ -418,13 +415,7 @@ public void testConnectUsingKeyPair() throws Exception {
PublicKey publicKey2 = keyPair.getPublic();
PrivateKey privateKey2 = keyPair.getPrivate();
properties.put("privateKey", privateKey2);
SQLException e =
assertThrows(
SQLException.class,
() -> {
DriverManager.getConnection(uri, properties);
});
assertEquals(390144, e.getErrorCode());
connectExpectingInvalidJWTError(uri, properties);

// test multiple key pair
try (Connection connection = getConnection();
Expand Down Expand Up @@ -929,6 +920,13 @@ public void testFailOverOrgAccount() throws SQLException {
}
}

private void connectExpectingInvalidJWTError(String fullUri, Properties properties) {
SQLException e =
assertThrows(
SQLException.class, () -> DriverManager.getConnection(fullUri, properties).close());
assertEquals(390144, e.getErrorCode());
}

private class ConcurrentConnections implements Runnable {

ConcurrentConnections() {}
Expand Down
27 changes: 5 additions & 22 deletions src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package net.snowflake.client.jdbc;

import static net.snowflake.client.core.SessionUtil.CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY;
import static net.snowflake.client.jdbc.ConnectionIT.BAD_REQUEST_GS_CODE;
import static net.snowflake.client.jdbc.ConnectionIT.INVALID_CONNECTION_INFO_CODE;
import static net.snowflake.client.jdbc.ConnectionIT.NETWORK_ERROR_CODE;
import static net.snowflake.client.jdbc.ConnectionIT.WAIT_FOR_TELEMETRY_REPORT_IN_MILLISECS;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
Expand Down Expand Up @@ -599,21 +595,14 @@ public void testHttpsLoginTimeoutWithOutSSL() throws InterruptedException {

DriverManager.getConnection(wrongUri, properties);
});
assertThat(
"Communication error", e.getErrorCode(), equalTo(ErrorCode.NETWORK_ERROR.getMessageCode()));
if (TelemetryService.getInstance()
.getServerDeploymentName()
.equals(TelemetryService.TELEMETRY_SERVER_DEPLOYMENT.DEV.getName())
|| TelemetryService.getInstance()
.getServerDeploymentName()
.equals(TelemetryService.TELEMETRY_SERVER_DEPLOYMENT.REG.getName())) {
// a connection error response (wrong user and password)
// with status code 200 is returned in RT
assertThat(
"Communication error",
e.getErrorCode(),
anyOf(
equalTo(INVALID_CONNECTION_INFO_CODE),
equalTo(BAD_REQUEST_GS_CODE),
equalTo(NETWORK_ERROR_CODE)));

// since it returns normal response,
// the telemetry does not create new event
Expand All @@ -625,12 +614,6 @@ public void testHttpsLoginTimeoutWithOutSSL() throws InterruptedException {
equalTo(count));
}
} else {
// in qa1 and others, 404 http status code should be returned
assertThat(
"Communication error",
e.getErrorCode(),
equalTo(ErrorCode.NETWORK_ERROR.getMessageCode()));

if (TelemetryService.getInstance().isDeploymentEnabled()) {
assertThat(
"Telemetry event has not been reported successfully. Error: "
Expand Down Expand Up @@ -848,7 +831,7 @@ public void testPrivateKeyInConnectionString() throws SQLException, IOException

privateKeyLocation = getFullPathFileInResource("encrypted_rsa_key.p8");
uri = uriWithPrivateKeyFileAndPassword(baseUri, privateKeyLocation, "test");
connectExpectingError390144(uri, properties);
connectExpectingInvalidJWTError(uri, properties);

// test with invalid private key
privateKeyLocation = getFullPathFileInResource("invalid_private_key.pem");
Expand Down Expand Up @@ -877,7 +860,7 @@ private static String uriWithPrivateKeyFileAndPassword(
+ password;
}

private static void connectExpectingError390144(String fullUri, Properties properties) {
private static void connectExpectingInvalidJWTError(String fullUri, Properties properties) {
SQLException e =
assertThrows(
SQLException.class, () -> DriverManager.getConnection(fullUri, properties).close());
Expand Down Expand Up @@ -963,7 +946,7 @@ public void testPrivateKeyBase64InConnectionString() throws SQLException, IOExce

privateKeyBase64 = readPrivateKeyFileToBase64Content("encrypted_rsa_key.p8");
uri = uriWithPrivateKeyBase64AndPassword(baseUri, privateKeyBase64, "test");
connectExpectingError390144(uri, properties);
connectExpectingInvalidJWTError(uri, properties);

// test with invalid private key
privateKeyBase64 = readPrivateKeyFileToBase64Content("invalid_private_key.pem");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import net.snowflake.client.core.OCSPMode;
import net.snowflake.common.core.SqlState;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

Expand Down Expand Up @@ -78,8 +79,8 @@ public void testProcessFileNamesException() {
assertThrows(
SnowflakeSQLException.class,
() -> SnowflakeFileTransferAgent.expandFileNames(locations, null));
assertEquals(200007, err.getErrorCode());
assertEquals("22000", err.getSQLState());
assertEquals(ErrorCode.FAIL_LIST_FILES.getMessageCode(), err.getErrorCode());
assertEquals(SqlState.DATA_EXCEPTION, err.getSQLState());
SnowflakeFileTransferAgent.setInjectedFileTransferException(null);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.snowflake.client.jdbc;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -99,7 +100,7 @@ public void testExecuteLessBindings(String queryResultFormat) throws Exception {
// first statement
SQLException e =
assertThrows(SQLException.class, () -> preparedStatement.executeUpdate());
assertThat(e.getErrorCode(), is(100132));
assertThat(e.getMessage(), containsString("Bind variable ? not set"));
}
} finally {
statement.execute("drop table if exists test_multi_bind");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ public void testPrepareUDTF(String queryResultFormat) throws Exception {
connection.prepareStatement("select * from table(employee_detail(?, 123))"); ) {
// second argument is invalid
prepStatement.setInt(1, 1);
SQLException e = assertThrows(SQLException.class, prepStatement::execute);
// failed because argument type did not match
assertThat(e.getErrorCode(), is(1044));
assertThrows(SQLException.class, prepStatement::execute);
}

// create a udf with same name but different arguments and return type
Expand Down
36 changes: 18 additions & 18 deletions src/test/java/net/snowflake/client/jdbc/ResultSetIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void testGetShort(String queryResultFormat) throws SQLException {
int finalI = i;
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getShort(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
assertTrue(resultSet.next());
// certain column types can only have certain values when called by getShort() or else a
Expand All @@ -193,7 +193,7 @@ public void testGetShort(String queryResultFormat) throws SQLException {
int finalI = i;
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getShort(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ public void testGetInt(String queryResultFormat) throws SQLException {
int finalI = i;
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getInt(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
assertTrue(resultSet.next());
// certain column types can only have certain values when called by getInt() or else a
Expand All @@ -231,7 +231,7 @@ public void testGetInt(String queryResultFormat) throws SQLException {
int finalI = i;
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getInt(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ public void testGetLong(String queryResultFormat) throws SQLException {
int finalI = i;
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getLong(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
assertTrue(resultSet.next());
// certain column types can only have certain values when called by getLong() or else a
Expand All @@ -269,7 +269,7 @@ public void testGetLong(String queryResultFormat) throws SQLException {
int finalI = i;
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getLong(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
}
}
Expand Down Expand Up @@ -297,7 +297,7 @@ public void testGetFloat(String queryResultFormat) throws SQLException {
int finalI = i;
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getFloat(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
assertTrue(resultSet.next());
// certain column types can only have certain values when called by getFloat() or else a
Expand All @@ -307,7 +307,7 @@ public void testGetFloat(String queryResultFormat) throws SQLException {
int finalI = i;
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getFloat(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
}
}
Expand Down Expand Up @@ -335,7 +335,7 @@ public void testGetDouble(String queryResultFormat) throws SQLException {
int finalI = i;
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getDouble(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
assertTrue(resultSet.next());
// certain column types can only have certain values when called by getDouble() or else a
Expand All @@ -345,7 +345,7 @@ public void testGetDouble(String queryResultFormat) throws SQLException {
int finalI = i;
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getDouble(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
}
}
Expand Down Expand Up @@ -393,15 +393,15 @@ public void testGetBigDecimal(String queryResultFormat) throws SQLException {
SQLException ex =
assertThrows(
SQLException.class, () -> resultSet.getBigDecimal(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
assertTrue(resultSet.next());
for (int i = 5; i < 7; i++) {
int finalI = i;
SQLException ex =
assertThrows(
SQLException.class, () -> resultSet.getBigDecimal(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
}
}
Expand All @@ -423,7 +423,7 @@ public void testGetBigDecimalNegative(String queryResultFormat) throws SQLExcept
assertTrue(resultSet.next());
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getBigDecimal(2, 38));
assertEquals(200032, ex.getErrorCode());
assertEquals(ErrorCode.COLUMN_DOES_NOT_EXIST.getMessageCode(), ex.getErrorCode());
}
}
} finally {
Expand Down Expand Up @@ -701,7 +701,7 @@ public void testGetBoolean(String queryResultFormat) throws SQLException {
SQLException ex =
assertThrows(
SQLException.class, () -> resultSet.getBoolean(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}

assertTrue(resultSet.next());
Expand All @@ -710,7 +710,7 @@ public void testGetBoolean(String queryResultFormat) throws SQLException {
SQLException ex =
assertThrows(
SQLException.class, () -> resultSet.getBoolean(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}
}
}
Expand Down Expand Up @@ -842,9 +842,9 @@ public void testInvalidColumnIndex(String queryResultFormat) throws SQLException

assertTrue(resultSet.next());
SQLException e = assertThrows(SQLException.class, () -> resultSet.getString(0));
assertEquals(200032, e.getErrorCode());
assertEquals(ErrorCode.COLUMN_DOES_NOT_EXIST.getMessageCode(), e.getErrorCode());
e = assertThrows(SQLException.class, () -> resultSet.getString(2));
assertEquals(200032, e.getErrorCode());
assertEquals(ErrorCode.COLUMN_DOES_NOT_EXIST.getMessageCode(), e.getErrorCode());
}
}

Expand Down Expand Up @@ -1011,7 +1011,7 @@ public void testNextNegative(String queryResultFormat) throws SQLException {
assertTrue(rs.next());
System.setProperty("snowflake.enable_incident_test2", "true");
SQLException ex = assertThrows(SQLException.class, rs::next);
assertEquals(200014, ex.getErrorCode());
assertEquals(ErrorCode.MAX_RESULT_LIMIT_EXCEEDED.getMessageCode(), ex.getErrorCode());
System.setProperty("snowflake.enable_incident_test2", "false");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public void testBytesCrossTypeTests(String queryResultFormat) throws Exception {
int finalI = i;
SQLException ex =
assertThrows(SQLException.class, () -> resultSet.getBytes(finalI), "Failing on " + i);
assertEquals(200038, ex.getErrorCode());
assertEquals(ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(), ex.getErrorCode());
}

byte[] decoded = SFBinary.fromHex("48454C4C4F").getBytes();
Expand Down
15 changes: 2 additions & 13 deletions src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1888,22 +1888,11 @@ public void testNullBind() throws Throwable {

preparedStatement.clearBatch();

// this test causes query count in GS not to be decremented because
// the exception is thrown before registerQC. Discuss with Johnston
// to resolve the issue before enabling the test.
preparedStatement.setObject(1, "Null", Types.DOUBLE);
preparedStatement.addBatch();
SnowflakeSQLException ex =
assertThrows(SnowflakeSQLException.class, preparedStatement::executeBatch);
assertEquals(2086, ex.getErrorCode());

preparedStatement.clearBatch();

preparedStatement.setString(1, "hello");
preparedStatement.addBatch();

preparedStatement.setDouble(1, 1.2);
ex = assertThrows(SnowflakeSQLException.class, preparedStatement::addBatch);
SnowflakeSQLException ex =
assertThrows(SnowflakeSQLException.class, preparedStatement::addBatch);
assertEquals(
(int) ErrorCode.ARRAY_BIND_MIXED_TYPES_NOT_SUPPORTED.getMessageCode(),
ex.getErrorCode());
Expand Down
Loading