Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
advancedxy committed Nov 27, 2024
1 parent a4635e9 commit c02354e
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public void removePartitionSpec() {
}

@Test
public void testRemovePartitionSpecsWithRefs() {
public void testRemovePartitionSpecsWithBranch() {
int defaultSpecId = 3;
long snapshotId = 42L;
when(metadata.defaultSpecId()).thenReturn(defaultSpecId);
Expand Down Expand Up @@ -508,6 +508,37 @@ public void testRemovePartitionSpecsFailure() {
defaultSpecId, defaultSpecId + 1);
}

@Test
public void testRemovePartitionSpecsWithBranchFailure() {
int defaultSpecId = 3;
long snapshotId = 42L;
when(metadata.defaultSpecId()).thenReturn(defaultSpecId);
when(updated.defaultSpecId()).thenReturn(defaultSpecId);

String branch = "test";
SnapshotRef snapshotRef = mock(SnapshotRef.class);
when(snapshotRef.snapshotId()).thenReturn(snapshotId);
when(snapshotRef.isBranch()).thenReturn(true);
when(metadata.refs()).thenReturn(ImmutableMap.of(branch, snapshotRef));
when(metadata.ref(branch)).thenReturn(snapshotRef);

SnapshotRef updatedRef = mock(SnapshotRef.class);
when(updatedRef.snapshotId()).thenReturn(snapshotId + 1);
when(updatedRef.isBranch()).thenReturn(true);
when(updated.ref(branch)).thenReturn(updatedRef);

List<UpdateRequirement> requirements =
UpdateRequirements.forUpdateTable(
metadata,
ImmutableList.of(new MetadataUpdate.RemovePartitionSpecs(Sets.newHashSet(1, 2))));

assertThatThrownBy(() -> requirements.forEach(req -> req.validate(updated)))
.isInstanceOf(CommitFailedException.class)
.hasMessage(
"Requirement failed: branch %s has changed: expected id %s != %s",
branch, snapshotId, snapshotId + 1);
}

@Test
public void addSortOrder() {
List<UpdateRequirement> requirements =
Expand Down

0 comments on commit c02354e

Please sign in to comment.