dimas-b commented on code in PR #590: URL: https://github.com/apache/polaris/pull/590#discussion_r1898611969
########## 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: To clarify: if a remote server is available outside the JUnit5 lifecycle, one can simply make an Server Manager impl. that returned a pre-configured URI and Realm, and then use a JUnit5 "suite" to execute tests from the new test module. -- 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]
