dimas-b commented on code in PR #590: URL: https://github.com/apache/polaris/pull/590#discussion_r1900170255
########## 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)); Review Comment: Let me see if we this can be refactored to fit Quarkus better -- 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]
