nastra commented on code in PR #14215:
URL: https://github.com/apache/iceberg/pull/14215#discussion_r2394260827
##########
core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java:
##########
@@ -3167,6 +3172,412 @@ public void testRegisterExistingTable() {
assertThat(catalog.dropTable(identifier)).isTrue();
}
+ @Test
+ public void testBranchLifecycleManagement() {
+ C catalog = catalog();
+
+ if (requiresNamespaceCreate()) {
+ catalog.createNamespace(NS);
+ }
+
+ Table table = catalog.buildTable(TABLE, SCHEMA).create();
+ table.newFastAppend().appendFile(FILE_A).commit();
+ Snapshot firstSnapshot = table.currentSnapshot();
+
+ String branchName1 = "feature-branch-1";
+ table.manageSnapshots().createBranch(branchName1).commit();
+
+ // Verify branch was created
+ Map<String, SnapshotRef> refs = table.refs();
+ assertThat(refs).containsKey(branchName1);
+ assertThat(refs.get(branchName1).isBranch()).isTrue();
+
assertThat(refs.get(branchName1).snapshotId()).isEqualTo(firstSnapshot.snapshotId());
+
+ table.newFastAppend().appendFile(FILE_B).commit();
+ Snapshot secondSnapshot = table.currentSnapshot();
+
+ String branchName2 = "feature-branch-2";
+ table.manageSnapshots().createBranch(branchName2,
firstSnapshot.snapshotId()).commit();
+
+ // Verify branch points to the specific snapshot
+ refs = table.refs();
+ assertThat(refs).containsKey(branchName2);
+
assertThat(refs.get(branchName2).snapshotId()).isEqualTo(firstSnapshot.snapshotId());
+
assertThat(refs.get(branchName2).snapshotId()).isNotEqualTo(secondSnapshot.snapshotId());
+
+ String branchName3 = "retention-branch";
+ int minSnapshotsToKeep = 5;
+ long maxSnapshotAgeMs = Duration.ofDays(7).toMillis(); // 7 days
+ long maxRefAgeMs = Duration.ofDays(30).toMillis(); // 30 days
+
+ table
+ .manageSnapshots()
+ .createBranch(branchName3, firstSnapshot.snapshotId())
+ .setMinSnapshotsToKeep(branchName3, minSnapshotsToKeep)
+ .setMaxSnapshotAgeMs(branchName3, maxSnapshotAgeMs)
+ .setMaxRefAgeMs(branchName3, maxRefAgeMs)
+ .commit();
+
+ // Verify branch with retention policies
+ refs = table.refs();
+ SnapshotRef branchRef = refs.get(branchName3);
+ assertThat(branchRef).isNotNull();
+ assertThat(branchRef.isBranch()).isTrue();
+ assertThat(branchRef.minSnapshotsToKeep()).isEqualTo(minSnapshotsToKeep);
+ assertThat(branchRef.maxSnapshotAgeMs()).isEqualTo(maxSnapshotAgeMs);
+ assertThat(branchRef.maxRefAgeMs()).isEqualTo(maxRefAgeMs);
+
+ table.manageSnapshots().replaceBranch(branchName1,
secondSnapshot.snapshotId()).commit();
+
+ // Verify branch points to new snapshot
+ refs = table.refs();
+ SnapshotRef branchRef1 = refs.get(branchName1);
+ assertThat(branchRef1.snapshotId()).isEqualTo(secondSnapshot.snapshotId());
+
assertThat(branchRef1.snapshotId()).isNotEqualTo(firstSnapshot.snapshotId());
+
+ // Add data to feature branch (this should create a new snapshot on the
branch)
+ table.newFastAppend().toBranch(branchName1).appendFile(FILE_C).commit();
+
+ // Verify both branches have independent snapshots
+ refs = table.refs();
+ SnapshotRef mainRef = refs.get(SnapshotRef.MAIN_BRANCH);
+ SnapshotRef branchRef1Updated = refs.get(branchName1);
+
+ assertThat(mainRef.snapshotId()).isEqualTo(secondSnapshot.snapshotId());
+
assertThat(branchRef1Updated.snapshotId()).isNotEqualTo(mainRef.snapshotId());
+
+ // Verify the branch snapshot contains FILE_C
+ Snapshot branchSnapshot = table.snapshot(branchRef1Updated.snapshotId());
+ assertThat(branchSnapshot).isNotNull();
+
+ table.manageSnapshots().removeBranch(branchName2).commit();
+
+ // Verify branch is removed
+ refs = table.refs();
+ assertThat(refs).doesNotContainKey(branchName2);
+ }
+
+ @Test
+ public void testTagLifecycleManagement() {
+ C catalog = catalog();
+
+ if (requiresNamespaceCreate()) {
+ catalog.createNamespace(NS);
+ }
+
+ Table table = catalog.buildTable(TABLE, SCHEMA).create();
+ table.newFastAppend().appendFile(FILE_A).commit();
+ Snapshot firstSnapshot = table.currentSnapshot();
+
+ String tagName1 = "v1.0";
+ table.manageSnapshots().createTag(tagName1,
firstSnapshot.snapshotId()).commit();
+
+ // Verify tag was created
+ Map<String, SnapshotRef> refs = table.refs();
+ assertThat(refs).containsKey(tagName1);
+ assertThat(refs.get(tagName1).isTag()).isTrue();
+
assertThat(refs.get(tagName1).snapshotId()).isEqualTo(firstSnapshot.snapshotId());
+
+ table.newFastAppend().appendFile(FILE_B).commit();
+ Snapshot secondSnapshot = table.currentSnapshot();
+
+ String tagName2 = "v1.1";
+ long maxRefAgeMs = Duration.ofDays(365).toMillis(); // 1 year
+
+ table
+ .manageSnapshots()
+ .createTag(tagName2, secondSnapshot.snapshotId())
+ .setMaxRefAgeMs(tagName2, maxRefAgeMs)
+ .commit();
+
+ // Verify tag with retention policy
+ refs = table.refs();
+ SnapshotRef tagRef = refs.get(tagName2);
+ assertThat(tagRef).isNotNull();
+ assertThat(tagRef.isTag()).isTrue();
+ assertThat(tagRef.maxRefAgeMs()).isEqualTo(maxRefAgeMs);
+
+ table.manageSnapshots().replaceTag(tagName1,
secondSnapshot.snapshotId()).commit();
+
+ // Verify tag points to new snapshot
+ refs = table.refs();
+ SnapshotRef tagRef1 = refs.get(tagName1);
+ assertThat(tagRef1.snapshotId()).isEqualTo(secondSnapshot.snapshotId());
+ assertThat(tagRef1.snapshotId()).isNotEqualTo(firstSnapshot.snapshotId());
Review Comment:
same as above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]