adutra commented on code in PR #590: URL: https://github.com/apache/polaris/pull/590#discussion_r1897842819
########## integration-tests/src/main/java/org/apache/polaris/service/it/env/Server.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.it.env; + +import java.net.URI; + +public interface Server extends AutoCloseable { + URI baseUri(); + + AuthToken adminToken(); + + ClientCredentials adminCredentials(); Review Comment: Where has the `Snowman` user gone? ########## dropwizard/service/src/test/java/org/apache/polaris/service/dropwizard/it/DropwizardServerManager.java: ########## @@ -0,0 +1,108 @@ +/* + * 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.dropwizard.it; + +import io.dropwizard.testing.ConfigOverride; +import io.dropwizard.testing.ResourceHelpers; +import io.dropwizard.testing.junit5.DropwizardAppExtension; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; +import org.apache.polaris.service.dropwizard.PolarisApplication; +import org.apache.polaris.service.dropwizard.auth.TokenUtils; +import org.apache.polaris.service.dropwizard.config.PolarisApplicationConfig; +import org.apache.polaris.service.it.env.AuthToken; +import org.apache.polaris.service.it.env.ClientCredentials; +import org.apache.polaris.service.it.env.Server; +import org.apache.polaris.service.it.ext.PolarisServerManager; + +public class DropwizardServerManager implements PolarisServerManager { + public static final String TEST_REALM = "POLARIS"; + + @Override + public String realm() { + return TEST_REALM; + } + + @Override + public Server startServer(Map<String, String> featureConfig) { + return new Holder(featureConfig); + } + + private static class Holder implements Server { + private final DropwizardAppExtension<PolarisApplicationConfig> ext; + private final AuthToken token; + + public Holder(Map<String, String> featureConfig) { + Map<String, String> config = new HashMap<>(); + featureConfig.forEach((k, v) -> config.put("featureConfiguration." + k, v)); + // Bind to random port to support parallelism + config.put("server.applicationConnectors[0].port", "0"); + config.put("server.adminConnectors[0].port", "0"); + + ConfigOverride[] overrides = + config.entrySet().stream() + .map((e) -> ConfigOverride.config(e.getKey(), e.getValue())) + .toList() + .toArray(new ConfigOverride[0]); + ext = + new DropwizardAppExtension<>( + PolarisApplication.class, + ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), + overrides); + + try { + ext.before(); + } catch (Exception e) { + throw new RuntimeException(e); + } + + token = new AuthToken(getToken(), "root"); + } + + private String getToken() { + return TokenUtils.getTokenFromSecrets( + ext.client(), + baseUri().toString(), + adminCredentials().clientId(), + adminCredentials().clientSecret(), + TEST_REALM); + } + + @Override + public URI baseUri() { + return URI.create(String.format("http://localhost:%d", ext.getLocalPort())); + } + + @Override + public AuthToken adminToken() { + return token; + } + + @Override + public ClientCredentials adminCredentials() { + return new ClientCredentials("test-admin", "test-secret"); Review Comment: The old `TestEnv` extension used to append a "test ID" to the generated credentials afaict. ########## gradle/libs.versions.toml: ########## @@ -74,6 +74,7 @@ smallrye-common-annotation = { module = "io.smallrye.common:smallrye-common-anno spotbugs-annotations = { module = "com.github.spotbugs:spotbugs-annotations", version = "4.8.5" } swagger-annotations = { module = "io.swagger:swagger-annotations", version.ref = "swagger" } swagger-jaxrs = { module = "io.swagger:swagger-jaxrs", version.ref = "swagger" } +jaxrs-api = { module = "jakarta.ws.rs:jakarta.ws.rs-api", version = "3.0.0" } Review Comment: This lib is already declared as `jakarta-ws-rs-api`. ########## 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: Couldn't we create this client outside of the extension? In Quarkus, it would be better to inject the `ObjectMapper` that's used server-side, but it won't be available for injection here. ########## dropwizard/service/src/test/java/org/apache/polaris/service/dropwizard/it/DropwizardServerManager.java: ########## @@ -0,0 +1,108 @@ +/* + * 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.dropwizard.it; + +import io.dropwizard.testing.ConfigOverride; +import io.dropwizard.testing.ResourceHelpers; +import io.dropwizard.testing.junit5.DropwizardAppExtension; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; +import org.apache.polaris.service.dropwizard.PolarisApplication; +import org.apache.polaris.service.dropwizard.auth.TokenUtils; +import org.apache.polaris.service.dropwizard.config.PolarisApplicationConfig; +import org.apache.polaris.service.it.env.AuthToken; +import org.apache.polaris.service.it.env.ClientCredentials; +import org.apache.polaris.service.it.env.Server; +import org.apache.polaris.service.it.ext.PolarisServerManager; + +public class DropwizardServerManager implements PolarisServerManager { + public static final String TEST_REALM = "POLARIS"; + + @Override + public String realm() { + return TEST_REALM; + } + + @Override + public Server startServer(Map<String, String> featureConfig) { + return new Holder(featureConfig); + } + + private static class Holder implements Server { + private final DropwizardAppExtension<PolarisApplicationConfig> ext; + private final AuthToken token; + + public Holder(Map<String, String> featureConfig) { + Map<String, String> config = new HashMap<>(); + featureConfig.forEach((k, v) -> config.put("featureConfiguration." + k, v)); + // Bind to random port to support parallelism + config.put("server.applicationConnectors[0].port", "0"); + config.put("server.adminConnectors[0].port", "0"); + + ConfigOverride[] overrides = + config.entrySet().stream() + .map((e) -> ConfigOverride.config(e.getKey(), e.getValue())) + .toList() + .toArray(new ConfigOverride[0]); + ext = + new DropwizardAppExtension<>( + PolarisApplication.class, + ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), + overrides); + + try { + ext.before(); + } catch (Exception e) { + throw new RuntimeException(e); + } + + token = new AuthToken(getToken(), "root"); + } + + private String getToken() { + return TokenUtils.getTokenFromSecrets( + ext.client(), + baseUri().toString(), + adminCredentials().clientId(), + adminCredentials().clientSecret(), + TEST_REALM); + } + + @Override + public URI baseUri() { + return URI.create(String.format("http://localhost:%d", ext.getLocalPort())); Review Comment: The old `TestEnv` extension could modify this to hit a remote Polaris server afaict. ########## 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(); + mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.setPropertyNamingStrategy(new PropertyNamingStrategies.KebabCaseStrategy()); + RESTSerializers.registerAll(mapper); Review Comment: I think we are missing a call to: ```java org.apache.polaris.service.config.Serializers.registerSerializers(objectMapper) ``` -- 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]
