Skip to content

Migrate Snapshot files in Core to JUnit5#9892

Merged
nastra merged 5 commits intoapache:mainfrom
tomtongue:mig-junit5-iceberg-core-snapshot
Mar 11, 2024
Merged

Migrate Snapshot files in Core to JUnit5#9892
nastra merged 5 commits intoapache:mainfrom
tomtongue:mig-junit5-iceberg-core-snapshot

Conversation

@tomtongue
Copy link
Contributor

@tomtongue tomtongue commented Mar 7, 2024

Migrate the following "Read" in iceberg-core to JUnit 5 for #9085.

Current Progress

Snapshots:

  • TestSnapshot
  • TestSnapshotJson
    • LocalTableOperations
    • TestTableMetadata (partially changed, the change is related to LocalTableOperations)
  • TestSnapshotLoading
  • TestSnapshotSelection
  • TestSnapshotSummary

The following classes are for Iceberg procedures:

  • TestSnapshotManager
  • TestSnapshotRefParser

@github-actions github-actions bot added the core label Mar 7, 2024
@tomtongue tomtongue changed the title [WIP] Migrate Snapshot files in Core to JUnit5 Migrate Snapshot files in Core to JUnit5 Mar 8, 2024
@tomtongue
Copy link
Contributor Author

@nastra Update the snapshot files. Could you review this PR?

