Repository navigation
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). |
|
@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.
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.
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.
this should extend SparkTestHelperBase
| } | ||
| } | ||
|
|
||
| @TempDir public File temp; |
There was a problem hiding this comment.
for JUnit5 this can be protected
| SparkCatalogConfig.SPARK.properties())); | ||
| } | ||
|
|
||
| @TempDir public File temp; |
There was a problem hiding this comment.
actually I don't think we need this here, because we already have it in the super class
nastra
left a comment
There was a problem hiding this comment.
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:
|
| 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.
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.
Confirmed that on my end, thanks. Update the tests.
| 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.
for the same reason that I mentioned above, it's better to have Assertions.assertThat(actual).as("Number of columns should match").hasSameSizeAs(expected);
|
|
||
| protected void assertEquals(String context, Object[] expectedRow, Object[] actualRow) { | ||
| Assert.assertEquals("Number of columns should match", expectedRow.length, actualRow.length); | ||
| Assertions.assertThat(actualRow.length) |
| Assert.assertArrayEquals(newContext, (byte[]) expectedValue, (byte[]) actualValue); | ||
| Assertions.assertThat((byte[]) actualValue) | ||
| .as(newContext) | ||
| .isEqualTo((byte[]) expectedValue); |
There was a problem hiding this comment.
this cast shouldn't be required
|
|
||
| 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.
| Assertions.assertThat(Iterables.size(groups)).as("Must have 1 group").isEqualTo(1); | |
| Assertions.assertThat(groups).hasSize(1); |
|
|
||
| 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.
| Assertions.assertThat(Iterables.size(groups)).as("Must have 1 group").isEqualTo(1); | |
| Assertions.assertThat(groups).hasSize(1); |
| Assertions.assertThat(Iterables.size(groups)).as("Must have 1 group").isEqualTo(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); |
| Assertions.assertThat(Iterables.size(groups)).as("Must have 1 group").isEqualTo(1); | ||
| 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.
please adjust all of these to use Assertions.assertThat(groups).as(..).hasSize(1);
There was a problem hiding this comment.
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