Skip to content

Commit

Permalink
SNOW-1356389: Use junit assertions instead of jvm assert in tests (#1743
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sfc-gh-dprzybysz committed Apr 30, 2024
1 parent 6f7a6b7 commit 9e1c486
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testParameterParsing() {
parameterMap.put("other_parameter", BooleanNode.getTrue());
SFBaseSession session = new MockConnectionTest.MockSnowflakeConnectionImpl().getSFSession();
SessionUtil.updateSfDriverParamValues(parameterMap, session);
assert (((BooleanNode) session.getOtherParameter("other_parameter")).asBoolean());
assertTrue(((BooleanNode) session.getOtherParameter("other_parameter")).asBoolean());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public PasswordAuthentication getPasswordAuthentication() {

// Make sure that the downloaded file exists, it should be gzip compressed
File downloaded = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE + ".gz");
assert (downloaded.exists());
assertTrue(downloaded.exists());

Process p =
Runtime.getRuntime()
Expand All @@ -750,7 +750,7 @@ public PasswordAuthentication getPasswordAuthentication() {

File original = new File(sourceFilePath);
File unzipped = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE);
assert (original.length() == unzipped.length());
assertEquals(original.length(), unzipped.length());
} catch (Throwable t) {
t.printStackTrace();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package net.snowflake.client.jdbc;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
Expand Down Expand Up @@ -114,15 +115,14 @@ public int read() throws IOException {
SnowflakeFileTransferConfig config = builder.build();

// Assert setting fields are in config
assert (config.getSnowflakeFileTransferMetadata() == metadata);
assert (config.getUploadStream() == input);
assert (config.getOcspMode() == OCSPMode.FAIL_CLOSED);
assert (!config.getRequireCompress());
assert (config.getNetworkTimeoutInMilli() == 12345);
assert (config.getProxyProperties() == props);
assert (config.getPrefix().equals("dummy_prefix"));
assert (config.getDestFileName().equals("dummy_dest_file_name"));

assertEquals(metadata, config.getSnowflakeFileTransferMetadata());
assertEquals(input, config.getUploadStream());
assertEquals(OCSPMode.FAIL_CLOSED, config.getOcspMode());
assertFalse(config.getRequireCompress());
assertEquals(12345, config.getNetworkTimeoutInMilli());
assertEquals(props, config.getProxyProperties());
assertEquals("dummy_prefix", config.getPrefix());
assertEquals("dummy_dest_file_name", config.getDestFileName());
assertEquals(expectedThrowCount, throwCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package net.snowflake.client.jdbc;

import static org.junit.Assert.assertNotNull;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -88,7 +90,7 @@ private static void connectAndQuery(int num_queries) throws SQLException {
try (ResultSet resultSet = statement.executeQuery(QUERY)) {
while (resultSet.next()) {
final String user = resultSet.getString(1);
assert user != null;
assertNotNull(user);
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public void testPutWithWildcardGCP() throws Throwable {
for (int i = 0; i < fileNames.length; i++) {
// Make sure that the downloaded file exists, it should be gzip compressed
downloaded = new File(destFolderCanonicalPathWithSeparator + fileNames[i] + ".gz");
assert (downloaded.exists());
assertTrue(downloaded.exists());

Process p =
Runtime.getRuntime()
Expand All @@ -780,8 +780,8 @@ public void testPutWithWildcardGCP() throws Throwable {

File original = new File(individualFilePath);
File unzipped = new File(destFolderCanonicalPathWithSeparator + fileNames[i]);
assert (original.length() == unzipped.length());
assert (FileUtils.contentEquals(original, unzipped));
assertEquals(original.length(), unzipped.length());
assertTrue(FileUtils.contentEquals(original, unzipped));
}
} finally {
statement.execute("DROP STAGE IF EXISTS wildcard_stage");
Expand Down Expand Up @@ -862,7 +862,7 @@ public void testPutGetLargeFileGCP() throws Throwable {

// Make sure that the downloaded file exists; it should be gzip compressed
File downloaded = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv.gz");
assert (downloaded.exists());
assertTrue(downloaded.exists());

// unzip the file
Process p =
Expand All @@ -874,8 +874,8 @@ public void testPutGetLargeFileGCP() throws Throwable {
// back into a stage,
// downloaded, and unzipped
File unzipped = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv");
assert (largeTempFile.length() == unzipped.length());
assert (FileUtils.contentEquals(largeTempFile, unzipped));
assertEquals(largeTempFile.length(), unzipped.length());
assertTrue(FileUtils.contentEquals(largeTempFile, unzipped));
} finally {
statement.execute("DROP STAGE IF EXISTS largefile_stage");
statement.execute("DROP STAGE IF EXISTS extra_stage");
Expand Down Expand Up @@ -937,7 +937,7 @@ public void testPutOverwrite() throws Throwable {

// Make sure that the downloaded file exists; it should be gzip compressed
File downloaded = new File(destFolderCanonicalPathWithSeparator + "testfile.csv.gz");
assert (downloaded.exists());
assertTrue(downloaded.exists());

// unzip the file
Process p =
Expand All @@ -946,7 +946,7 @@ public void testPutOverwrite() throws Throwable {
p.waitFor();

File unzipped = new File(destFolderCanonicalPathWithSeparator + "testfile.csv");
assert (FileUtils.contentEqualsIgnoreEOL(file2, unzipped, null));
assertTrue(FileUtils.contentEqualsIgnoreEOL(file2, unzipped, null));
} finally {
statement.execute("DROP TABLE IF EXISTS testLoadToLocalFS");
}
Expand Down Expand Up @@ -2695,7 +2695,7 @@ public void testPutGet() throws Throwable {

// Make sure that the downloaded file exists, it should be gzip compressed
File downloaded = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE + ".gz");
assert (downloaded.exists());
assertTrue(downloaded.exists());

Process p =
Runtime.getRuntime()
Expand All @@ -2704,7 +2704,7 @@ public void testPutGet() throws Throwable {

File original = new File(sourceFilePath);
File unzipped = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE);
assert (original.length() == unzipped.length());
assertEquals(original.length(), unzipped.length());
} finally {
statement.execute("DROP STAGE IF EXISTS testGetPut_stage");
}
Expand Down Expand Up @@ -2754,7 +2754,7 @@ public void testPutGetToUnencryptedStage() throws Throwable {

// Make sure that the downloaded file exists, it should be gzip compressed
File downloaded = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE + ".gz");
assert (downloaded.exists());
assertTrue(downloaded.exists());

Process p =
Runtime.getRuntime()
Expand All @@ -2763,7 +2763,7 @@ public void testPutGetToUnencryptedStage() throws Throwable {

File original = new File(sourceFilePath);
File unzipped = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE);
assert (original.length() == unzipped.length());
assertEquals(original.length(), unzipped.length());
} finally {
statement.execute("DROP STAGE IF EXISTS testPutGet_unencstage");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void testGCPFileTransferMetadataWithOneFile() throws Throwable {
for (SnowflakeFileTransferMetadata oneMetadata : metadatas1) {
InputStream inputStream = new FileInputStream(srcPath1);

assert (oneMetadata.isForOneFile());
assertTrue(oneMetadata.isForOneFile());
SnowflakeFileTransferAgent.uploadWithoutConnection(
SnowflakeFileTransferConfig.Builder.newInstance()
.setSnowflakeFileTransferMetadata(oneMetadata)
Expand Down Expand Up @@ -252,7 +252,7 @@ public void testGCPFileTransferMetadataWithOneFile() throws Throwable {
p.waitFor();

InputStream gzInputStream = new FileInputStream(gzfilePath);
assert (oneMetadata.isForOneFile());
assertTrue(oneMetadata.isForOneFile());
SnowflakeFileTransferAgent.uploadWithoutConnection(
SnowflakeFileTransferConfig.Builder.newInstance()
.setSnowflakeFileTransferMetadata(oneMetadata)
Expand All @@ -271,8 +271,10 @@ public void testGCPFileTransferMetadataWithOneFile() throws Throwable {

// Make sure that the downloaded files are EQUAL,
// they should be gzip compressed
assert (isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true));
assert (isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true));
assertTrue(
isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true));
assertTrue(
isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true));
} finally {
statement.execute("DROP STAGE if exists " + testStageName);
}
Expand Down Expand Up @@ -360,8 +362,10 @@ public void testAzureS3FileTransferMetadataWithOneFile() throws Throwable {

// Make sure that the downloaded files are EQUAL,
// they should be gzip compressed
assert (isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true));
assert (isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true));
assertTrue(
isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true));
assertTrue(
isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true));
} finally {
statement.execute("DROP STAGE if exists " + testStageName);
}
Expand Down Expand Up @@ -1057,7 +1061,7 @@ private void putAndGetFile(Statement statement) throws Throwable {

// Make sure that the downloaded file exists, it should be gzip compressed
File downloaded = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE_2 + ".gz");
assert (downloaded.exists());
assertTrue(downloaded.exists());

Process p =
Runtime.getRuntime()
Expand All @@ -1070,7 +1074,7 @@ private void putAndGetFile(Statement statement) throws Throwable {
"Original file: " + original.getAbsolutePath() + ", size: " + original.length());
System.out.println(
"Unzipped file: " + unzipped.getAbsolutePath() + ", size: " + unzipped.length());
assert (original.length() == unzipped.length());
assertEquals(original.length(), unzipped.length());
} finally {
statement.execute("DROP STAGE IF EXISTS testGetPut_stage");
}
Expand Down Expand Up @@ -1137,7 +1141,7 @@ public void testPutGetLargeFileGCSDownscopedCredential() throws Throwable {

// Make sure that the downloaded file exists; it should be gzip compressed
File downloaded = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv.gz");
assert (downloaded.exists());
assertTrue(downloaded.exists());

// unzip the file
Process p =
Expand All @@ -1149,8 +1153,8 @@ public void testPutGetLargeFileGCSDownscopedCredential() throws Throwable {
// back into a stage,
// downloaded, and unzipped
File unzipped = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv");
assert (largeTempFile.length() == unzipped.length());
assert (FileUtils.contentEquals(largeTempFile, unzipped));
assertEquals(largeTempFile.length(), unzipped.length());
assertTrue(FileUtils.contentEquals(largeTempFile, unzipped));
} finally {
statement.execute("DROP STAGE IF EXISTS largefile_stage");
statement.execute("DROP STAGE IF EXISTS extra_stage");
Expand Down Expand Up @@ -1213,7 +1217,7 @@ public void testPutGetLargeFileAzure() throws Throwable {

// Make sure that the downloaded file exists; it should be gzip compressed
File downloaded = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv.gz");
assert (downloaded.exists());
assertTrue(downloaded.exists());

// unzip the file
Process p =
Expand All @@ -1225,8 +1229,8 @@ public void testPutGetLargeFileAzure() throws Throwable {
// back into a stage,
// downloaded, and unzipped
File unzipped = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv");
assert (largeTempFile.length() == unzipped.length());
assert (FileUtils.contentEquals(largeTempFile, unzipped));
assertEquals(largeTempFile.length(), unzipped.length());
assertTrue(FileUtils.contentEquals(largeTempFile, unzipped));
} finally {
statement.execute("DROP STAGE IF EXISTS largefile_stage");
statement.execute("DROP STAGE IF EXISTS extra_stage");
Expand Down Expand Up @@ -1349,8 +1353,10 @@ public void testPutS3RegionalUrl() throws Throwable {

// Make sure that the downloaded files are EQUAL,
// they should be gzip compressed
assert (isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true));
assert (isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true));
assertTrue(
isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true));
assertTrue(
isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true));
} finally {
statement.execute("DROP STAGE if exists " + testStageName);
}
Expand Down Expand Up @@ -1489,7 +1495,7 @@ public void testUploadWithGCSPresignedUrlWithoutConnection() throws Throwable {
for (SnowflakeFileTransferMetadata oneMetadata : metadata) {
InputStream inputStream = new FileInputStream(srcPath);

assert (oneMetadata.isForOneFile());
assertTrue(oneMetadata.isForOneFile());
SnowflakeFileTransferAgent.uploadWithoutConnection(
SnowflakeFileTransferConfig.Builder.newInstance()
.setSnowflakeFileTransferMetadata(oneMetadata)
Expand All @@ -1504,7 +1510,7 @@ public void testUploadWithGCSPresignedUrlWithoutConnection() throws Throwable {
"Failed to get files",
statement.execute(
"GET @" + testStageName + " 'file://" + destFolderCanonicalPath + "/' parallel=8"));
assert (isFileContentEqual(srcPath, false, destFolderCanonicalPath + "/file1.gz", true));
assertTrue(isFileContentEqual(srcPath, false, destFolderCanonicalPath + "/file1.gz", true));
} finally {
statement.execute("DROP STAGE if exists " + testStageName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void testCopyAndUpload() throws Exception {
// Make sure that the downloaded file exists, it should be gzip compressed
File downloaded =
new File(tempFolder.getCanonicalPath() + File.separator + fileName + ".gz");
assert (downloaded.exists());
assertTrue(downloaded.exists());
}
// unzip the new file
Process p =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void testTransactionStatement() throws SQLException {
PooledConnection pooledConnection = poolDataSource.getPooledConnection();
try (Connection logicalConnection = pooledConnection.getConnection()) {
logicalConnection.setAutoCommit(false);
assert (!logicalConnection.getAutoCommit());
assertFalse(logicalConnection.getAutoCommit());
logicalConnection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
assertEquals(2, logicalConnection.getTransactionIsolation());

Expand Down

0 comments on commit 9e1c486

Please sign in to comment.