RussellSpitzer commented on code in PR #264:
URL: https://github.com/apache/polaris/pull/264#discussion_r1745725981


##########
polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisOverlappingTableTest.java:
##########
@@ -0,0 +1,304 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.service.admin;
+
+import static org.apache.polaris.service.admin.PolarisAuthzTestBase.SCHEMA;
+import static 
org.apache.polaris.service.context.DefaultContextResolver.REALM_PROPERTY_KEY;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import io.dropwizard.testing.ConfigOverride;
+import io.dropwizard.testing.ResourceHelpers;
+import io.dropwizard.testing.junit5.DropwizardAppExtension;
+import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.client.Invocation;
+import jakarta.ws.rs.core.Response;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Stream;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.rest.requests.CreateNamespaceRequest;
+import org.apache.iceberg.rest.requests.CreateTableRequest;
+import org.apache.polaris.core.PolarisConfiguration;
+import org.apache.polaris.core.admin.model.Catalog;
+import org.apache.polaris.core.admin.model.CatalogProperties;
+import org.apache.polaris.core.admin.model.CreateCatalogRequest;
+import org.apache.polaris.core.admin.model.FileStorageConfigInfo;
+import org.apache.polaris.core.admin.model.StorageConfigInfo;
+import org.apache.polaris.service.PolarisApplication;
+import org.apache.polaris.service.config.PolarisApplicationConfig;
+import org.apache.polaris.service.test.PolarisConnectionExtension;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+@ExtendWith({DropwizardExtensionsSupport.class, 
PolarisConnectionExtension.class})
+public class PolarisOverlappingTableTest {
+  private static final DropwizardAppExtension<PolarisApplicationConfig> 
BASE_EXT =
+      new DropwizardAppExtension<>(
+          PolarisApplication.class,
+          
ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"),
+          // Bind to random port to support parallelism
+          ConfigOverride.config("server.applicationConnectors[0].port", "0"),
+          ConfigOverride.config("server.adminConnectors[0].port", "0"),
+          // Enforce table location constraints
+          
ConfigOverride.config("featureConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION", 
"false"),
+          
ConfigOverride.config("featureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP", 
"false"));
+
+  private static final DropwizardAppExtension<PolarisApplicationConfig> 
LAX_EXT =
+      new DropwizardAppExtension<>(
+          PolarisApplication.class,
+          
ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"),
+          // Bind to random port to support parallelism
+          ConfigOverride.config("server.applicationConnectors[0].port", "0"),
+          ConfigOverride.config("server.adminConnectors[0].port", "0"),
+          // Relax table location constraints
+          
ConfigOverride.config("featureConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION", 
"true"),
+          
ConfigOverride.config("featureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP", 
"true"));
+
+  private static PolarisConnectionExtension.PolarisToken adminToken;
+  private static String userToken;
+  private static String realm;
+  private static String namespace;
+  private static final String baseLocation = 
"file:///tmp/PolarisOverlappingTableTest";
+
+  private static final CatalogWrapper defaultCatalog = new 
CatalogWrapper("default");
+  private static final CatalogWrapper laxCatalog = new CatalogWrapper("lax");
+  private static final CatalogWrapper strictCatalog = new 
CatalogWrapper("strict");
+
+  /** Used to define a parameterized test config */
+  protected record TestConfig(
+      DropwizardAppExtension<PolarisApplicationConfig> extension,
+      CatalogWrapper catalogWrapper,
+      Response.Status response) {
+    public String catalog() {
+      return catalogWrapper.catalog;
+    }
+
+    private String extensionName() {
+      return (extension
+              .getConfiguration()
+              .getConfigurationStore()
+              .getConfiguration(null, 
PolarisConfiguration.ALLOW_TABLE_LOCATION_OVERLAP))
+          ? "lax"
+          : "strict";
+    }
+
+    /** Extract the first component of the catalog name; e.g. `default` from 
`default_123_xyz` */
+    private String catalogShortName() {
+      StringBuilder result = new StringBuilder();
+      for (char c : catalog().toCharArray()) {
+        if (c == '_') {
+          break;
+        }
+        result.append(c);
+      }
+      return result.toString();
+    }
+
+    @Override
+    public String toString() {
+      return String.format(
+          "extension=%s, catalog=%s, status=%s",
+          extensionName(), catalogShortName(), response.toString());
+    }
+  }
+
+  /* Used to wrap a catalog name, so the TestConfig's final `catalog` field 
can be updated */
+  protected static class CatalogWrapper {
+    public String catalog;
+
+    public CatalogWrapper(String catalog) {
+      this.catalog = catalog;
+    }
+
+    @Override
+    public String toString() {
+      return catalog;
+    }
+  }
+
+  @BeforeEach
+  public void setup(PolarisConnectionExtension.PolarisToken adminToken) {
+    userToken = adminToken.token();
+    realm = 
PolarisConnectionExtension.getTestRealm(PolarisServiceImplIntegrationTest.class);
+    defaultCatalog.catalog = String.format("default_catalog_%s", 
UUID.randomUUID().toString());
+    laxCatalog.catalog = String.format("lax_catalog_%s", 
UUID.randomUUID().toString());
+    strictCatalog.catalog = String.format("strict_catalog_%s", 
UUID.randomUUID().toString());
+    List.of(BASE_EXT, LAX_EXT)
+        .forEach(
+            EXT -> {
+              List.of(defaultCatalog, laxCatalog, strictCatalog)
+                  .forEach(
+                      c -> {
+                        StorageConfigInfo config =
+                            FileStorageConfigInfo.builder()
+                                
.setStorageType(StorageConfigInfo.StorageTypeEnum.FILE)
+                                .build();
+                        CatalogProperties.Builder propertiesBuilder =
+                            CatalogProperties.builder()
+                                .setDefaultBaseLocation(String.format("%s/%s", 
baseLocation, c));
+                        if (!c.equals(defaultCatalog)) {

Review Comment:
   I hate to suggest this because in my heart I like functional approaches, but 
I think they just look bad in Java.
   So what you could do is convert to for (...) 
   
   That would save us a lot of indentation because we have too keep adding a 
new level every time we add to our functional apply thanks to the style guide.
   ```java
   List.of(BASE_EXT, LAX_EXT)
     .forEach(
       EXT -> {
         List.of(defaultCatalog, laxCatalog, strictCatalog)
           .forEach(
             c -> {
               //6 Levels of indentation
   ```
   
   Java
   ```java
   for (ext : List.of(...)) {
     for (catalog : List.of()) {
     // 3 levels of indentation
     }
   }
   ```
   Scala :(
   ```scala
   for ( ext <- (...); catalog <-(...)) {
    // 1 level of indentation :(
   }
   ```
   
   Other things to make this more readable,
   
   We could do static imports of PolarisConfiguration. This would require 
adding some "ignores" for the style guide I believe but I honestly don't think 
we lose anything by doing those static imports.
   
   Long term we probably want to extract some of this out into a base test 
class maybe? So a user can just do something like
   
   BaseTestClass.createCatalog(name, properties)



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

Reply via email to