rdblue commented on a change in pull request #4071:
URL: https://github.com/apache/iceberg/pull/4071#discussion_r835975976



##########
File path: core/src/test/java/org/apache/iceberg/TestSnapshotManager.java
##########
@@ -250,4 +250,268 @@ public void testCherryPickOverwrite() {
         lastSnapshotId, table.currentSnapshot().snapshotId());
     validateTableFiles(table, FILE_A, FILE_B);
   }
+
+  @Test
+  public void testCreateBranch() {
+    table.newAppend()
+        .appendFile(FILE_A)
+        .commit();
+    long snapshotId = table.currentSnapshot().snapshotId();
+    // Test a basic case of creating a branch
+    table.manageSnapshots()
+        .createBranch("branch1", snapshotId)
+        .commit();
+    SnapshotRef expectedBranch = table.ops().refresh().ref("branch1");
+    Assert.assertTrue(expectedBranch != null &&
+            
expectedBranch.equals(SnapshotRef.branchBuilder(snapshotId).build()));
+
+    // Trying to create a branch with an existing name should fail
+    AssertHelpers.assertThrows("Should fail validation check if we try and 
create branch again",
+            ValidationException.class, "Reference with name branch1 already 
exists",
+            () -> table.manageSnapshots().createBranch("branch1", 
snapshotId).commit());
+
+    // Trying to create another branch within the same chain
+    AssertHelpers.assertThrows("Should fail validation check if we try and 
create branch again",
+            ValidationException.class, "Reference with name branch2 already 
exists",

Review comment:
       Normally, I think this sort of problem would be 
`IllegalArgumentException`. That's what we typically use for arguments to a 
table change that are incompatible, not `ValidationException`. 




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

Reply via email to