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-1693588 Upgrade to JUnit5 #1909

Open
wants to merge 87 commits into
base: master
Choose a base branch
from

Conversation

sfc-gh-astachowski
Copy link
Collaborator

@sfc-gh-astachowski sfc-gh-astachowski commented Oct 4, 2024

Overview

SNOW-1693588 upgraded all tests to junit5. There are a lot of changes, but most are of following types:

  • Changed imports to junit5 (@Test annotation, Assumptions, Assertions)
    • Note: junit5 assertions take error message as last argument instead of first, causing a lot of changes.
  • Changed annotations to their 1:1 counterparts ( @Before to @BeforeEach, @BeforeClass to @BeforeAll etc.)
  • Changed parametrisation from junit4 style (class level) to junit5 style (method level). This means in most cases, that any constructors with arguments have been removed and the arguments are instead passed directly to the tests.
    • As a con, this means some @BeforeClass annotations could not be translated to junit5, as the fields they depend on no longer exist. As a result, in those cases relevant functions are now called at the beginning of each test. (Could be remedied later I believe)
  • Changed temporary folders from junit4 style to junit5 style (@Rule to @TempDir)
    • Moved several input/output streams to try-with-resources statements (while seemingly unrelated, leaving them open was causing some issues with @TempDir on windows)
  • Changed conditional enable/disable annotations to junit5 style
    • Moved static functions from deleted Conditional ignore rules to new AssumptionUtils class
  • Changed from junit4 @Category annotations to junit5 @Tag
  • No longer asserting throws with annotations, using assertThrows instead.
  • In many tests added logic to restore system properties after test execution (required now, because junit5 runs tests in different order than junit4, revealing errors like this).

Pre-review self checklist

  • PR branch is updated with all the changes from master branch
  • The code is correctly formatted (run mvn -P check-style validate)
  • New public API is not unnecessary exposed (run mvn verify and inspect target/japicmp/japicmp.html)
  • The pull request name is prefixed with SNOW-XXXX:
  • Code is in compliance with internal logging requirements

@sfc-gh-astachowski sfc-gh-astachowski requested a review from a team as a code owner October 4, 2024 08:58
# Conflicts:
#	src/test/java/net/snowflake/client/jdbc/ClientMemoryLimitParallelIT.java
#	src/test/java/net/snowflake/client/jdbc/ConnectionIT.java
#	src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java
#	src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataIT.java
#	src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataLatestIT.java
#	src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultsetIT.java
#	src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java
#	src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java
#	src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtArrowIT.java
#	src/test/java/net/snowflake/client/jdbc/PreparedMultiStmtIT.java
#	src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java
#	src/test/java/net/snowflake/client/jdbc/SnowflakeUtilTest.java
#	src/test/java/net/snowflake/client/jdbc/StreamLatestIT.java
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