name -> {
try {
return temp.newFile(name).getAbsolutePath();
return java.nio.file.Files.createTempDirectory(temp, "junit")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this create a temp file with the given name rather than a temp directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. yes, that should create a temp file. Will fix.


public class TestSnapshotJson {
@Rule public TemporaryFolder temp = new TemporaryFolder();
@TempDir private static 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 private static Path temp;
@TempDir private Path temp;


public TableOperations ops = new LocalTableOperations(temp);
public TableOperations ops =
new LocalTableOperations(java.nio.file.Files.createTempDirectory(temp, "junit"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this create a new temp directory? I think it should just pass temp

public TableOperations ops =
new LocalTableOperations(java.nio.file.Files.createTempDirectory(temp, "junit"));

public TestSnapshotJson() throws IOException {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the constructor here?

Copy link
Contributor Author

@tomtongue tomtongue Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't need. As the above comment, I previously set createTempDirectory for LocalTableOperations, then the createTempDirectory needs the IOException handling. But as your feedback, temp should be set for LocalTableOperations and this IOException is not needed. Remove it in the next commit.

private String createManifestListWithManifestFiles(long snapshotId, Long parentSnapshotId)
throws IOException {
File manifestList = temp.newFile("manifests" + UUID.randomUUID());
File manifestList = java.nio.file.Files.createTempDirectory(temp, "junit").toFile();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should create a new temp file instead of a temp directory

assertThat(snapshot.snapshotId()).isEqualTo(expected.snapshotId());
assertThat(snapshot.allManifests(ops.io())).hasSize(2);

for (int i = 0; i < snapshot.allManifests(ops.io()).size(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these new checks? can you elaborate why those are being added?

Copy link
Contributor Author

@tomtongue tomtongue Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nastra I tried to check each element in the manifest list, but it's a bit redundant. I believe it's enough to check with isEqualTo between two lists. Let me revert this part and other part like this.

.build();

@Rule public TemporaryFolder temp = new TemporaryFolder();
@TempDir protected static 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 protected static Path temp;
@TempDir private Path temp;

private String createManifestListWithManifestFile(
long snapshotId, Long parentSnapshotId, String manifestFile) throws IOException {
File manifestList = temp.newFile("manifests" + UUID.randomUUID());
File manifestList = java.nio.file.Files.createTempDirectory(temp, "junit").toFile();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, shouldn't this create a temp file with the given name rather than a temp folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it should be a temp file. Will fix this part.

expectedBranch != null
&& expectedBranch.equals(SnapshotRef.branchBuilder(snapshotId).build()));
assertThat(expectedBranch).isNotNull();
assertThat(expectedBranch).isEqualTo(SnapshotRef.branchBuilder(snapshotId).build());
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(expectedBranch).isEqualTo(SnapshotRef.branchBuilder(snapshotId).build());
assertThat(expectedBranch).isNotNull().isEqualTo(SnapshotRef.branchBuilder(snapshotId).build());

Assert.assertTrue(
expectedBranch != null
&& expectedBranch.equals(SnapshotRef.branchBuilder(snapshotId).build()));
assertThat(expectedBranch).isNotNull();
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(expectedBranch).isNotNull();

Assertions.assertThat(actualBranch).isNotNull();
Assertions.assertThat(actualBranch).isEqualTo(SnapshotRef.branchBuilder(snapshotId).build());
assertThat(actualBranch).isNotNull();
assertThat(actualBranch).isEqualTo(SnapshotRef.branchBuilder(snapshotId).build());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both checks can be combined

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, thank you.

Assert.assertTrue(
expectedTag != null && expectedTag.equals(SnapshotRef.tagBuilder(snapshotId).build()));
assertThat(expectedTag).isNotNull();
assertThat(expectedTag).isEqualTo(SnapshotRef.tagBuilder(snapshotId).build());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

"Table should be on version 2 after creating manageSnapshots", 2, (int) version());
assertThat(readMetadata())
.as("Base metadata should not change when manageSnapshots is created")
.isEqualTo(base);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be isSameAs() as this check actually verifies that both objects are referentially equal. Same for the other places that previously used assertSame()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sure. Thanks for the advice.

@tomtongue tomtongue force-pushed the mig-junit5-iceberg-core-snapshot branch from cc0a63e to eaaf0f8 Compare March 8, 2024 16:43
@tomtongue
Copy link
Contributor Author

@nastra Thanks for the review. Reflected your comments. Could you review the new one?

private String createManifestListWithManifestFiles(long snapshotId, Long parentSnapshotId)
throws IOException {
File manifestList = temp.newFile("manifests" + UUID.randomUUID());
File manifestList = File.createTempFile("junit", null, temp.toFile());
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
File manifestList = File.createTempFile("junit", null, temp.toFile());
File manifestList = File.createTempFile("manifests", null, temp.toFile());

private String createManifestListWithManifestFile(
long snapshotId, Long parentSnapshotId, String manifestFile) throws IOException {
File manifestList = temp.newFile("manifests" + UUID.randomUUID());
File manifestList = File.createTempFile("junit", null, temp.toFile());
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
File manifestList = File.createTempFile("junit", null, temp.toFile());
File manifestList = File.createTempFile("manifests", null, temp.toFile());

"Table should be on version 2 after creating transaction", 2, (int) version());
assertThat(readMetadata())
.as("Base metadata should not change when transaction is created")
.isEqualTo(base);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be isSameAs()

txn.commitTransaction();

Assert.assertEquals(snapshotAfterFirstAppend, readMetadata().currentSnapshot());
assertThat(readMetadata().currentSnapshot()).isSameAs(snapshotAfterFirstAppend);
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(readMetadata().currentSnapshot()).isSameAs(snapshotAfterFirstAppend);
assertThat(readMetadata().currentSnapshot()).isEqualTo(snapshotAfterFirstAppend);

Assert.assertEquals(snapshotAfterFirstAppend, readMetadata().currentSnapshot());
Assert.assertEquals(
"Table should be on version 3 after invoking rollbackTo", 3, (int) version());
assertThat(readMetadata().currentSnapshot()).isSameAs(snapshotAfterFirstAppend);
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(readMetadata().currentSnapshot()).isSameAs(snapshotAfterFirstAppend);
assertThat(readMetadata().currentSnapshot()).isEqualTo(snapshotAfterFirstAppend);

@tomtongue
Copy link
Contributor Author

Thanks for the review @nastra

@nastra nastra merged commit 5ce5c78 into apache:main Mar 11, 2024
@tomtongue tomtongue deleted the mig-junit5-iceberg-core-snapshot branch March 11, 2024 14:57
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