Skip to content

Commit

Permalink
improve error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
nastra committed Oct 18, 2023
1 parent d4f510d commit a51761b
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.iceberg.exceptions.NoSuchTableException;
import org.apache.iceberg.exceptions.NoSuchViewException;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
import org.apache.iceberg.rest.RESTCatalog;
import org.apache.iceberg.types.Types;
import org.assertj.core.api.Assumptions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -1284,14 +1283,16 @@ public void updateViewPropertiesConflict() {
catalog().dropView(identifier);
assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse();

String expectedMessage =
catalog() instanceof RESTCatalog ? "View does not exist: ns.view" : "Cannot commit";
Class<?> expectedException =
catalog() instanceof RESTCatalog ? NoSuchViewException.class : CommitFailedException.class;

assertThatThrownBy(() -> updateViewProperties.set("key1", "val1").commit())
.isInstanceOf(expectedException)
.hasMessageContaining(expectedMessage);
.satisfiesAnyOf(
x ->
assertThat(x)
.isInstanceOf(NoSuchViewException.class)
.hasMessageContaining("View does not exist: ns.view"),
x ->
assertThat(x)
.isInstanceOf(CommitFailedException.class)
.hasMessageContaining("Cannot commit"));
}

@Test
Expand Down Expand Up @@ -1319,20 +1320,22 @@ public void replaceViewVersionConflict() {
catalog().dropView(identifier);
assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse();

String expectedMessage =
catalog() instanceof RESTCatalog ? "View does not exist: ns.view" : "Cannot commit";
Class<?> expectedException =
catalog() instanceof RESTCatalog ? NoSuchViewException.class : CommitFailedException.class;

assertThatThrownBy(
() ->
replaceViewVersion
.withQuery("trino", "select * from ns.tbl")
.withSchema(SCHEMA)
.withDefaultNamespace(identifier.namespace())
.commit())
.isInstanceOf(expectedException)
.hasMessageContaining(expectedMessage);
.satisfiesAnyOf(
x ->
assertThat(x)
.isInstanceOf(NoSuchViewException.class)
.hasMessageContaining("View does not exist: ns.view"),
x ->
assertThat(x)
.isInstanceOf(CommitFailedException.class)
.hasMessageContaining("Cannot commit"));
}

@Test
Expand Down Expand Up @@ -1522,14 +1525,16 @@ public void updateViewLocationConflict() {
catalog().dropView(identifier);
assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse();

String expectedMessage =
catalog() instanceof RESTCatalog ? "View does not exist: ns.view" : "Cannot commit";
Class<?> expectedException =
catalog() instanceof RESTCatalog ? NoSuchViewException.class : CommitFailedException.class;

// the view was already dropped concurrently
assertThatThrownBy(() -> updateViewLocation.setLocation("new-location").commit())
.isInstanceOf(expectedException)
.hasMessageContaining(expectedMessage);
.satisfiesAnyOf(
x ->
assertThat(x)
.isInstanceOf(NoSuchViewException.class)
.hasMessageContaining("View does not exist: ns.view"),
x ->
assertThat(x)
.isInstanceOf(CommitFailedException.class)
.hasMessageContaining("Cannot commit"));
}
}

0 comments on commit a51761b

Please sign in to comment.