Create ExtensionTestBase for migration to JUnit5#9613
Conversation
| private static final Random RANDOM = ThreadLocalRandom.current(); | ||
|
|
||
| @Parameters(name = "catalogName = {0}, implementation = {1}, config = {2}") | ||
| protected static Object[][] parameters() { |
There was a problem hiding this comment.
I don't think this is needed here because the default params are coming from CatalogTestBase
There was a problem hiding this comment.
remove the parameters part (keep the RANDOM because the parent class doesn't have it and it's required).
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
|
|
||
| @ExtendWith(ParameterizedTestExtension.class) |
There was a problem hiding this comment.
I also don't think this is required, because CatalogTestBase already has this
|
|
||
| private final int formatVersion; | ||
| @Parameter(index = 3) | ||
| protected int formatVersion; |
There was a problem hiding this comment.
| protected int formatVersion; | |
| private int formatVersion; |
| } | ||
|
|
||
| @Rule public TemporaryFolder temp = new TemporaryFolder(); | ||
| @TempDir protected Path temp; |
There was a problem hiding this comment.
no need to make this protected, because this class doesn't have any subclasses
| // Spark Session Catalog cannot load metadata tables | ||
| // with "The namespace in session catalog must have exactly one name part" | ||
| Assume.assumeFalse(catalogName.equals("spark_catalog")); | ||
| Assumptions.assumeFalse(catalogName.equals("spark_catalog")); |
There was a problem hiding this comment.
please use the one from AssertJ: assumeThat(catalog).isNotEqualTo("spark_catalog")
There was a problem hiding this comment.
oops, sorry, let me fix this.
| record2.put("id", 2L); | ||
| record2.put("data", "b"); | ||
| File outputFile = temp.newFile("test.avro"); | ||
| File outputFile = File.createTempFile("test", ".avro", temp.toFile()); |
There was a problem hiding this comment.
| File outputFile = File.createTempFile("test", ".avro", temp.toFile()); | |
| File outputFile = temp.resolve("test.avro").toFile(); |
| catalogName, tableName, fileTableDir.getAbsolutePath()); | ||
|
|
||
| Assert.assertEquals(2L, result); | ||
| Assertions.assertThat(result).isEqualTo(2L); |
There was a problem hiding this comment.
it's ok to statically import assertThat() in places where it's newly introduced
|
|
||
| Matcher matcher = uuidPattern.matcher(manifestPath); | ||
| Assert.assertTrue("verify manifest path has uuid", matcher.find()); | ||
| Assertions.assertThat(matcher.find()).as("verify manifest path has uuid").isTrue(); |
There was a problem hiding this comment.
| Assertions.assertThat(matcher.find()).as("verify manifest path has uuid").isTrue(); | |
| assertThat(matcher).as("verify manifest path has uuid").matches(); |
There was a problem hiding this comment.
matches is a full string match, so this couldn't pass the test if this test was changed. Or, should I change the regex pattern?
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| fileTableDir = temp.toFile(); |
There was a problem hiding this comment.
could you please check if we actually need fileTableDir? I think the calls that use fileTableDir.getAbsolutePath() can be replaced with temp.toFile().getAbsolutePath().
There was a problem hiding this comment.
I believe temp.toFile().getAbsolutePath() is evaluated in the sql and I couldn't find any errors based on my several attempts. However, fileTableDir is called 33 times in this class, and keep the current one is less changes. What do you think? (committed without changes for now)
There was a problem hiding this comment.
ok let's keep fileTableDir in this case
| catalogName, tableName, fileTableDir.getAbsolutePath()); | ||
|
|
||
| Assert.assertEquals(2L, result); | ||
| Assertions.assertThat(result).isEqualTo(2L); |
There was a problem hiding this comment.
please use the statically imported method
| // Spark Session Catalog cannot load metadata tables | ||
| // with "The namespace in session catalog must have exactly one name part" | ||
| Assume.assumeFalse(catalogName.equals("spark_catalog")); | ||
| Assumptions.assumeThat(catalogName).isNotEqualTo("spark_catalog"); |
There was a problem hiding this comment.
please use the statically imported method
| // verify manifest file name has uuid pattern | ||
| String manifestPath = (String) sql("select path from %s.manifests", tableName).get(0)[0]; | ||
|
|
||
| System.out.println(manifestPath); |
There was a problem hiding this comment.
Forgot to remove...will do it.
|
please also add the below diff to |
...park-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestAddFilesProcedure.java
Show resolved
Hide resolved
…unnecessary print-debug
nastra
left a comment
There was a problem hiding this comment.
LGTM, thanks @tomtongue. It would be great if you could also move subclasses of SparkExtensionsTestBase to ExtensionsTestBase in a few follow-up PRs
|
@nastra thanks a lot for the review. I will create a new PR to move other classes in the extension after this. |
Create
ExtensionTestBaseto migrate current tests in SparkExtension to JUnit 5 in regards to #9086.For now, only one test
TestAddFilesProcedureis updated with JUnit 5. Once the current migration works well, I will migrate other classes in the extension path.