nastra commented on code in PR #10755: URL: https://github.com/apache/iceberg/pull/10755#discussion_r1852387515
########## core/src/test/java/org/apache/iceberg/TestUpdateRequirements.java: ########## @@ -424,6 +424,89 @@ public void setDefaultPartitionSpecFailure() { .hasMessage("Requirement failed: default partition spec changed: expected id 0 != 1"); } + @Test + public void testRemovePartitionSpec() { + int defaultSpecId = 3; + when(metadata.defaultSpecId()).thenReturn(defaultSpecId); + // empty refs + when(metadata.refs()).thenReturn(ImmutableMap.of()); + + List<UpdateRequirement> requirements = + UpdateRequirements.forUpdateTable( + metadata, + ImmutableList.of(new MetadataUpdate.RemovePartitionSpecs(Sets.newHashSet(1, 2)))); + + assertThat(requirements) + .hasSize(2) + .hasOnlyElementsOfTypes( + UpdateRequirement.AssertTableUUID.class, UpdateRequirement.AssertDefaultSpecID.class); + + assertTableUUID(requirements); + + assertThat(requirements) + .element(1) + .asInstanceOf(InstanceOfAssertFactories.type(UpdateRequirement.AssertDefaultSpecID.class)) + .extracting(UpdateRequirement.AssertDefaultSpecID::specId) + .isEqualTo(defaultSpecId); + } + + @Test + public void testRemovePartitionSpecsWithRefs() { + int defaultSpecId = 3; + long snapshotId = 42L; + when(metadata.defaultSpecId()).thenReturn(defaultSpecId); + + String branch = "branch"; + SnapshotRef snapshotRef = mock(SnapshotRef.class); + when(snapshotRef.snapshotId()).thenReturn(snapshotId); + when(snapshotRef.isBranch()).thenReturn(true); + when(metadata.refs()).thenReturn(ImmutableMap.of(branch, snapshotRef)); Review Comment: this also requires mocking this: `when(metadata.ref(branch)).thenReturn(snapshotRef);` (it wasn't failing because the call to `validate()` was missing) -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org