Skip to content

Commit

Permalink
Enable re-using polaris-service tests (apache#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew4699 authored Sep 13, 2024
1 parent 19c8258 commit 0b7d6c0
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 28 deletions.
7 changes: 7 additions & 0 deletions polaris-service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ tasks.named<Jar>("jar") {
manifest { attributes["Main-Class"] = "org.apache.polaris.service.PolarisApplication" }
}

tasks.register<Jar>("testJar") {
archiveClassifier.set("tests")
from(sourceSets.test.get().output)
}

val shadowJar =
tasks.named<ShadowJar>("shadowJar") {
manifest { attributes["Main-Class"] = "org.apache.polaris.service.PolarisApplication" }
Expand All @@ -255,3 +260,5 @@ tasks.register<Sync>("prepareDockerDist") {
}

tasks.named("build").configure { dependsOn("prepareDockerDist") }

tasks.named("assemble").configure { dependsOn("testJar") }
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.apache.polaris.service.auth.BasePolarisAuthenticator;
import org.apache.polaris.service.config.PolarisApplicationConfig;
import org.apache.polaris.service.test.PolarisConnectionExtension;
import org.apache.polaris.service.test.PolarisRealm;
import org.apache.polaris.service.test.SnowmanCredentialsExtension;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.InstanceOfAssertFactories;
Expand Down Expand Up @@ -112,9 +113,10 @@ public class PolarisApplicationIntegrationTest {
@BeforeAll
public static void setup(
PolarisConnectionExtension.PolarisToken userToken,
SnowmanCredentialsExtension.SnowmanCredentials snowmanCredentials)
SnowmanCredentialsExtension.SnowmanCredentials snowmanCredentials,
@PolarisRealm String polarisRealm)
throws IOException {
realm = PolarisConnectionExtension.getTestRealm(PolarisApplicationIntegrationTest.class);
realm = polarisRealm;

testDir = Path.of("build/test_data/iceberg/" + realm);
FileUtils.deleteQuietly(testDir.toFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.polaris.service.PolarisApplication;
import org.apache.polaris.service.config.PolarisApplicationConfig;
import org.apache.polaris.service.test.PolarisConnectionExtension;
import org.apache.polaris.service.test.PolarisRealm;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -61,9 +62,11 @@ public class PolarisOverlappingCatalogTest {
private static String realm;

@BeforeAll
public static void setup(PolarisConnectionExtension.PolarisToken adminToken) throws IOException {
public static void setup(
PolarisConnectionExtension.PolarisToken adminToken, @PolarisRealm String polarisRealm)
throws IOException {
userToken = adminToken.token();
realm = PolarisConnectionExtension.getTestRealm(PolarisOverlappingCatalogTest.class);
realm = polarisRealm;

// Set up the database location
PolarisConnectionExtension.createTestDir(realm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.polaris.service.PolarisApplication;
import org.apache.polaris.service.config.PolarisApplicationConfig;
import org.apache.polaris.service.test.PolarisConnectionExtension;
import org.apache.polaris.service.test.PolarisRealm;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -135,9 +136,10 @@ public String toString() {
}

@BeforeEach
public void setup(PolarisConnectionExtension.PolarisToken adminToken) {
public void setup(
PolarisConnectionExtension.PolarisToken adminToken, @PolarisRealm String polarisRealm) {
userToken = adminToken.token();
realm = PolarisConnectionExtension.getTestRealm(PolarisServiceImplIntegrationTest.class);
realm = polarisRealm;
defaultCatalog.catalog = String.format("default_catalog_%s", UUID.randomUUID().toString());
laxCatalog.catalog = String.format("lax_catalog_%s", UUID.randomUUID().toString());
strictCatalog.catalog = String.format("strict_catalog_%s", UUID.randomUUID().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.apache.polaris.service.auth.TokenUtils;
import org.apache.polaris.service.config.PolarisApplicationConfig;
import org.apache.polaris.service.test.PolarisConnectionExtension;
import org.apache.polaris.service.test.PolarisRealm;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -99,9 +100,11 @@ public class PolarisServiceImplIntegrationTest {
private static String realm;

@BeforeAll
public static void setup(PolarisConnectionExtension.PolarisToken adminToken) throws IOException {
public static void setup(
PolarisConnectionExtension.PolarisToken adminToken, @PolarisRealm String polarisRealm)
throws IOException {
userToken = adminToken.token();
realm = PolarisConnectionExtension.getTestRealm(PolarisServiceImplIntegrationTest.class);
realm = polarisRealm;

// Set up test location
PolarisConnectionExtension.createTestDir(realm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.apache.polaris.service.config.PolarisApplicationConfig;
import org.apache.polaris.service.test.PolarisConnectionExtension;
import org.apache.polaris.service.test.PolarisConnectionExtension.PolarisToken;
import org.apache.polaris.service.test.PolarisRealm;
import org.apache.polaris.service.test.SnowmanCredentialsExtension;
import org.apache.polaris.service.test.SnowmanCredentialsExtension.SnowmanCredentials;
import org.apache.polaris.service.types.NotificationRequest;
Expand Down Expand Up @@ -121,22 +122,24 @@ public class PolarisRestCatalogIntegrationTest extends CatalogTests<RESTCatalog>
private RESTCatalog restCatalog;
private String currentCatalogName;
private String userToken;
private static String realm;
private String realm;

private final String catalogBaseLocation =
S3_BUCKET_BASE + "/" + System.getenv("USER") + "/path/to/data";

@BeforeAll
public static void setup() throws IOException {
realm = PolarisConnectionExtension.getTestRealm(PolarisRestCatalogIntegrationTest.class);

public static void setup(@PolarisRealm String realm) throws IOException {
// Set up test location
PolarisConnectionExtension.createTestDir(realm);
}

@BeforeEach
public void before(
TestInfo testInfo, PolarisToken adminToken, SnowmanCredentials snowmanCredentials) {
TestInfo testInfo,
PolarisToken adminToken,
SnowmanCredentials snowmanCredentials,
@PolarisRealm String realm) {
this.realm = realm;
userToken =
TokenUtils.getTokenFromSecrets(
EXT.client(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.apache.polaris.service.config.PolarisApplicationConfig;
import org.apache.polaris.service.test.PolarisConnectionExtension;
import org.apache.polaris.service.test.PolarisConnectionExtension.PolarisToken;
import org.apache.polaris.service.test.PolarisRealm;
import org.apache.polaris.service.test.SnowmanCredentialsExtension;
import org.apache.polaris.service.test.SnowmanCredentialsExtension.SnowmanCredentials;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -87,19 +88,19 @@ public class PolarisRestCatalogViewIntegrationTest extends ViewCatalogTests<REST
"server.adminConnectors[0].port", "0")); // Bind to random port to support parallelism

private RESTCatalog restCatalog;
private static String realm;

@BeforeAll
public static void setup() throws IOException {
realm = PolarisConnectionExtension.getTestRealm(PolarisRestCatalogViewIntegrationTest.class);

public static void setup(@PolarisRealm String realm) throws IOException {
// Set up test location
PolarisConnectionExtension.createTestDir(realm);
}

@BeforeEach
public void before(
TestInfo testInfo, PolarisToken adminToken, SnowmanCredentials snowmanCredentials) {
TestInfo testInfo,
PolarisToken adminToken,
SnowmanCredentials snowmanCredentials,
@PolarisRealm String realm) {
String userToken = adminToken.token();
testInfo
.getTestMethod()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.polaris.service.PolarisApplication;
import org.apache.polaris.service.config.PolarisApplicationConfig;
import org.apache.polaris.service.test.PolarisConnectionExtension;
import org.apache.polaris.service.test.PolarisRealm;
import org.apache.polaris.service.types.NotificationRequest;
import org.apache.polaris.service.types.NotificationType;
import org.apache.polaris.service.types.TableUpdateNotification;
Expand Down Expand Up @@ -77,14 +78,14 @@ public class PolarisSparkIntegrationTest {
new S3MockContainer("3.9.1").withInitialBuckets("my-bucket,my-old-bucket");
private static PolarisConnectionExtension.PolarisToken polarisToken;
private static SparkSession spark;
private static String realm;
private String realm;

@BeforeAll
public static void setup(PolarisConnectionExtension.PolarisToken polarisToken)
public static void setup(
PolarisConnectionExtension.PolarisToken polarisToken, @PolarisRealm String realm)
throws IOException {
s3Container.start();
PolarisSparkIntegrationTest.polarisToken = polarisToken;
realm = PolarisConnectionExtension.getTestRealm(PolarisSparkIntegrationTest.class);

// Set up test location
PolarisConnectionExtension.createTestDir(realm);
Expand All @@ -96,7 +97,8 @@ public static void cleanup() {
}

@BeforeEach
public void before() {
public void before(@PolarisRealm String realm) {
this.realm = realm;
AwsStorageConfigInfo awsConfigModel =
AwsStorageConfigInfo.builder()
.setRoleArn("arn:aws:iam::123456789012:role/my-role")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void beforeAll(ExtensionContext extensionContext) throws Exception {
}

// Generate unique realm using test name for each test since the tests can run in parallel
realm = getTestRealm(extensionContext.getRequiredTestClass());
realm = extensionContext.getRequiredTestClass().getName().replace('.', '_');
extensionContext
.getStore(Namespace.create(extensionContext.getRequiredTestClass()))
.put(REALM_PROPERTY_KEY, realm);
Expand Down Expand Up @@ -127,10 +127,6 @@ public void afterAll(ExtensionContext context) {
}
}

public static String getTestRealm(Class testClassName) {
return testClassName.getName().replace('.', '_');
}

public static void createTestDir(String realm) throws IOException {
// Set up the database location
Path testDir = Path.of("build/test_data/polaris/" + realm);
Expand Down Expand Up @@ -183,7 +179,9 @@ public boolean supportsParameter(
.getType()
.equals(PolarisConnectionExtension.PolarisToken.class)
|| parameterContext.getParameter().getType().equals(MetaStoreManagerFactory.class)
|| parameterContext.getParameter().getType().equals(PolarisPrincipalSecrets.class);
|| parameterContext.getParameter().getType().equals(PolarisPrincipalSecrets.class)
|| (parameterContext.getParameter().getType().equals(String.class)
&& parameterContext.getParameter().isAnnotationPresent(PolarisRealm.class));
}

@Override
Expand All @@ -199,6 +197,9 @@ public Object resolveParameter(
adminSecrets.getMainSecret(),
realm);
return new PolarisToken(token);
} else if (parameterContext.getParameter().getType().equals(String.class)
&& parameterContext.getParameter().isAnnotationPresent(PolarisRealm.class)) {
return realm;
} else {
return metaStoreManagerFactory;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotation used to specify where to inject the Polaris test realm identifier. This is provided by
* PolarisConnectionExtension.
*/
@Target({ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface PolarisRealm {}

0 comments on commit 0b7d6c0

Please sign in to comment.