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

Migrate Read and other sub-classes in spark-extensions to JUnit5 and AssertJ style #9790

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

tomtongue
Copy link
Contributor

@tomtongue tomtongue commented Feb 24, 2024

Migrate the following "Read" and other sub-classes in spark-extensions to JUnit 5 and AssertJ style along with #9613, and #9086.

Current Progress

  • TestMetaColumnProjectionWithStageScan
  • TestMetadataTables
  • TestStroragePartitionedJoinsInRowLevelOperations
  • TestSystemFunctionPushDownDQL
  • TestViews
  • TestAlterTableSchema (testSetInvalidIdentifierFields still has Assert.)
  • SmokeTest

@github-actions github-actions bot added the spark label Feb 24, 2024
@tomtongue tomtongue changed the title [WIP] Migrate Read and other sub-classes in spark-extensions to JUnit5 and AssertJ style Migrate Read and other sub-classes in spark-extensions to JUnit5 and AssertJ style Feb 26, 2024
@tomtongue tomtongue force-pushed the mig-junit5-other-extensions branch from 34ba439 to 0c61738 Compare February 26, 2024 09:34
@tomtongue
Copy link
Contributor Author

tomtongue commented Feb 26, 2024

@nastra This is the last PR for the migration of spark-extensions except for SmokeTest in spark-runtime.
Could you review this when you have time?

The current PR doesn't have the SmokeTest migration, but if needed, please let me know.

@Before
public void before() {
@BeforeEach
public void setupResource() {
Copy link
Contributor

Choose a reason for hiding this comment

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

rather than renaming, it's better to just add super.before() as the first call in this method

@Before
public void before() {
@BeforeEach
public void useCatalog() {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we just call super.before() here as the first call instead of renaming?

assertThat(actualPartitionsWithProjection)
.as("Metadata table should return two partitions record")
.hasSize(2);
assertThat(actualPartitionsWithProjection)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assertThat(actualPartitionsWithProjection)

this can be just comined with the statement above

Assert.assertEquals(currentSnapshotId, testTag.get(0).getAs("snapshot_id"));
Assert.assertEquals(Long.valueOf(50), testTag.get(0).getAs("max_reference_age_in_ms"));
assertThat(testTag).hasSize(1);
assertThat(testTag.get(0).schema().fieldNames())
Copy link
Contributor

Choose a reason for hiding this comment

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

you could combine this with the previous line:
assertThat(testTag).hasSize(1).first().schema().fieldNames()).containsExactly(...)

please also update all the other checks in this file around branch/tag verification

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that calling schema() after the first() as above is not allowed here (I believe those tests can be combined with satisfies). So in the new commit, the tests of hasSize and record check are combined.

@nastra
Copy link
Contributor

nastra commented Feb 26, 2024

@tomtongue can you also please migrate and include SmokeTest in this PR?

@tomtongue
Copy link
Contributor Author

Thanks for the review. Sure, will include the SmokeTest with updates based on your reviews.

@github-actions github-actions bot added the build label Feb 27, 2024
@tomtongue tomtongue force-pushed the mig-junit5-other-extensions branch from bcb12a6 to e00bb2d Compare February 27, 2024 09:58
public void testGettingStarted() throws IOException {
// Creating a table
sql("CREATE TABLE %s (id bigint, data string) USING iceberg", tableName);

// Writing
sql("INSERT INTO %s VALUES (1, 'a'), (2, 'b'), (3, 'c')", tableName);
Assert.assertEquals(
"Should have inserted 3 rows", 3L, scalarSql("SELECT COUNT(*) FROM %s", tableName));
Assertions.assertThat(scalarSql("SELECT COUNT(*) FROM %s", tableName))
Copy link
Contributor

Choose a reason for hiding this comment

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

why not use the static import here?

Copy link
Contributor Author

@tomtongue tomtongue Feb 27, 2024

Choose a reason for hiding this comment

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

The static import is not recommended from the checkstyle. When it's statically imported, the test fails. Here's one of the examples:

 > Task :iceberg-spark:iceberg-spark-extensions-3.4_2.12:compileTestJava
Error: eckstyle] [ERROR] /home/runner/work/iceberg/iceberg/spark/v3.5/spark-runtime/src/integration/java/org/apache/iceberg/spark/SmokeTest.java:21:46: Using a static member import should be avoided - org.assertj.core.api.Assertions.assertThat. [AvoidStaticImport]

@nastra
Copy link
Contributor

nastra commented Feb 27, 2024

@tomtongue can you rebase this against latest main as there were some changes that just went in for TestViews

@tomtongue tomtongue force-pushed the mig-junit5-other-extensions branch from e00bb2d to b465306 Compare February 27, 2024 12:29
@tomtongue
Copy link
Contributor Author

Okay, rebased this branch onto the latest main. @nastra

Copy link
Contributor

@nastra nastra left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @tomtongue

@nastra nastra merged commit 2240154 into apache:main Feb 27, 2024
31 checks passed
@tomtongue
Copy link
Contributor Author

Thanks so much for your review! @nastra

@tomtongue tomtongue deleted the mig-junit5-other-extensions branch March 1, 2024 15:26
bitsondatadev pushed a commit to bitsondatadev/iceberg that referenced this pull request Mar 3, 2024
devangjhabakh pushed a commit to cdouglas/iceberg that referenced this pull request Apr 22, 2024
zachdisc pushed a commit to zachdisc/iceberg that referenced this pull request Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants