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

MR: Migrate parameterized tests to JUni5 #9711

Merged
merged 5 commits into from
Feb 13, 2024
Merged

Conversation

lisirrx
Copy link
Contributor

@lisirrx lisirrx commented Feb 11, 2024

@nastra Could you please review this pr?

to #9269

@github-actions github-actions bot added the MR label Feb 11, 2024
@@ -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;
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
@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();
Copy link
Contributor

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

Copy link
Contributor Author

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());
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(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();
Copy link
Contributor

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> {

Copy link
Contributor

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 {

Copy link
Contributor

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")),
Copy link
Contributor

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;
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
@TempDir public Path temp;
@TempDir private Path temp;

public FileFormat fileFormat1;

@Parameterized.Parameter(1)
@Parameter(index = 1)
public FileFormat fileFormat2;
Copy link
Contributor

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?

Copy link
Contributor Author

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

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"});
Copy link
Contributor

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 {

Copy link
Contributor

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;
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
@Parameter public TestTables.TestTableType testTableType;
@Parameter private TestTables.TestTableType testTableType;


@Rule public TemporaryFolder temp = new TemporaryFolder();
@TempDir public java.nio.file.Path temp;
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
@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");
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(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;
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
@TempDir public Path temp;
@TempDir private Path temp;

same for all the other parameters

@nastra nastra changed the title fix #9269 Switch class level parameterized for mr MR: Migrate parameterized tests to JUni5 Feb 13, 2024
Assert.assertEquals(
summary.get(SnapshotSummary.TOTAL_FILE_SIZE_PROP),
hmsParams.get(StatsSetupConst.TOTAL_SIZE));
assertThat(hmsParams).doesNotContainKey("custom_property");
Copy link
Contributor

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");
Copy link
Contributor

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");

Copy link
Contributor

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

Copy link
Contributor Author

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.

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 @lisirrx

@nastra nastra merged commit 50fb400 into apache:main Feb 13, 2024
11 checks passed
@lisirrx
Copy link
Contributor Author

lisirrx commented Feb 14, 2024

LGTM, thanks @lisirrx

Thanks!

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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants