You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "andrew4699 (via GitHub)" <gi...@apache.org> on 2024/10/22 01:46:45 UTC

[PR] Enable defining custom test environments [polaris]

andrew4699 opened a new pull request, #391:
URL: https://github.com/apache/polaris/pull/391

   # Description
   
   This is a test-only change which adds a pattern for running tests against user-specified environments by specifying your own base URL and HTTP client. Makes PolarisRestCatalogViewIntegrationTest use the custom test environment.
   
   Example:
   ```
   INTEGRATION_TEST_BASE_URL="http://localhost:8181" \
   INTEGRATION_TEST_HTTP_CLIENT_FACTORY_IMPL="org.apache.polaris.MyCustomHttpClientFactory" \
   INTEGRATION_TEST_ROLE_ARN="arn:aws:iam::<role>" \
   INTEGRATION_TEST_S3_PATH="s3://<bucket>" \
   ./gradlew test --info --rerun --tests "org.apache.polaris.service.catalog.PolarisRestCatalogViewIntegrationTest"
   ```
   
   ## Type of change
   
   - [X] New feature (non-breaking change which adds functionality)
   
   # How Has This Been Tested?
   
   - [X] Existing tests work
   - [X] Tested running against a non-Dropwizard Polaris with a custom HTTP client
   
   # Checklist:
   
   - [X] I have performed a self-review of my code
   - [X] I have commented my code, particularly in hard-to-understand areas
   - [X] My changes generate no new warnings
   


-- 
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-unsubscribe@polaris.apache.org

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


Re: [PR] Enable defining custom test environments [polaris]

Posted by "andrew4699 (via GitHub)" <gi...@apache.org>.
andrew4699 commented on code in PR #391:
URL: https://github.com/apache/polaris/pull/391#discussion_r1813479983