public class CallableStatementITBase extends BaseJDBCTest {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been created to remove inheritance between CallableStatementIT and CallableStatementLatestIT in order to avoid duplicating tests.

@@ -25,6 +27,7 @@ public void setup() {
}

@Test
@Disabled
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has serious isolation problems, and as far as I can tell was never actually ran. To be fixed later

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add an issue for such problems and mark the tests with TODO comment with JIRA ID

import org.junit.jupiter.params.provider.ArgumentsSource;

// @Category(TestCategoryStatement.class)
@Tag(TestTags.STATEMENT)
public class PreparedStatement1IT extends PreparedStatement0IT {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class combines previous PreparedStatement1IT and PreparedStatementArrow1IT


/**
* PreparedStatement integration tests for the latest JDBC driver. This doesn't work for the oldest
* supported driver. Revisit this tests whenever bumping up the oldest supported driver to examine
* if the tests still are not applicable. If it is applicable, move tests to PreparedStatement1IT so
* that both the latest and oldest supported driver run the tests.
*/
@Category(TestCategoryStatement.class)
// @Category(TestCategoryStatement.class)
@Tag(TestTags.STATEMENT)
public class PreparedStatement1LatestIT extends PreparedStatement0IT {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class combines previous PreparedStatement1LatestIT and PreparedStatementArrow1LatestIT

import org.junit.jupiter.params.provider.ArgumentsSource;

// @Category(TestCategoryStatement.class)
@Tag(TestTags.STATEMENT)
public class PreparedStatement2IT extends PreparedStatement0IT {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class combines previous PreparedStatement2IT and PreparedStatementArrow2IT


/** Test ResultSet */
@Category(TestCategoryResultSet.class)
// @Category(TestCategoryResultSet.class)
@Tag(TestTags.RESULT_SET)
public class ResultSetIT extends ResultSet0IT {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now combines old ResultSetIT and ResultSetArrowIT


/** SnowflakeResultSetSerializable tests */
@Category(TestCategoryResultSet.class)
// @Category(TestCategoryResultSet.class)
@Tag(TestTags.RESULT_SET)
public class SnowflakeResultSetSerializableIT extends BaseJDBCTest {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now handles both json and arrow tests

<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit-platform</artifactId>
<version>3.5.1</version>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add version to the properties - here and in other places in poms

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call

$MVNW_EXE -DjenkinsIT \
-Djava.io.tmpdir=$WORKSPACE \
-Djacoco.skip.instrument=false \
-DtestCategory=net.snowflake.client.category.$c \
-Dtest="$JDBC_TEST_CATEGORY" \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we change the property name to JDBC_TEST_SUITES?
here and in other scripts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll do that

@Retention(RetentionPolicy.RUNTIME)
@EnabledIfEnvironmentVariable(named = "SNOWFLAKE_TEST_ACCOUNT", matches = "testaccount")
@DisabledIfEnvironmentVariable(named = "GITHUB_ACTIONS", matches = ".*")
public @interface RunOnTestaccount {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's rename - run on test account not on github actions

@@ -87,7 +86,7 @@ public void testThrowErrorWhenWrongPermissionsForConnectionConfigurationFile()
File tokenFile = new File(Paths.get(tempPath.toString(), "token").toUri());
prepareConnectionConfigurationTomlFile(
Collections.singletonMap("token_file_path", tokenFile.toString()), false, false);
assumeFalse(RunningNotOnLinuxMac.isNotRunningOnLinuxMac());
assumeFalse(AssumptionUtils.isNotRunningOnLinuxMac());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we replace the assumptions (here and in other places) with annotations?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can investigate this, for now it is recreating 1:1 original behaviour. I think this can be addressed in a later PR


@Category(TestCategoryCore.class)
// @Category(TestCategoryCore.class)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove categories annotations instead of commenting in all places

}

@Test
public void shouldChooseOcspCacheServerUrls() {
// @Parameterized.Parameters(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove unnecessary comments

import static org.junit.Assume.assumeNoException;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
// import static org.junit.jupiter.api.Assumptions.assumeNoException;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's removed unnecessary code

}

try (ResultSet resultSet =
databaseMetaData.getCrossReference(null, null, null, null, null, null)) {
assertThat(getSizeOfResultSet(resultSet), greaterThanOrEqualTo(2));
MatcherAssert.assertThat(getSizeOfResultSet(resultSet), greaterThanOrEqualTo(2));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we import static MatcherAssert.assertThat?

@@ -164,7 +162,7 @@ public void testGetVectorViaGetStringIsEqualToTheGetObject() throws SQLException
assertTrue(resultSet.next());
assertGetObjectAndGetStringBeTheSame(resultSet, "[-1,5]", 1);
String floatArrayRepresentation =
"json".equals(queryResultFormat)
"JSON".equals(queryResultFormat)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use equals ignore case

@@ -1471,14 +1491,63 @@ public void testNoSpaceLeftOnDeviceException() throws SQLException {
}

@Test
@ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubAction.class)
@Disabled // ignored until SNOW-1616480 is resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a TODO to comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants