adutra commented on code in PR #590:
URL: https://github.com/apache/polaris/pull/590#discussion_r1903079862


##########
integration-tests/src/main/java/org/apache/polaris/service/it/ext/PolarisIntegrationTestExtension.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.it.ext;
+
+import static java.util.concurrent.TimeUnit.*;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.PropertyNamingStrategies;
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientBuilder;
+import jakarta.ws.rs.ext.ContextResolver;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.stream.Collectors;
+import org.apache.iceberg.rest.RESTSerializers;
+import org.apache.polaris.service.it.env.AuthToken;
+import org.apache.polaris.service.it.env.ClientCredentials;
+import org.apache.polaris.service.it.env.PolarisApiClient;
+import org.apache.polaris.service.it.env.PolarisFeatureConfig;
+import org.apache.polaris.service.it.env.Server;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
+import 
org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+import org.junit.platform.commons.util.AnnotationUtils;
+import org.junit.platform.engine.UniqueId;
+
+public class PolarisIntegrationTestExtension implements ParameterResolver {
+  private static final Namespace NAMESPACE =
+      Namespace.create(PolarisIntegrationTestExtension.class);
+
+  private static final PolarisServerManager manager =
+      ServiceLoader.load(PolarisServerManager.class)
+          .findFirst()
+          .orElseThrow(() -> new IllegalStateException("PolarisServerManager 
not found"));
+
+  @Override
+  public boolean supportsParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    Class<?> type = parameterContext.getParameter().getType();
+    return type.isAssignableFrom(PolarisApiClient.class)
+        || type.isAssignableFrom(ClientCredentials.class)
+        || type.isAssignableFrom(AuthToken.class);
+  }
+
+  @Override
+  public Object resolveParameter(
+      ParameterContext parameterContext, ExtensionContext extensionContext)
+      throws ParameterResolutionException {
+    Env env = env(extensionContext);
+    Class<?> type = parameterContext.getParameter().getType();
+    if (type.isAssignableFrom(PolarisApiClient.class)) {
+      return env.client();
+    } else if (type.isAssignableFrom(ClientCredentials.class)) {
+      return env.server.adminCredentials();
+    } else if (type.isAssignableFrom(AuthToken.class)) {
+      return env.server.adminToken();
+    }
+    throw new IllegalStateException("Unable to resolve parameter: " + 
parameterContext);
+  }
+
+  private Env env(ExtensionContext context) {
+    ExtensionContext classCtx = classContext(context);
+    ExtensionContext.Store store = classCtx.getStore(NAMESPACE);
+    return store.getOrComputeIfAbsent(
+        Env.class,
+        (key) -> {
+          Class<?> testClass = classCtx.getRequiredTestClass();
+          Map<String, String> featureConfig =
+              AnnotationUtils.findRepeatableAnnotations(testClass, 
PolarisFeatureConfig.class)
+                  .stream()
+                  .collect(
+                      Collectors.toMap(PolarisFeatureConfig::name, 
PolarisFeatureConfig::value));
+          return new Env(manager.realm(), manager.startServer(featureConfig));
+        },
+        Env.class);
+  }
+
+  private ExtensionContext classContext(ExtensionContext context) {
+    while (context.getParent().isPresent()) {
+      UniqueId id = UniqueId.parse(context.getUniqueId());
+      if ("class".equals(id.getLastSegment().getType())) {
+        break;
+      }
+
+      context = context.getParent().get();
+    }
+
+    return context;
+  }
+
+  private static class Env implements CloseableResource {
+    private final String realm;
+    private final Server server;
+    private final Client client;
+
+    private Env(String realm, Server server) {
+      this.realm = realm;
+      this.server = server;
+
+      ObjectMapper mapper = new ObjectMapper();

Review Comment:
   Unresolving this conversation because it turns out the `Server` impl will 
need access to an `ObjectMapper`. We can't access the one created by Quarkus 
because this is a black box test. But we may be able to share the object mapper 
created here with the server impl. This is minor though, for now my Quarkus 
server impl is simply creating another `ObjectMapper` identical to this one.



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