-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
MR: Migrate parameterized tests to JUni5 #9711
Conversation
@@ -90,52 +93,49 @@ public class TestIcebergInputFormats { | |||
private static final PartitionSpec SPEC = | |||
PartitionSpec.builderFor(SCHEMA).identity("date").bucket("id", 1).build(); | |||
|
|||
@Rule public TemporaryFolder temp = new TemporaryFolder(); | |||
@TempDir public Path 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.
@TempDir public Path temp; | |
@TempDir private Path temp; |
public void before() throws IOException { | ||
conf = new Configuration(); | ||
conf.set(CatalogUtil.ICEBERG_CATALOG_TYPE, Catalogs.LOCATION); | ||
HadoopTables tables = new HadoopTables(conf); | ||
|
||
File location = temp.newFolder(testInputFormat.name(), fileFormat.name()); | ||
Assert.assertTrue(location.delete()); | ||
File location = temp.resolve(Paths.get(testInputFormat.name(), fileFormat.name())).toFile(); |
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.
in other places we use Files.createTempDirectory(temp, "junit").toFile()
, so I think we should do the same here
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.
In other places, the Files.createTempDirectory(temp, "junit").toFile()
is used to replace temp.newFolder();
which create a junit
folder under the temp
's root path.
However, when comes temp.newFolder(path1, path2)
, the method create a new leveled path like ${tempRoot}/path1/path2
. I read the source code of Files.createTempDirectory
and it can only create one level path. So I use temp.resolve
here
@@ -237,8 +237,8 @@ public void testProjection() throws Exception { | |||
|
|||
List<Record> outputRecords = testInputFormat.create(builder.conf()).getRecords(); | |||
|
|||
Assert.assertEquals(inputRecords.size(), outputRecords.size()); | |||
Assert.assertEquals(projection.asStruct(), outputRecords.get(0).struct()); | |||
assertThat(outputRecords.size()).isEqualTo(inputRecords.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.
assertThat(outputRecords.size()).isEqualTo(inputRecords.size()); | |
assertThat(outputRecords).hasSameSizeAs(inputRecords); |
public void testCustomCatalog() throws IOException { | ||
String warehouseLocation = temp.newFolder("hadoop_catalog").getAbsolutePath(); | ||
String warehouseLocation = temp.resolve("hadoop_catalog").toAbsolutePath().toString(); |
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 is correct
} | ||
|
||
public interface Factory<T> { | ||
|
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.
nit: unnecessary newline
|
||
// Helper class for setting up and testing various catalog implementations | ||
abstract class TestTables { | ||
|
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.
nit: unnecessary new line
this( | ||
conf, | ||
temp, | ||
(HiveVersion.min(HiveVersion.HIVE_3) ? "file:" : "") | ||
+ temp.newFolder("custom", "warehouse").toString(), | ||
+ temp.resolve(Paths.get("custom", "warehouse")), |
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.
we should also use Files.createTempDirectory(temp, ...)
here
|
||
@Rule public TemporaryFolder temp = new TemporaryFolder(); | ||
@TempDir public Path 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.
@TempDir public Path temp; | |
@TempDir private Path temp; |
public FileFormat fileFormat1; | ||
|
||
@Parameterized.Parameter(1) | ||
@Parameter(index = 1) | ||
public FileFormat fileFormat2; |
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.
these should all be private instead of public. Could you please adjust all of this parameters to be private?
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, I'll fix them
mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerLocalScan.java
Outdated
Show resolved
Hide resolved
Assert.assertArrayEquals(new Object[] {1L, "Bob", "Green"}, rows.get(1)); | ||
Assert.assertArrayEquals(new Object[] {2L, "Trudy", "Pink"}, rows.get(2)); | ||
assertThat(rows).hasSize(3); | ||
assertThat(rows.get(0)).isEqualTo(new Object[] {0L, "Alice", "Brown"}); |
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.
nit: this could also be written in a single stmt: assertThat(rows).containsExactly(first, second, third)
public class TestHiveIcebergStorageHandlerNoScan { | ||
|
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.
newline
@@ -140,35 +138,34 @@ public static Collection<Object[]> parameters() { | |||
|
|||
private TestTables testTables; | |||
|
|||
@Parameter(0) | |||
public TestTables.TestTableType testTableType; | |||
@Parameter public TestTables.TestTableType testTableType; |
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.
@Parameter public TestTables.TestTableType testTableType; | |
@Parameter private TestTables.TestTableType testTableType; |
|
||
@Rule public TemporaryFolder temp = new TemporaryFolder(); | ||
@TempDir public java.nio.file.Path 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.
@TempDir public java.nio.file.Path temp; | |
@TempDir private java.nio.file.Path temp; |
Assert.assertNotNull(hmsParams.get(hive_metastoreConstants.DDL_TIME)); | ||
Assert.assertNotNull(hmsParams.get(InputFormatConfig.PARTITION_SPEC)); | ||
assertThat(hmsParams).hasSize(14); | ||
assertThat(hmsParams.get("custom_property")).isEqualTo("initial_val"); |
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.
assertThat(hmsParams.get("custom_property")).isEqualTo("initial_val"); | |
assertThat(hmsParams).containsEntry("custom_property", "initial_val"); |
please also adjust the others as well. The advantage of using containsEntry()
is that it will print the content of the map if the assertion ever fails
public boolean isVectorized; | ||
|
||
@Rule public TemporaryFolder temp = new TemporaryFolder(); | ||
@TempDir public Path 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.
@TempDir public Path temp; | |
@TempDir private Path temp; |
same for all the other parameters
Assert.assertEquals( | ||
summary.get(SnapshotSummary.TOTAL_FILE_SIZE_PROP), | ||
hmsParams.get(StatsSetupConst.TOTAL_SIZE)); | ||
assertThat(hmsParams).doesNotContainKey("custom_property"); |
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 seems wrong. Shouldn't this do the same comparison as the previous assertions were doing?
assertThat(hmsParams)
.containsEntry(StatsSetupConst.NUM_FILES, summary.get(SnapshotSummary.TOTAL_DATA_FILES_PROP))
.containsEntry(StatsSetupConst.ROW_COUNT, summary.get(SnapshotSummary.TOTAL_RECORDS_PROP))
.containsEntry(...)
Assert.assertFalse(hmsParams.containsKey("custom_property")); | ||
Assert.assertFalse(hmsParams.containsKey("new_prop_1")); | ||
Assert.assertTrue(hmsParams.containsKey("new_prop_2")); | ||
assertThat(hmsParams).doesNotContainKey("custom_property"); |
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.
these can be chained together:
assertThat(hmsParams)
.doesNotContainKey("custom_property")
.doesNotContainKey("new_prop_1")
.containsKey("new_prop_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.
can you also please chain together the other assertions against hmsParams
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.
oh, thanks, you teach me something new! I'll fix them.
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.
LGTM, thanks @lisirrx
Thanks! |
@nastra Could you please review this pr?
to #9269