Skip to content

Commit

Permalink
Refactored result set serializable tests from inheritance to paramete…
Browse files Browse the repository at this point in the history
…rization
  • Loading branch information
sfc-gh-astachowski committed Nov 5, 2024
1 parent 31023c4 commit 4a97907
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 80 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import javax.annotation.Nullable;
import net.snowflake.client.annotations.DontRunOnGithubActions;
import net.snowflake.client.category.TestTags;
import net.snowflake.client.providers.SimpleFormatProvider;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;

/** SnowflakeResultSetSerializable tests */
// @Category(TestCategoryResultSet.class)
Expand All @@ -35,25 +38,16 @@ public class SnowflakeResultSetSerializableIT extends BaseJDBCTest {

private static boolean developPrint = false;

private String queryResultFormat;

// sfFullURL is used to support private link URL.
// This test case is not for private link env, so just use a valid URL for testing purpose.
private String sfFullURL = "https://sfctest0.snowflakecomputing.com";

public SnowflakeResultSetSerializableIT() {
this("json");
}

SnowflakeResultSetSerializableIT(String format) {
queryResultFormat = format;
public Connection init(String queryResultFormat) throws SQLException {
return init(null, queryResultFormat);
}

public Connection init() throws SQLException {
return init(null);
}

public Connection init(@Nullable Properties properties) throws SQLException {
public Connection init(@Nullable Properties properties, String queryResultFormat)
throws SQLException {
Connection conn = BaseJDBCTest.getConnection(properties);
try (Statement stmt = conn.createStatement()) {
stmt.execute("alter session set jdbc_query_result_format = '" + queryResultFormat + "'");
Expand Down Expand Up @@ -237,11 +231,16 @@ private String deserializeResultSetWithProperties(List<String> files, Properties
* @throws Throwable If any error happens.
*/
private void testBasicTableHarness(
int rowCount, long maxSizeInBytes, String whereClause, boolean needSetupTable, boolean async)
int rowCount,
long maxSizeInBytes,
String whereClause,
boolean needSetupTable,
boolean async,
String queryResultFormat)
throws Throwable {
List<String> fileNameList = null;
String originalResultCSVString = null;
try (Connection connection = init()) {
try (Connection connection = init(queryResultFormat)) {
Statement statement = connection.createStatement();

if (developPrint) {
Expand Down Expand Up @@ -288,57 +287,61 @@ private void testBasicTableHarness(
assertEquals(chunkResultString, originalResultCSVString);
}

@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@DontRunOnGithubActions
public void testBasicTableWithEmptyResult() throws Throwable {
public void testBasicTableWithEmptyResult(String queryResultFormat) throws Throwable {
// Use complex WHERE clause in order to test both ARROW and JSON.
// It looks GS only generates JSON format result.
testBasicTableHarness(10, 1024, "where int_c * int_c = 2", true, false);
testBasicTableHarness(10, 1024, "where int_c * int_c = 2", true, false, queryResultFormat);
// Test Async mode
testBasicTableHarness(10, 1024, "where int_c * int_c = 2", true, true);
testBasicTableHarness(10, 1024, "where int_c * int_c = 2", true, true, queryResultFormat);
}

@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@DontRunOnGithubActions
public void testBasicTableWithOnlyFirstChunk() throws Throwable {
public void testBasicTableWithOnlyFirstChunk(String queryResultFormat) throws Throwable {
// Result only includes first data chunk, test maxSize is small.
testBasicTableHarness(1, 1, "", true, false);
testBasicTableHarness(1, 1, "", true, false, queryResultFormat);
// Test Async mode
testBasicTableHarness(1, 1, "", true, true);
testBasicTableHarness(1, 1, "", true, true, queryResultFormat);
// Result only includes first data chunk, test maxSize is big.
testBasicTableHarness(1, 1024 * 1024, "", false, false);
testBasicTableHarness(1, 1024 * 1024, "", false, false, queryResultFormat);
// Test async mode
testBasicTableHarness(1, 1024 * 1024, "", false, true);
testBasicTableHarness(1, 1024 * 1024, "", false, true, queryResultFormat);
}

@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@DontRunOnGithubActions
public void testBasicTableWithOneFileChunk() throws Throwable {
public void testBasicTableWithOneFileChunk(String queryResultFormat) throws Throwable {
// Result only includes first data chunk, test maxSize is small.
testBasicTableHarness(300, 1, "", true, false);
testBasicTableHarness(300, 1, "", true, false, queryResultFormat);
// Test Async mode
testBasicTableHarness(300, 1, "", true, true);
testBasicTableHarness(300, 1, "", true, true, queryResultFormat);
// Result only includes first data chunk, test maxSize is big.
testBasicTableHarness(300, 1024 * 1024, "", false, false);
testBasicTableHarness(300, 1024 * 1024, "", false, false, queryResultFormat);
// Test Async mode
testBasicTableHarness(300, 1024 * 1024, "", false, true);
testBasicTableHarness(300, 1024 * 1024, "", false, true, queryResultFormat);
}

@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@DontRunOnGithubActions
public void testBasicTableWithSomeFileChunks() throws Throwable {
public void testBasicTableWithSomeFileChunks(String queryResultFormat) throws Throwable {
// Result only includes first data chunk, test maxSize is small.
testBasicTableHarness(90000, 1, "", true, false);
testBasicTableHarness(90000, 1, "", true, false, queryResultFormat);
// Test Async mode
testBasicTableHarness(90000, 1, "", true, true);
testBasicTableHarness(90000, 1, "", true, true, queryResultFormat);
// Result only includes first data chunk, test maxSize is median.
testBasicTableHarness(90000, 3 * 1024 * 1024, "", false, false);
testBasicTableHarness(90000, 3 * 1024 * 1024, "", false, false, queryResultFormat);
// Test Async mode
testBasicTableHarness(90000, 3 * 1024 * 1024, "", false, true);
testBasicTableHarness(90000, 3 * 1024 * 1024, "", false, true, queryResultFormat);
// Result only includes first data chunk, test maxSize is big.
testBasicTableHarness(90000, 100 * 1024 * 1024, "", false, false);
testBasicTableHarness(90000, 100 * 1024 * 1024, "", false, false, queryResultFormat);
// Test Async mode
testBasicTableHarness(90000, 100 * 1024 * 1024, "", false, true);
testBasicTableHarness(90000, 100 * 1024 * 1024, "", false, true, queryResultFormat);
}

/**
Expand All @@ -364,11 +367,12 @@ private void testTimestampHarness(
String format_ntz,
String format_ltz,
String format_tz,
String timezone)
String timezone,
String queryResultFormat)
throws Throwable {
List<String> fileNameList = null;
String originalResultCSVString = null;
try (Connection connection = init();
try (Connection connection = init(queryResultFormat);
Statement statement = connection.createStatement()) {
statement.execute("alter session set DATE_OUTPUT_FORMAT = '" + format_date + "'");
statement.execute("alter session set TIME_OUTPUT_FORMAT = '" + format_time + "'");
Expand Down Expand Up @@ -418,9 +422,10 @@ private void testTimestampHarness(
assertEquals(chunkResultString, originalResultCSVString);
}

@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@DontRunOnGithubActions
public void testTimestamp() throws Throwable {
public void testTimestamp(String queryResultFormat) throws Throwable {
String[] dateFormats = {"YYYY-MM-DD", "DD-MON-YYYY", "MM/DD/YYYY"};
String[] timeFormats = {"HH24:MI:SS.FFTZH:TZM", "HH24:MI:SS.FF", "HH24:MI:SS"};
String[] timestampFormats = {
Expand All @@ -440,16 +445,19 @@ public void testTimestamp() throws Throwable {
timestampFormats[i],
timestampFormats[i],
timestampFormats[i],
timezones[i]);
timezones[i],
queryResultFormat);
}
}

@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@DontRunOnGithubActions
public void testBasicTableWithSerializeObjectsAfterReadResultSet() throws Throwable {
public void testBasicTableWithSerializeObjectsAfterReadResultSet(String queryResultFormat)
throws Throwable {
List<String> fileNameList = null;
String originalResultCSVString = null;
try (Connection connection = init();
try (Connection connection = init(queryResultFormat);
Statement statement = connection.createStatement()) {
statement.execute("create or replace schema testschema");

Expand Down Expand Up @@ -527,13 +535,14 @@ private synchronized List<String> splitResultSetSerializables(
return resultFileList;
}

@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@DontRunOnGithubActions
public void testSplitResultSetSerializable() throws Throwable {
public void testSplitResultSetSerializable(String queryResultFormat) throws Throwable {
List<String> fileNameList = null;
String originalResultCSVString = null;
int rowCount = 90000;
try (Connection connection = init();
try (Connection connection = init(queryResultFormat);
Statement statement = connection.createStatement()) {

statement.execute(
Expand Down Expand Up @@ -593,10 +602,11 @@ private void hackToSetupWrongURL(List<SnowflakeResultSetSerializable> resultSetS
}
}

@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@DontRunOnGithubActions
public void testCloseUnconsumedResultSet() throws Throwable {
try (Connection connection = init();
public void testCloseUnconsumedResultSet(String queryResultFormat) throws Throwable {
try (Connection connection = init(queryResultFormat);
Statement statement = connection.createStatement()) {
try {
statement.execute(
Expand All @@ -623,13 +633,14 @@ public void testCloseUnconsumedResultSet() throws Throwable {
}
}

@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@DontRunOnGithubActions
public void testNegativeWithChunkFileNotExist() throws Throwable {
public void testNegativeWithChunkFileNotExist(String queryResultFormat) throws Throwable {
// This test takes about (download worker retry times * networkTimeout) long to finish
Properties properties = new Properties();
properties.put("networkTimeout", 10000); // 10000 millisec
try (Connection connection = init(properties)) {
try (Connection connection = init(properties, queryResultFormat)) {
try (Statement statement = connection.createStatement()) {
statement.execute(
"create or replace table table_basic " + " (int_c int, string_c string(128))");
Expand Down Expand Up @@ -677,10 +688,11 @@ public void testNegativeWithChunkFileNotExist() throws Throwable {
}
}

@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@DontRunOnGithubActions
public void testNegativeWithClosedResultSet() throws Throwable {
try (Connection connection = init()) {
public void testNegativeWithClosedResultSet(String queryResultFormat) throws Throwable {
try (Connection connection = init(queryResultFormat)) {
Statement statement = connection.createStatement();

statement.execute(
Expand Down Expand Up @@ -729,15 +741,16 @@ public void testNegativeWithClosedResultSet() throws Throwable {
*
* @throws Throwable
*/
@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@Disabled
@DontRunOnGithubActions
public void testCustomProxyWithFiles() throws Throwable {
public void testCustomProxyWithFiles(String queryResultFormat) throws Throwable {
boolean generateFiles = false;
boolean correctProxy = false;

if (generateFiles) {
generateTestFiles();
generateTestFiles(queryResultFormat);
fail("This is generate test file.");
}

Expand Down Expand Up @@ -774,8 +787,8 @@ public void testCustomProxyWithFiles() throws Throwable {
}
}

private void generateTestFiles() throws Throwable {
try (Connection connection = init();
private void generateTestFiles(String queryResultFormat) throws Throwable {
try (Connection connection = init(queryResultFormat);
Statement statement = connection.createStatement()) {

statement.execute(
Expand All @@ -799,15 +812,16 @@ private void generateTestFiles() throws Throwable {
}
}

@Test
@ParameterizedTest
@ArgumentsSource(SimpleFormatProvider.class)
@DontRunOnGithubActions
public void testRetrieveMetadata() throws Throwable {
public void testRetrieveMetadata(String queryResultFormat) throws Throwable {
List<String> fileNameList;
int rowCount = 90000;
long expectedTotalRowCount = 0;
long expectedTotalCompressedSize = 0;
long expectedTotalUncompressedSize = 0;
try (Connection connection = init();
try (Connection connection = init(queryResultFormat);
Statement statement = connection.createStatement()) {

statement.execute(
Expand Down

0 comments on commit 4a97907

Please sign in to comment.