Zephyr589 commented on code in PR #4658:
URL: https://github.com/apache/iceberg/pull/4658#discussion_r867317075


##########
flink/v1.14/flink/src/test/java/org/apache/iceberg/flink/TestFlinkCatalogDatabase.java:
##########
@@ -273,4 +273,40 @@ public void testHadoopNotSupportMeta() {
         String.format("Cannot create namespace %s: metadata is not supported", 
icebergNamespace),
         () -> sql("CREATE DATABASE %s WITH ('prop'='value')", flinkDatabase));
   }
+
+  @Test
+  public void testDropNonEmptyNamespaceOnCascade() {
+    Assume.assumeFalse("Hadoop catalog throws IOException: Directory is not 
empty.", isHadoopCatalog);
+
+    Assert.assertFalse(
+            "Namespace should not already exist",
+            validationNamespaceCatalog.namespaceExists(icebergNamespace));
+
+    sql("CREATE DATABASE %s ", flinkDatabase);
+
+    validationCatalog.createTable(
+            TableIdentifier.of(icebergNamespace, "tl"),
+            new Schema(Types.NestedField.optional(0, "id", 
Types.LongType.get())));
+
+    Assert.assertTrue("Namespace should exist", 
validationNamespaceCatalog.namespaceExists(icebergNamespace));
+    Assert.assertTrue("Table should exist", 
validationCatalog.tableExists(TableIdentifier.of(icebergNamespace, "tl")));
+
+    AssertHelpers.assertThrowsCause(
+            "Should fail if trying to delete a non-empty database without 
CASCADE",
+            DatabaseNotEmptyException.class,
+            String.format("Database %s in catalog %s is not empty.", DATABASE, 
catalogName),
+            () -> sql("DROP DATABASE %s", flinkDatabase));
+
+    Assert.assertTrue("Namespace should still exist after a failed drop",
+            validationNamespaceCatalog.namespaceExists(icebergNamespace));
+    Assert.assertTrue("Table should still exist after a failed drop",
+            validationCatalog.tableExists(TableIdentifier.of(icebergNamespace, 
"tl")));
+
+    sql("DROP DATABASE %s CASCADE", flinkDatabase);
+
+    Assert.assertFalse("Namespace should not exist after deleting with 
CASCADE",
+            validationNamespaceCatalog.namespaceExists(icebergNamespace));
+    Assert.assertFalse("Namespace should not exist after deleting its parent 
namespace with CASCADE",

Review Comment:
   Yes



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