-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Create SparkCatalogTestBase class for the migration to JUnit5 #9129
Create SparkCatalogTestBase class for the migration to JUnit5 #9129
Conversation
Working on updating other tests for JUnit5 and AssertJ. After updating the tests the class is merged into the original class (if I should separate other test updates to other PRs or there are another way, please let me know). |
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/SparkCatalogTestBaseForJU5.java
Outdated
Show resolved
Hide resolved
@tomtongue I think we first need to have a JUnit5 equivalent of |
Thank you! I'm working on changes. Let me do this. |
Add the following classes that basically cover JUnit5 and AssertJ styles. Each class has a lot of inheritants so that new classes are created for now. And, can I update existing Spark tests to use the new base classes? @nastra |
import org.assertj.core.api.Assertions; | ||
import org.junit.Assert; | ||
|
||
public class TestHelperBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this class, we can just use SparkTestHelperBase
because there's nothing JUnit4-specific in there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct, thank you! I remove TestHelperBase
and add changes to SparkTestHelperBase
with JUnit5 updates.
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
public abstract class TestBase extends TestHelperBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should extend SparkTestHelperBase
} | ||
} | ||
|
||
@TempDir public File temp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for JUnit5 this can be protected
SparkCatalogConfig.SPARK.properties())); | ||
} | ||
|
||
@TempDir public File temp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be protected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I don't think we need this here, because we already have it in the super class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks almost ready, just a few small things. Also could you please convert TestSparkFileRewriter
to use this new base class?
Let's first get the new base classes in and convert a single test to the new base class. Then we can handle other classes in a separate PR |
…riter parent to new TestBase
Thanks for the review, @nastra! I add the following changes based on the reviews:
|
@@ -55,12 +55,15 @@ private Object[] toJava(Row row) { | |||
|
|||
protected void assertEquals( | |||
String context, List<Object[]> expectedRows, List<Object[]> actualRows) { | |||
Assert.assertEquals( | |||
context + ": number of results should match", expectedRows.size(), actualRows.size()); | |||
Assertions.assertThat(actualRows.size()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to have
Assertions.assertThat(actualRows)
.as(context + ": number of results should match")
.hasSameSizeAs(expectedRows);
because this will show the content when the assertion ever fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed that on my end, thanks. Update the tests.
for (int row = 0; row < expectedRows.size(); row += 1) { | ||
Object[] expected = expectedRows.get(row); | ||
Object[] actual = actualRows.get(row); | ||
Assert.assertEquals("Number of columns should match", expected.length, actual.length); | ||
Assertions.assertThat(actual.length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the same reason that I mentioned above, it's better to have Assertions.assertThat(actual).as("Number of columns should match").hasSameSizeAs(expected);
@@ -69,19 +72,25 @@ protected void assertEquals( | |||
} | |||
|
|||
protected void assertEquals(String context, Object[] expectedRow, Object[] actualRow) { | |||
Assert.assertEquals("Number of columns should match", expectedRow.length, actualRow.length); | |||
Assertions.assertThat(actualRow.length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
Assert.assertArrayEquals(newContext, (byte[]) expectedValue, (byte[]) actualValue); | ||
Assertions.assertThat((byte[]) actualValue) | ||
.as(newContext) | ||
.isEqualTo((byte[]) expectedValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this cast shouldn't be required
@@ -129,9 +128,9 @@ private void checkDataFilesDeleteThreshold(SizeBasedDataRewriter rewriter) { | |||
rewriter.init(options); | |||
|
|||
Iterable<List<FileScanTask>> groups = rewriter.planFileGroups(tasks); | |||
Assert.assertEquals("Must have 1 group", 1, Iterables.size(groups)); | |||
Assertions.assertThat(Iterables.size(groups)).as("Must have 1 group").isEqualTo(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertions.assertThat(Iterables.size(groups)).as("Must have 1 group").isEqualTo(1); | |
Assertions.assertThat(groups).hasSize(1); |
@@ -110,9 +109,9 @@ private void checkDataFileSizeFiltering(SizeBasedDataRewriter rewriter) { | |||
rewriter.init(options); | |||
|
|||
Iterable<List<FileScanTask>> groups = rewriter.planFileGroups(tasks); | |||
Assert.assertEquals("Must have 1 group", 1, Iterables.size(groups)); | |||
Assertions.assertThat(Iterables.size(groups)).as("Must have 1 group").isEqualTo(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertions.assertThat(Iterables.size(groups)).as("Must have 1 group").isEqualTo(1); | |
Assertions.assertThat(groups).hasSize(1); |
List<FileScanTask> group = Iterables.getOnlyElement(groups); | ||
Assert.assertEquals("Must rewrite 2 files", 2, group.size()); | ||
Assertions.assertThat(group.size()).as("Must rewrite 2 files").isEqualTo(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
List<FileScanTask> group = Iterables.getOnlyElement(groups); | ||
Assert.assertEquals("Must rewrite big file", 1, group.size()); | ||
Assertions.assertThat(group.size()).as("Must rewrite big file").isEqualTo(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please adjust all of these to use Assertions.assertThat(groups).as(..).hasSize(1);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, thanks for the review. I'm working on it.
Thanks for the review again. Change the tests that are commented here. I reviewed all my changes on my end again, but If there's any part that should be changed, please let me know @nastra |
Base class creation for the migration to JUnit5 in regards to #9076 .
fixes #9074 #9075 #9076