dimas-b commented on code in PR #10908:
URL: https://github.com/apache/iceberg/pull/10908#discussion_r1714266569


##########
open-api/src/testFixtures/java/org/apache/iceberg/rest/RCKUtils.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.iceberg.rest;
+
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.CatalogProperties;
+import org.eclipse.jetty.server.Server;
+
+class RCKUtils {
+  private static final String CATALOG_ENV_PREFIX = "CATALOG_";
+  static final String RCK_REQUIRES_NAMESPACE_CREATE = 
"rck.requires-namespace-create";
+  static final String RCK_SUPPORTS_SERVERSIDE_RETRY = 
"rck.supports-serverside-retry";
+
+  private static Server localServer;
+
+  private RCKUtils() {}
+
+  /**
+   * Utility method that allows configuring catalog properties via environment 
variables.
+   *
+   * <p>Returns a property map for all environment variables that start with 
<code>CATALOG_</code>
+   * replacing double-underscore (<code>__</code>) with dash (<code>-</code>) 
and replacing single
+   * underscore (<code>_</code>) with dot (<code>.</code>) to allow for common 
catalog property
+   * conventions. All characters in the name are converted to lowercase and 
values are unmodified.
+   *
+   * <p>Examples:
+   *
+   * <pre><code>
+   *     CATALOG_CATALOG__IMPL=org.apache.iceberg.jdbc.JdbcCatalog -> 
catalog-impl=org.apache.iceberg.jdbc.JdbcCatalog
+   *     CATALOG_URI=jdbc:sqlite:memory: -> uri=jdbc:sqlite:memory:
+   *     CATALOG_WAREHOUSE=test_warehouse     -> warehouse=test_warehouse
+   *     CATALOG_IO_IMPL=org.apache.iceberg.aws.s3.S3FileIO -> 
io-impl=org.apache.iceberg.aws.s3.S3FileIO
+   * .    CATALOG_JDBC_USER=ice_user     -> jdbc.user=ice_user
+   *
+   * </code></pre>
+   *
+   * @return configuration map
+   */
+  static Map<String, String> environmentCatalogConfig() {
+    return System.getenv().entrySet().stream()
+        .filter(e -> e.getKey().startsWith(CATALOG_ENV_PREFIX))
+        .collect(
+            Collectors.toMap(
+                e ->
+                    e.getKey()
+                        .replaceFirst(CATALOG_ENV_PREFIX, "")
+                        .replaceAll("__", "-")
+                        .replaceAll("_", ".")
+                        .toLowerCase(Locale.ROOT),
+                Map.Entry::getValue,
+                (m1, m2) -> {
+                  throw new IllegalArgumentException("Duplicate key: " + m1);
+                },
+                HashMap::new));
+  }
+
+  static boolean isLocalServer() {
+    return Boolean.parseBoolean(System.getProperty("rck.local", "true"));
+  }
+
+  static void startLocalServer() throws Exception {
+    RESTCatalogServer restServer = new RESTCatalogServer();
+    localServer = restServer.start();
+  }
+
+  static void stopLocalServer() throws Exception {
+    localServer.stop();
+  }
+
+  static RESTCatalog initCatalogClient() {
+    Map<String, String> catalogProperties = Maps.newHashMap();
+    catalogProperties.putAll(RCKUtils.environmentCatalogConfig());
+    catalogProperties.putAll(Maps.fromProperties(System.getProperties()));

Review Comment:
   Would it be possible to get non-default properties primarily from actual 
test instances? That should allow non-Iceberg code to run these tests against 
multiple backends in the same JVM. Defaulting to system properties is fine, of 
course, as long as long as tests have a way to provide overrides per test 
instance. That should also allow parallel execution.
   



##########
open-api/src/testFixtures/java/org/apache/iceberg/rest/RCKUtils.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.iceberg.rest;
+
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.CatalogProperties;
+import org.eclipse.jetty.server.Server;
+
+class RCKUtils {
+  private static final String CATALOG_ENV_PREFIX = "CATALOG_";
+  static final String RCK_REQUIRES_NAMESPACE_CREATE = 
"rck.requires-namespace-create";
+  static final String RCK_SUPPORTS_SERVERSIDE_RETRY = 
"rck.supports-serverside-retry";
+
+  private static Server localServer;
+
+  private RCKUtils() {}
+
+  /**
+   * Utility method that allows configuring catalog properties via environment 
variables.
+   *
+   * <p>Returns a property map for all environment variables that start with 
<code>CATALOG_</code>
+   * replacing double-underscore (<code>__</code>) with dash (<code>-</code>) 
and replacing single
+   * underscore (<code>_</code>) with dot (<code>.</code>) to allow for common 
catalog property
+   * conventions. All characters in the name are converted to lowercase and 
values are unmodified.
+   *
+   * <p>Examples:
+   *
+   * <pre><code>
+   *     CATALOG_CATALOG__IMPL=org.apache.iceberg.jdbc.JdbcCatalog -> 
catalog-impl=org.apache.iceberg.jdbc.JdbcCatalog
+   *     CATALOG_URI=jdbc:sqlite:memory: -> uri=jdbc:sqlite:memory:
+   *     CATALOG_WAREHOUSE=test_warehouse     -> warehouse=test_warehouse
+   *     CATALOG_IO_IMPL=org.apache.iceberg.aws.s3.S3FileIO -> 
io-impl=org.apache.iceberg.aws.s3.S3FileIO
+   * .    CATALOG_JDBC_USER=ice_user     -> jdbc.user=ice_user
+   *
+   * </code></pre>
+   *
+   * @return configuration map
+   */
+  static Map<String, String> environmentCatalogConfig() {
+    return System.getenv().entrySet().stream()
+        .filter(e -> e.getKey().startsWith(CATALOG_ENV_PREFIX))
+        .collect(
+            Collectors.toMap(
+                e ->
+                    e.getKey()
+                        .replaceFirst(CATALOG_ENV_PREFIX, "")
+                        .replaceAll("__", "-")
+                        .replaceAll("_", ".")
+                        .toLowerCase(Locale.ROOT),
+                Map.Entry::getValue,
+                (m1, m2) -> {
+                  throw new IllegalArgumentException("Duplicate key: " + m1);
+                },
+                HashMap::new));
+  }
+
+  static boolean isLocalServer() {
+    return Boolean.parseBoolean(System.getProperty("rck.local", "true"));
+  }
+
+  static void startLocalServer() throws Exception {
+    RESTCatalogServer restServer = new RESTCatalogServer();
+    localServer = restServer.start();
+  }
+
+  static void stopLocalServer() throws Exception {
+    localServer.stop();
+  }
+
+  static RESTCatalog initCatalogClient() {
+    Map<String, String> catalogProperties = Maps.newHashMap();
+    catalogProperties.putAll(RCKUtils.environmentCatalogConfig());
+    catalogProperties.putAll(Maps.fromProperties(System.getProperties()));
+
+    // Set defaults
+    catalogProperties.putIfAbsent(CatalogProperties.URI, 
"http://localhost:8181/";);
+    catalogProperties.putIfAbsent(CatalogProperties.WAREHOUSE_LOCATION, 
"integration");
+
+    RESTCatalog catalog = new RESTCatalog();
+    catalog.setConf(new Configuration());
+    catalog.initialize("tabular", catalogProperties);

Review Comment:
   `tabular`? :)



##########
build.gradle:
##########
@@ -952,6 +952,36 @@ project(':iceberg-snowflake') {
 }
 
 project(':iceberg-open-api') {
+  apply plugin: 'java-test-fixtures'

Review Comment:
   `RESTCompatibilityKitSuite` is currently under a `test` source directory? 
How is it published (sorry, I could not find even older classes from that 
module in Maven Central)? 



##########
open-api/src/test/java/org/apache/iceberg/rest/RESTCompatibilityKitCatalogTests.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.iceberg.rest;
+
+import org.apache.iceberg.catalog.CatalogTests;
+import org.apache.iceberg.util.PropertyUtil;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RESTCompatibilityKitCatalogTests extends 
CatalogTests<RESTCatalog> {
+  private static final Logger LOG = 
LoggerFactory.getLogger(RESTCompatibilityKitCatalogTests.class);
+
+  private static RESTCatalog restCatalog;
+
+  @BeforeAll
+  static void beforeClass() throws Exception {
+    if (RCKUtils.isLocalServer()) {
+      RCKUtils.startLocalServer();

Review Comment:
   It would be much nicer to use a JUnit5 Extension for managing the server 
lifecycle. Also, the extension could support pluggable code for non-default 
servers. This way the test code can be written without any dependency on the 
server side, while server startup becomes a runtime concern of the test 
extension.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to