You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2022/05/30 14:50:18 UTC

[iceberg] branch master updated: Core: Update catalog tests for flexibility and consistency (#4897)

This is an automated email from the ASF dual-hosted git repository.

blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 82db4fa9e Core: Update catalog tests for flexibility and consistency (#4897)
82db4fa9e is described below

commit 82db4fa9ef6d958f5b0f9742c16e30d28338a584
Author: Bryan Keller <br...@gmail.com>
AuthorDate: Mon May 30 07:50:13 2022 -0700

    Core: Update catalog tests for flexibility and consistency (#4897)
---
 .../org/apache/iceberg/rest/CatalogHandlers.java   |  5 +++--
 .../org/apache/iceberg/catalog/CatalogTests.java   | 25 +++++++++++++++-------
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java b/core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java
index 53e905bd3..bb5a46024 100644
--- a/core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java
+++ b/core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java
@@ -279,9 +279,10 @@ public class CatalogHandlers {
   }
 
   private static TableMetadata create(TableOperations ops, TableMetadata start, UpdateTableRequest request) {
-    TableMetadata.Builder builder = TableMetadata.buildFrom(start);
-
     // the only valid requirement is that the table will be created
+    request.requirements().forEach(requirement -> requirement.validate(ops.current()));
+
+    TableMetadata.Builder builder = TableMetadata.buildFrom(start);
     request.updates().forEach(update -> update.applyTo(builder));
 
     // create transactions do not retry. if the table exists, retrying is not a solution
diff --git a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
index b9c498a58..a5a07e909 100644
--- a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
+++ b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
@@ -47,7 +47,6 @@ import org.apache.iceberg.exceptions.NoSuchNamespaceException;
 import org.apache.iceberg.exceptions.NoSuchTableException;
 import org.apache.iceberg.expressions.Expressions;
 import org.apache.iceberg.io.CloseableIterable;
-import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
 import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
@@ -163,7 +162,7 @@ public abstract class CatalogTests<C extends Catalog & SupportsNamespaces> {
     Assert.assertFalse("Namespace should not exist", catalog.namespaceExists(NS));
 
     catalog.createNamespace(NS);
-    Assert.assertEquals("Catalog should have the created namespace", ImmutableList.of(NS), catalog.listNamespaces());
+    Assert.assertTrue("Catalog should have the created namespace", catalog.listNamespaces().contains(NS));
     Assert.assertTrue("Namespace should exist", catalog.namespaceExists(NS));
   }
 
@@ -357,16 +356,22 @@ public abstract class CatalogTests<C extends Catalog & SupportsNamespaces> {
     Namespace ns2 = Namespace.of("newdb_2");
 
     catalog.createNamespace(ns1);
-    Assert.assertEquals("Should include newdb_1", concat(starting, ns1), catalog.listNamespaces());
+    Assertions.assertThat(catalog.listNamespaces())
+            .withFailMessage("Should include newdb_1")
+            .hasSameElementsAs(concat(starting, ns1));
 
     catalog.createNamespace(ns2);
-    Assert.assertEquals("Should include newdb_1 and newdb_2", concat(starting, ns1, ns2), catalog.listNamespaces());
+    Assertions.assertThat(catalog.listNamespaces())
+            .withFailMessage("Should include newdb_1 and newdb_2")
+            .hasSameElementsAs(concat(starting, ns1, ns2));
 
     catalog.dropNamespace(ns1);
-    Assert.assertEquals("Should include newdb_2, not newdb_1", concat(starting, ns2), catalog.listNamespaces());
+    Assertions.assertThat(catalog.listNamespaces())
+            .withFailMessage("Should include newdb_2, not newdb_1")
+            .hasSameElementsAs(concat(starting, ns2));
 
     catalog.dropNamespace(ns2);
-    Assert.assertEquals("Should include only starting namespaces", starting, catalog.listNamespaces());
+    Assert.assertTrue("Should include only starting namespaces", catalog.listNamespaces().containsAll(starting));
   }
 
   @Test
@@ -1146,8 +1151,10 @@ public abstract class CatalogTests<C extends Catalog & SupportsNamespaces> {
     catalog.buildTable(TABLE, OTHER_SCHEMA).create();
 
     Assertions.setMaxStackTraceElementsDisplayed(Integer.MAX_VALUE);
+    String expectedMessage =
+        supportsServerSideRetry() ? "Requirement failed: table already exists" : "Table already exists";
     AssertHelpers.assertThrows("Should fail because table was created concurrently",
-        AlreadyExistsException.class, "Table already exists", create::commitTransaction);
+        AlreadyExistsException.class, expectedMessage, create::commitTransaction);
 
     // validate the concurrently created table is unmodified
     Table table = catalog.loadTable(TABLE);
@@ -1326,8 +1333,10 @@ public abstract class CatalogTests<C extends Catalog & SupportsNamespaces> {
 
     catalog.buildTable(TABLE, OTHER_SCHEMA).create();
 
+    String expectedMessage =
+        supportsServerSideRetry() ? "Requirement failed: table already exists" : "Table already exists";
     AssertHelpers.assertThrows("Should fail because table was created concurrently",
-        AlreadyExistsException.class, "Table already exists", createOrReplace::commitTransaction);
+        AlreadyExistsException.class, expectedMessage, createOrReplace::commitTransaction);
 
     // validate the concurrently created table is unmodified
     Table table = catalog.loadTable(TABLE);