##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironment.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.test;
+
+import jakarta.ws.rs.client.Client;
+import java.net.URI;
+
+/** Defines the test environment that a test should run in. */
+public class TestEnvironment {

Review Comment:
   Updated



-- 
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-unsubscribe@polaris.apache.org

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


Re: [PR] Enable defining custom test environments [polaris]

Posted by "andrew4699 (via GitHub)" <gi...@apache.org>.
andrew4699 commented on code in PR #391:
URL: https://github.com/apache/polaris/pull/391#discussion_r1813479773


##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironmentExtension.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.test;
+
+import static org.apache.polaris.service.test.PolarisConnectionExtension.findDropwizardExtension;
+
+import io.dropwizard.testing.junit5.DropwizardAppExtension;
+import jakarta.ws.rs.client.Client;
+import java.util.Optional;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+/**
+ * JUnit test extension that constructs a TestEnvironment. It tries to use environment variables and
+ * falls back to communicating with the local Dropwizard instance.
+ */
+public class TestEnvironmentExtension implements ParameterResolver {
+  /**
+   * Environment variable that specifies the Polaris base URL to use. If this is not set, falls back
+   * to the root path of your Dropwizard instance.
+   */
+  public static final String ENV_BASE_URL = "INTEGRATION_TEST_BASE_URL";
+
+  /**
+   * Environment variable that specifies the HTTP client factory that should construct test HTTP
+   * clients. This should be a class name. If this is not set, falls back to the client created by
+   * Dropwizard.
+   */
+  public static final String ENV_HTTP_CLIENT_FACTORY_IMPL =
+      "INTEGRATION_TEST_HTTP_CLIENT_FACTORY_IMPL";
+
+  private static TestEnvironment env;
+
+  public static synchronized TestEnvironment getEnv(ExtensionContext extensionContext)
+      throws IllegalAccessException {
+    if (env == null) {
+      Optional<String> baseUrl = Optional.ofNullable(System.getenv(ENV_BASE_URL));
+      DropwizardAppExtension dropwizardAppExtension = findDropwizardExtension(extensionContext);
+      if (dropwizardAppExtension == null && baseUrl.isEmpty()) {
+        throw new ParameterResolutionException(
+            "No test URL specified. Tried to default to Dropwizard but could not find DropwizardAppExtension.");
+      }
+
+      env =
+          new TestEnvironment(
+              getHttpClient(dropwizardAppExtension),
+              baseUrl.orElse(
+                  String.format("http://localhost:%d", dropwizardAppExtension.getLocalPort())));
+    }
+    return env;
+  }
+
+  @Override
+  public boolean supportsParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    return parameterContext.getParameter().getType().equals(TestEnvironment.class);
+  }
+
+  @Override
+  public Object resolveParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    try {
+      return getEnv(extensionContext);
+    } catch (IllegalAccessException e) {
+      throw new ParameterResolutionException(e.getMessage());
+    }
+  }
+
+  private static Client getHttpClient(DropwizardAppExtension dropwizardAppExtension) {
+    Optional<String> httpClientImpl =
+        Optional.ofNullable(System.getenv(ENV_HTTP_CLIENT_FACTORY_IMPL));
+
+    if (httpClientImpl.isEmpty()) {
+      if (dropwizardAppExtension == null) {
+        throw new ParameterResolutionException(
+            "Tried to default to Dropwizard client but could not find DropwizardAppExtension.");
+      }
+      return dropwizardAppExtension.client();

Review Comment:
   Updated to TestEnvironmentResolver + DropwizardTestEnvironmentResolver



##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironmentExtension.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.test;
+
+import static org.apache.polaris.service.test.PolarisConnectionExtension.findDropwizardExtension;
+
+import io.dropwizard.testing.junit5.DropwizardAppExtension;
+import jakarta.ws.rs.client.Client;
+import java.util.Optional;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+/**
+ * JUnit test extension that constructs a TestEnvironment. It tries to use environment variables and
+ * falls back to communicating with the local Dropwizard instance.
+ */
+public class TestEnvironmentExtension implements ParameterResolver {
+  /**
+   * Environment variable that specifies the Polaris base URL to use. If this is not set, falls back
+   * to the root path of your Dropwizard instance.
+   */
+  public static final String ENV_BASE_URL = "INTEGRATION_TEST_BASE_URL";
+
+  /**
+   * Environment variable that specifies the HTTP client factory that should construct test HTTP
+   * clients. This should be a class name. If this is not set, falls back to the client created by
+   * Dropwizard.
+   */
+  public static final String ENV_HTTP_CLIENT_FACTORY_IMPL =
+      "INTEGRATION_TEST_HTTP_CLIENT_FACTORY_IMPL";
+
+  private static TestEnvironment env;
+
+  public static synchronized TestEnvironment getEnv(ExtensionContext extensionContext)
+      throws IllegalAccessException {
+    if (env == null) {
+      Optional<String> baseUrl = Optional.ofNullable(System.getenv(ENV_BASE_URL));
+      DropwizardAppExtension dropwizardAppExtension = findDropwizardExtension(extensionContext);
+      if (dropwizardAppExtension == null && baseUrl.isEmpty()) {
+        throw new ParameterResolutionException(
+            "No test URL specified. Tried to default to Dropwizard but could not find DropwizardAppExtension.");
+      }
+
+      env =
+          new TestEnvironment(
+              getHttpClient(dropwizardAppExtension),
+              baseUrl.orElse(
+                  String.format("http://localhost:%d", dropwizardAppExtension.getLocalPort())));
+    }
+    return env;
+  }
+
+  @Override
+  public boolean supportsParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    return parameterContext.getParameter().getType().equals(TestEnvironment.class);
+  }
+
+  @Override
+  public Object resolveParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    try {
+      return getEnv(extensionContext);
+    } catch (IllegalAccessException e) {
+      throw new ParameterResolutionException(e.getMessage());
+    }
+  }
+
+  private static Client getHttpClient(DropwizardAppExtension dropwizardAppExtension) {
+    Optional<String> httpClientImpl =
+        Optional.ofNullable(System.getenv(ENV_HTTP_CLIENT_FACTORY_IMPL));
+
+    if (httpClientImpl.isEmpty()) {
+      if (dropwizardAppExtension == null) {
+        throw new ParameterResolutionException(
+            "Tried to default to Dropwizard client but could not find DropwizardAppExtension.");
+      }
+      return dropwizardAppExtension.client();
+    }
+
+    TestHttpClientFactory httpClientFactory;
+    try {
+      httpClientFactory =
+          (TestHttpClientFactory)
+              (Class.forName(httpClientImpl.get()).getDeclaredConstructor().newInstance());
+    } catch (Exception e) {
+      throw new IllegalArgumentException(
+          String.format(
+              "Cannot initialize http Client, %s does not implement PolarisTestHttpClientFactory.",

Review Comment:
   Updated



-- 
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-unsubscribe@polaris.apache.org

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


Re: [PR] Enable defining custom test environments [polaris]

Posted by "andrew4699 (via GitHub)" <gi...@apache.org>.
andrew4699 commented on code in PR #391:
URL: https://github.com/apache/polaris/pull/391#discussion_r1821598589


##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironment.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.test;
+
+import jakarta.ws.rs.client.Client;
+import java.net.URI;
+
+/** Defines the test environment that a test should run in. */
+public record TestEnvironment(Client apiClient, String baseUrl) {
+  public URI getBaseUri() {

Review Comment:
   Updated



-- 
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-unsubscribe@polaris.apache.org

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


Re: [PR] Enable defining custom test environments [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #391:
URL: https://github.com/apache/polaris/pull/391#discussion_r1811148874


##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironment.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.test;
+
+import jakarta.ws.rs.client.Client;
+import java.net.URI;
+
+/** Defines the test environment that a test should run in. */
+public class TestEnvironment {

Review Comment:
   Can this be a `record?



##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironment.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.test;
+
+import jakarta.ws.rs.client.Client;
+import java.net.URI;
+
+/** Defines the test environment that a test should run in. */
+public class TestEnvironment {

Review Comment:
   Can this be a `record`?



-- 
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-unsubscribe@polaris.apache.org

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


Re: [PR] Enable defining custom test environments [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #391:
URL: https://github.com/apache/polaris/pull/391#discussion_r1811151305


##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironmentExtension.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.test;
+
+import static org.apache.polaris.service.test.PolarisConnectionExtension.findDropwizardExtension;
+
+import io.dropwizard.testing.junit5.DropwizardAppExtension;
+import jakarta.ws.rs.client.Client;
+import java.util.Optional;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+/**
+ * JUnit test extension that constructs a TestEnvironment. It tries to use environment variables and
+ * falls back to communicating with the local Dropwizard instance.
+ */
+public class TestEnvironmentExtension implements ParameterResolver {
+  /**
+   * Environment variable that specifies the Polaris base URL to use. If this is not set, falls back
+   * to the root path of your Dropwizard instance.
+   */
+  public static final String ENV_BASE_URL = "INTEGRATION_TEST_BASE_URL";
+
+  /**
+   * Environment variable that specifies the HTTP client factory that should construct test HTTP
+   * clients. This should be a class name. If this is not set, falls back to the client created by
+   * Dropwizard.
+   */
+  public static final String ENV_HTTP_CLIENT_FACTORY_IMPL =
+      "INTEGRATION_TEST_HTTP_CLIENT_FACTORY_IMPL";
+
+  private static TestEnvironment env;
+
+  public static synchronized TestEnvironment getEnv(ExtensionContext extensionContext)
+      throws IllegalAccessException {
+    if (env == null) {
+      Optional<String> baseUrl = Optional.ofNullable(System.getenv(ENV_BASE_URL));
+      DropwizardAppExtension dropwizardAppExtension = findDropwizardExtension(extensionContext);
+      if (dropwizardAppExtension == null && baseUrl.isEmpty()) {
+        throw new ParameterResolutionException(
+            "No test URL specified. Tried to default to Dropwizard but could not find DropwizardAppExtension.");
+      }
+
+      env =
+          new TestEnvironment(
+              getHttpClient(dropwizardAppExtension),
+              baseUrl.orElse(
+                  String.format("http://localhost:%d", dropwizardAppExtension.getLocalPort())));
+    }
+    return env;
+  }
+
+  @Override
+  public boolean supportsParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    return parameterContext.getParameter().getType().equals(TestEnvironment.class);
+  }
+
+  @Override
+  public Object resolveParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    try {
+      return getEnv(extensionContext);
+    } catch (IllegalAccessException e) {
+      throw new ParameterResolutionException(e.getMessage());
+    }
+  }
+
+  private static Client getHttpClient(DropwizardAppExtension dropwizardAppExtension) {
+    Optional<String> httpClientImpl =
+        Optional.ofNullable(System.getenv(ENV_HTTP_CLIENT_FACTORY_IMPL));
+
+    if (httpClientImpl.isEmpty()) {
+      if (dropwizardAppExtension == null) {
+        throw new ParameterResolutionException(
+            "Tried to default to Dropwizard client but could not find DropwizardAppExtension.");
+      }
+      return dropwizardAppExtension.client();
+    }
+
+    TestHttpClientFactory httpClientFactory;
+    try {
+      httpClientFactory =
+          (TestHttpClientFactory)
+              (Class.forName(httpClientImpl.get()).getDeclaredConstructor().newInstance());
+    } catch (Exception e) {
+      throw new IllegalArgumentException(
+          String.format(
+              "Cannot initialize http Client, %s does not implement PolarisTestHttpClientFactory.",

Review Comment:
   It looks like this is now named `TestHttpClientFactory`. Also, let's not catch `Exception`



-- 
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-unsubscribe@polaris.apache.org

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


Re: [PR] Enable defining custom test environments [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #391:
URL: https://github.com/apache/polaris/pull/391#discussion_r1811150277


##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironmentExtension.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.test;
+
+import static org.apache.polaris.service.test.PolarisConnectionExtension.findDropwizardExtension;
+
+import io.dropwizard.testing.junit5.DropwizardAppExtension;
+import jakarta.ws.rs.client.Client;
+import java.util.Optional;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+/**
+ * JUnit test extension that constructs a TestEnvironment. It tries to use environment variables and
+ * falls back to communicating with the local Dropwizard instance.
+ */
+public class TestEnvironmentExtension implements ParameterResolver {
+  /**
+   * Environment variable that specifies the Polaris base URL to use. If this is not set, falls back
+   * to the root path of your Dropwizard instance.
+   */
+  public static final String ENV_BASE_URL = "INTEGRATION_TEST_BASE_URL";
+
+  /**
+   * Environment variable that specifies the HTTP client factory that should construct test HTTP
+   * clients. This should be a class name. If this is not set, falls back to the client created by
+   * Dropwizard.
+   */
+  public static final String ENV_HTTP_CLIENT_FACTORY_IMPL =

Review Comment:
   This approach seems a bit roundabout. Is there a way we can achieve this with a service file?



-- 
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-unsubscribe@polaris.apache.org

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


Re: [PR] Enable defining custom test environments [polaris]

Posted by "collado-mike (via GitHub)" <gi...@apache.org>.
collado-mike commented on code in PR #391:
URL: https://github.com/apache/polaris/pull/391#discussion_r1813403681


##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironment.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.test;
+
+import jakarta.ws.rs.client.Client;
+import java.net.URI;
+
+/** Defines the test environment that a test should run in. */
+public record TestEnvironment(Client apiClient, String baseUrl) {
+  public URI getBaseUri() {

Review Comment:
   You could make the main constructor take a URI and have a secondary constructor that takes the string and converts to a URI. That way the conversion is done on construction and always done once.



-- 
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-unsubscribe@polaris.apache.org

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


Re: [PR] Enable defining custom test environments [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard merged PR #391:
URL: https://github.com/apache/polaris/pull/391


-- 
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-unsubscribe@polaris.apache.org

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


Re: [PR] Enable defining custom test environments [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #391:
URL: https://github.com/apache/polaris/pull/391#discussion_r1811152353


##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironmentExtension.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.test;
+
+import static org.apache.polaris.service.test.PolarisConnectionExtension.findDropwizardExtension;
+
+import io.dropwizard.testing.junit5.DropwizardAppExtension;
+import jakarta.ws.rs.client.Client;
+import java.util.Optional;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+/**
+ * JUnit test extension that constructs a TestEnvironment. It tries to use environment variables and
+ * falls back to communicating with the local Dropwizard instance.
+ */
+public class TestEnvironmentExtension implements ParameterResolver {
+  /**
+   * Environment variable that specifies the Polaris base URL to use. If this is not set, falls back
+   * to the root path of your Dropwizard instance.
+   */
+  public static final String ENV_BASE_URL = "INTEGRATION_TEST_BASE_URL";
+
+  /**
+   * Environment variable that specifies the HTTP client factory that should construct test HTTP
+   * clients. This should be a class name. If this is not set, falls back to the client created by
+   * Dropwizard.
+   */
+  public static final String ENV_HTTP_CLIENT_FACTORY_IMPL =
+      "INTEGRATION_TEST_HTTP_CLIENT_FACTORY_IMPL";
+
+  private static TestEnvironment env;
+
+  public static synchronized TestEnvironment getEnv(ExtensionContext extensionContext)
+      throws IllegalAccessException {
+    if (env == null) {
+      Optional<String> baseUrl = Optional.ofNullable(System.getenv(ENV_BASE_URL));
+      DropwizardAppExtension dropwizardAppExtension = findDropwizardExtension(extensionContext);
+      if (dropwizardAppExtension == null && baseUrl.isEmpty()) {
+        throw new ParameterResolutionException(
+            "No test URL specified. Tried to default to Dropwizard but could not find DropwizardAppExtension.");
+      }
+
+      env =
+          new TestEnvironment(
+              getHttpClient(dropwizardAppExtension),
+              baseUrl.orElse(
+                  String.format("http://localhost:%d", dropwizardAppExtension.getLocalPort())));
+    }
+    return env;
+  }
+
+  @Override
+  public boolean supportsParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    return parameterContext.getParameter().getType().equals(TestEnvironment.class);
+  }
+
+  @Override
+  public Object resolveParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    try {
+      return getEnv(extensionContext);
+    } catch (IllegalAccessException e) {
+      throw new ParameterResolutionException(e.getMessage());
+    }
+  }
+
+  private static Client getHttpClient(DropwizardAppExtension dropwizardAppExtension) {
+    Optional<String> httpClientImpl =
+        Optional.ofNullable(System.getenv(ENV_HTTP_CLIENT_FACTORY_IMPL));
+
+    if (httpClientImpl.isEmpty()) {
+      if (dropwizardAppExtension == null) {
+        throw new ParameterResolutionException(
+            "Tried to default to Dropwizard client but could not find DropwizardAppExtension.");
+      }
+      return dropwizardAppExtension.client();

Review Comment:
   Should this logic actually get encapsulated in (e.g.) `DropWizardTestHttpClientFactory`?



##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironmentExtension.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.test;
+
+import static org.apache.polaris.service.test.PolarisConnectionExtension.findDropwizardExtension;
+
+import io.dropwizard.testing.junit5.DropwizardAppExtension;
+import jakarta.ws.rs.client.Client;
+import java.util.Optional;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+/**
+ * JUnit test extension that constructs a TestEnvironment. It tries to use environment variables and
+ * falls back to communicating with the local Dropwizard instance.
+ */
+public class TestEnvironmentExtension implements ParameterResolver {
+  /**
+   * Environment variable that specifies the Polaris base URL to use. If this is not set, falls back
+   * to the root path of your Dropwizard instance.
+   */
+  public static final String ENV_BASE_URL = "INTEGRATION_TEST_BASE_URL";
+
+  /**
+   * Environment variable that specifies the HTTP client factory that should construct test HTTP
+   * clients. This should be a class name. If this is not set, falls back to the client created by
+   * Dropwizard.
+   */
+  public static final String ENV_HTTP_CLIENT_FACTORY_IMPL =
+      "INTEGRATION_TEST_HTTP_CLIENT_FACTORY_IMPL";
+
+  private static TestEnvironment env;
+
+  public static synchronized TestEnvironment getEnv(ExtensionContext extensionContext)
+      throws IllegalAccessException {
+    if (env == null) {
+      Optional<String> baseUrl = Optional.ofNullable(System.getenv(ENV_BASE_URL));
+      DropwizardAppExtension dropwizardAppExtension = findDropwizardExtension(extensionContext);
+      if (dropwizardAppExtension == null && baseUrl.isEmpty()) {
+        throw new ParameterResolutionException(
+            "No test URL specified. Tried to default to Dropwizard but could not find DropwizardAppExtension.");
+      }
+
+      env =
+          new TestEnvironment(
+              getHttpClient(dropwizardAppExtension),
+              baseUrl.orElse(
+                  String.format("http://localhost:%d", dropwizardAppExtension.getLocalPort())));
+    }
+    return env;
+  }
+
+  @Override
+  public boolean supportsParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    return parameterContext.getParameter().getType().equals(TestEnvironment.class);
+  }
+
+  @Override
+  public Object resolveParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    try {
+      return getEnv(extensionContext);
+    } catch (IllegalAccessException e) {
+      throw new ParameterResolutionException(e.getMessage());
+    }
+  }
+
+  private static Client getHttpClient(DropwizardAppExtension dropwizardAppExtension) {
+    Optional<String> httpClientImpl =
+        Optional.ofNullable(System.getenv(ENV_HTTP_CLIENT_FACTORY_IMPL));
+
+    if (httpClientImpl.isEmpty()) {
+      if (dropwizardAppExtension == null) {
+        throw new ParameterResolutionException(
+            "Tried to default to Dropwizard client but could not find DropwizardAppExtension.");
+      }
+      return dropwizardAppExtension.client();

Review Comment:
   Should this logic actually get encapsulated in (e.g.) `DropWizardTestHttpClientFactory`? And that becomes the default?



-- 
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-unsubscribe@polaris.apache.org

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


Re: [PR] Enable defining custom test environments [polaris]

Posted by "andrew4699 (via GitHub)" <gi...@apache.org>.
andrew4699 commented on code in PR #391:
URL: https://github.com/apache/polaris/pull/391#discussion_r1821608255


##########
polaris-service/src/test/java/org/apache/polaris/service/test/TestEnvironmentExtension.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.test;
+
+import static org.apache.polaris.service.test.PolarisConnectionExtension.findDropwizardExtension;
+
+import io.dropwizard.testing.junit5.DropwizardAppExtension;
+import jakarta.ws.rs.client.Client;
+import java.util.Optional;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+/**
+ * JUnit test extension that constructs a TestEnvironment. It tries to use environment variables and
+ * falls back to communicating with the local Dropwizard instance.
+ */
+public class TestEnvironmentExtension implements ParameterResolver {
+  /**
+   * Environment variable that specifies the Polaris base URL to use. If this is not set, falls back
+   * to the root path of your Dropwizard instance.
+   */
+  public static final String ENV_BASE_URL = "INTEGRATION_TEST_BASE_URL";
+
+  /**
+   * Environment variable that specifies the HTTP client factory that should construct test HTTP
+   * clients. This should be a class name. If this is not set, falls back to the client created by
+   * Dropwizard.
+   */
+  public static final String ENV_HTTP_CLIENT_FACTORY_IMPL =

Review Comment:
   For things like this the project seems to have relied on providing a test config file and Jackson parsing the config. I'm hoping to decouple this from Dropwizard and for non-Dropwizard environments also not force people to go through that whole dance.



-- 
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-unsubscribe@polaris.apache.org

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