From 90f3b3f4bc2deb3ad5d8d3b54a4cc21facdde580 Mon Sep 17 00:00:00 2001 From: Yun Zou Date: Mon, 2 Dec 2024 11:24:21 -0800 Subject: [PATCH 1/2] refactor test --- .../PolarisApplicationConfigurationTest.java | 26 +++------- .../PolarisApplicationIntegrationTest.java | 15 +----- .../TimedApplicationEventListenerTest.java | 15 +----- .../admin/PolarisOverlappingTableTest.java | 27 ++++------- .../PolarisServiceImplIntegrationTest.java | 21 ++++---- .../PolarisRestCatalogIntegrationTest.java | 14 +----- ...PolarisRestCatalogViewIntegrationTest.java | 15 +----- .../catalog/PolarisSparkIntegrationTest.java | 10 +--- .../catalog/io/FileIOIntegrationTest.java | 14 +----- .../ratelimiter/RateLimiterFilterTest.java | 22 +++------ .../service/test/PolarisApplicationUtils.java | 48 +++++++++++++++++++ 11 files changed, 90 insertions(+), 137 deletions(-) create mode 100644 polaris-service/src/test/java/org/apache/polaris/service/test/PolarisApplicationUtils.java diff --git a/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationConfigurationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationConfigurationTest.java index 74442e040..00ca77f29 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationConfigurationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationConfigurationTest.java @@ -27,6 +27,7 @@ import org.apache.polaris.extension.persistence.impl.eclipselink.EclipseLinkPolarisMetaStoreManagerFactory; import org.apache.polaris.service.config.PolarisApplicationConfig; import org.apache.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory; +import org.apache.polaris.service.test.PolarisApplicationUtils; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -34,19 +35,9 @@ @ExtendWith(DropwizardExtensionsSupport.class) public class PolarisApplicationConfigurationTest { - public static final String CONFIG_PATH = - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"); - // Bind to random ports to support parallelism - public static final ConfigOverride RANDOM_APP_PORT = - ConfigOverride.config("server.applicationConnectors[0].port", "0"); - public static final ConfigOverride RANDOM_ADMIN_PORT = - ConfigOverride.config("server.adminConnectors[0].port", "0"); - @Nested class DefaultMetastore { - private final DropwizardAppExtension app = - new DropwizardAppExtension<>( - PolarisApplication.class, CONFIG_PATH, RANDOM_APP_PORT, RANDOM_ADMIN_PORT); + private final DropwizardAppExtension app = PolarisApplicationUtils.createTestPolarisApplication(); @Test void testMetastoreType() { @@ -58,14 +49,11 @@ void testMetastoreType() { @Nested class EclipseLinkMetastore { private final DropwizardAppExtension app = - new DropwizardAppExtension<>( - PolarisApplication.class, - CONFIG_PATH, - RANDOM_APP_PORT, - RANDOM_ADMIN_PORT, - ConfigOverride.config("metaStoreManager.type", "eclipse-link"), - ConfigOverride.config("metaStoreManager.persistence-unit", "test-unit"), - ConfigOverride.config("metaStoreManager.conf-file", "/test-conf-file")); + PolarisApplicationUtils.createTestPolarisApplication( + ConfigOverride.config("metaStoreManager.type", "eclipse-link"), + ConfigOverride.config("metaStoreManager.persistence-unit", "test-unit"), + ConfigOverride.config("metaStoreManager.conf-file", "/test-conf-file")); + @Test void testMetastoreType() { diff --git a/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java index 465b34d51..336a066c8 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java @@ -81,10 +81,7 @@ import org.apache.polaris.core.entity.PolarisEntityConstants; 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.apache.polaris.service.test.TestEnvironmentExtension; +import org.apache.polaris.service.test.*; import org.apache.polaris.service.throttling.RequestThrottlingErrorResponse; import org.assertj.core.api.Assertions; import org.assertj.core.api.InstanceOfAssertFactories; @@ -109,15 +106,7 @@ public class PolarisApplicationIntegrationTest { LoggerFactory.getLogger(PolarisApplicationIntegrationTest.class); public static final String PRINCIPAL_ROLE_NAME = "admin"; - private static final DropwizardAppExtension EXT = - new DropwizardAppExtension<>( - PolarisApplication.class, - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), - ConfigOverride.config( - "server.applicationConnectors[0].port", - "0"), // Bind to random port to support parallelism - ConfigOverride.config( - "server.adminConnectors[0].port", "0")); // Bind to random port to support parallelism + private static final DropwizardAppExtension EXT = PolarisApplicationUtils.createTestPolarisApplication(); private static String userToken; private static SnowmanCredentialsExtension.SnowmanCredentials snowmanCredentials; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/TimedApplicationEventListenerTest.java b/polaris-service/src/test/java/org/apache/polaris/service/TimedApplicationEventListenerTest.java index c0218b6a4..64c0c2642 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/TimedApplicationEventListenerTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/TimedApplicationEventListenerTest.java @@ -37,11 +37,7 @@ import org.apache.polaris.core.resource.TimedApi; import org.apache.polaris.service.admin.api.PolarisPrincipalsApi; 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.apache.polaris.service.test.TestEnvironmentExtension; -import org.apache.polaris.service.test.TestMetricsUtil; +import org.apache.polaris.service.test.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -56,14 +52,7 @@ }) public class TimedApplicationEventListenerTest { private static final DropwizardAppExtension EXT = - new DropwizardAppExtension<>( - PolarisApplication.class, - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), - ConfigOverride.config( - "server.applicationConnectors[0].port", - "0"), // Bind to random port to support parallelism - ConfigOverride.config( - "server.adminConnectors[0].port", "0")); // Bind to random port to support parallelism + PolarisApplicationUtils.createTestPolarisApplication(); private static final int ERROR_CODE = Response.Status.NOT_FOUND.getStatusCode(); private static final String ENDPOINT = "api/management/v1/principals"; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisOverlappingTableTest.java b/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisOverlappingTableTest.java index bb60f7149..0bd868c53 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisOverlappingTableTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisOverlappingTableTest.java @@ -43,6 +43,7 @@ import org.apache.polaris.core.admin.model.StorageConfigInfo; import org.apache.polaris.service.PolarisApplication; import org.apache.polaris.service.config.PolarisApplicationConfig; +import org.apache.polaris.service.test.PolarisApplicationUtils; import org.apache.polaris.service.test.PolarisConnectionExtension; import org.apache.polaris.service.test.PolarisRealm; import org.apache.polaris.service.test.TestEnvironmentExtension; @@ -59,26 +60,16 @@ }) public class PolarisOverlappingTableTest { private static final DropwizardAppExtension BASE_EXT = - new DropwizardAppExtension<>( - PolarisApplication.class, - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), - // Bind to random port to support parallelism - ConfigOverride.config("server.applicationConnectors[0].port", "0"), - ConfigOverride.config("server.adminConnectors[0].port", "0"), - // Enforce table location constraints - ConfigOverride.config("featureConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION", "false"), - ConfigOverride.config("featureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP", "false")); + PolarisApplicationUtils.createTestPolarisApplication( + // Enforce table location constraints + ConfigOverride.config("featureConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION", "false"), + ConfigOverride.config("featureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP", "false")); private static final DropwizardAppExtension LAX_EXT = - new DropwizardAppExtension<>( - PolarisApplication.class, - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), - // Bind to random port to support parallelism - ConfigOverride.config("server.applicationConnectors[0].port", "0"), - ConfigOverride.config("server.adminConnectors[0].port", "0"), - // Relax table location constraints - ConfigOverride.config("featureConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION", "true"), - ConfigOverride.config("featureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP", "true")); + PolarisApplicationUtils.createTestPolarisApplication( + // Relax table location constraints + ConfigOverride.config("featureConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION", "true"), + ConfigOverride.config("featureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP", "true")); private static PolarisConnectionExtension.PolarisToken adminToken; private static String userToken; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisServiceImplIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisServiceImplIntegrationTest.java index d20fd37f4..d00de6968 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisServiceImplIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisServiceImplIntegrationTest.java @@ -90,6 +90,7 @@ import org.apache.polaris.service.auth.BasePolarisAuthenticator; import org.apache.polaris.service.auth.TokenUtils; import org.apache.polaris.service.config.PolarisApplicationConfig; +import org.apache.polaris.service.test.PolarisApplicationUtils; import org.apache.polaris.service.test.PolarisConnectionExtension; import org.apache.polaris.service.test.PolarisRealm; import org.apache.polaris.service.test.TestEnvironmentExtension; @@ -118,19 +119,13 @@ public class PolarisServiceImplIntegrationTest { // slate on every test case; otherwise, leftover state from one test from failures will interfere // with other test cases. private static final DropwizardAppExtension EXT = - new DropwizardAppExtension<>( - PolarisApplication.class, - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), - ConfigOverride.config( - "server.applicationConnectors[0].port", - "0"), // Bind to random port to support parallelism - ConfigOverride.config("server.adminConnectors[0].port", "0"), - - // disallow FILE urls for the sake of tests below - ConfigOverride.config( - "featureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES", "S3,GCS,AZURE"), - ConfigOverride.config("gcp_credentials.access_token", "abc"), - ConfigOverride.config("gcp_credentials.expires_in", "12345")); + PolarisApplicationUtils.createTestPolarisApplication( + // disallow FILE urls for the sake of tests below + ConfigOverride.config( + "featureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES", "S3,GCS,AZURE"), + ConfigOverride.config("gcp_credentials.access_token", "abc"), + ConfigOverride.config("gcp_credentials.expires_in", "12345")); + private static String userToken; private static String realm; private static String clientId; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogIntegrationTest.java index 27646faa9..a27172294 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogIntegrationTest.java @@ -82,12 +82,9 @@ import org.apache.polaris.service.PolarisApplication; 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.*; 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.test.TestEnvironmentExtension; import org.apache.polaris.service.types.NotificationRequest; import org.apache.polaris.service.types.NotificationType; import org.apache.polaris.service.types.TableUpdateNotification; @@ -117,14 +114,7 @@ public class PolarisRestCatalogIntegrationTest extends CatalogTests Optional.ofNullable(System.getenv("INTEGRATION_TEST_S3_PATH")) .orElse("file:///tmp/buckets/my-bucket"); private static final DropwizardAppExtension EXT = - new DropwizardAppExtension<>( - PolarisApplication.class, - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), - ConfigOverride.config( - "server.applicationConnectors[0].port", - "0"), // Bind to random port to support parallelism - ConfigOverride.config( - "server.adminConnectors[0].port", "0")); // Bind to random port to support parallelism + PolarisApplicationUtils.createTestPolarisApplication(); protected static final String VIEW_QUERY = "select * from ns1.layer1_table"; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogViewIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogViewIntegrationTest.java index e9897a1f7..7575fcb57 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogViewIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogViewIntegrationTest.java @@ -36,13 +36,9 @@ import org.apache.polaris.core.entity.CatalogEntity; 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.*; 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.test.TestEnvironment; -import org.apache.polaris.service.test.TestEnvironmentExtension; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -61,14 +57,7 @@ }) public abstract class PolarisRestCatalogViewIntegrationTest extends ViewCatalogTests { private static final DropwizardAppExtension EXT = - new DropwizardAppExtension<>( - PolarisApplication.class, - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), - ConfigOverride.config( - "server.applicationConnectors[0].port", - "0"), // Bind to random port to support parallelism - ConfigOverride.config( - "server.adminConnectors[0].port", "0")); // Bind to random port to support parallelism + PolarisApplicationUtils.createTestPolarisApplication(); private RESTCatalog restCatalog; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisSparkIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisSparkIntegrationTest.java index 35bb96096..c6d34a583 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisSparkIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisSparkIntegrationTest.java @@ -43,6 +43,7 @@ import org.apache.polaris.core.admin.model.StorageConfigInfo; import org.apache.polaris.service.PolarisApplication; import org.apache.polaris.service.config.PolarisApplicationConfig; +import org.apache.polaris.service.test.PolarisApplicationUtils; import org.apache.polaris.service.test.PolarisConnectionExtension; import org.apache.polaris.service.test.PolarisRealm; import org.apache.polaris.service.test.TestEnvironmentExtension; @@ -68,14 +69,7 @@ }) public class PolarisSparkIntegrationTest { private static final DropwizardAppExtension EXT = - new DropwizardAppExtension<>( - PolarisApplication.class, - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), - ConfigOverride.config( - "server.applicationConnectors[0].port", - "0"), // Bind to random port to support parallelism - ConfigOverride.config( - "server.adminConnectors[0].port", "0")); // Bind to random port to support parallelism + PolarisApplicationUtils.createTestPolarisApplication(); public static final String CATALOG_NAME = "mycatalog"; public static final String EXTERNAL_CATALOG_NAME = "external_catalog"; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/catalog/io/FileIOIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/catalog/io/FileIOIntegrationTest.java index 9b0f2d7fd..151afe593 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/catalog/io/FileIOIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/catalog/io/FileIOIntegrationTest.java @@ -55,10 +55,7 @@ import org.apache.polaris.service.catalog.TestUtil; import org.apache.polaris.service.config.PolarisApplicationConfig; import org.apache.polaris.service.exception.IcebergExceptionMapper; -import org.apache.polaris.service.test.PolarisConnectionExtension; -import org.apache.polaris.service.test.PolarisRealm; -import org.apache.polaris.service.test.SnowmanCredentialsExtension; -import org.apache.polaris.service.test.TestEnvironmentExtension; +import org.apache.polaris.service.test.*; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -76,14 +73,7 @@ }) public class FileIOIntegrationTest { private static final DropwizardAppExtension EXT = - new DropwizardAppExtension<>( - PolarisApplication.class, - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), - ConfigOverride.config( - "server.applicationConnectors[0].port", - "0"), // Bind to random port to support parallelism - ConfigOverride.config("server.adminConnectors[0].port", "0"), - ConfigOverride.config("io.factoryType", "test")); + PolarisApplicationUtils.createTestPolarisApplication(ConfigOverride.config("io.factoryType", "test")); private static final String catalogBaseLocation = "file:/tmp/buckets/my-bucket/path/to/data"; private static TestFileIOFactory ioFactory; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java b/polaris-service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java index 772fc6aac..8fd9b0a3a 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java @@ -34,11 +34,7 @@ import java.util.function.Consumer; 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.test.SnowmanCredentialsExtension; -import org.apache.polaris.service.test.TestEnvironmentExtension; -import org.apache.polaris.service.test.TestMetricsUtil; +import org.apache.polaris.service.test.*; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -57,17 +53,11 @@ public class RateLimiterFilterTest { private static final long REQUESTS_PER_SECOND = 5; private static final long WINDOW_SECONDS = 10; private static final DropwizardAppExtension EXT = - new DropwizardAppExtension<>( - PolarisApplication.class, - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), - ConfigOverride.config( - "server.applicationConnectors[0].port", - "0"), // Bind to random port to support parallelism - ConfigOverride.config("server.adminConnectors[0].port", "0"), - ConfigOverride.config("rateLimiter.type", "mock-realm-token-bucket"), - ConfigOverride.config( - "rateLimiter.requestsPerSecond", String.valueOf(REQUESTS_PER_SECOND)), - ConfigOverride.config("rateLimiter.windowSeconds", String.valueOf(WINDOW_SECONDS))); + PolarisApplicationUtils.createTestPolarisApplication( + ConfigOverride.config("rateLimiter.type", "mock-realm-token-bucket"), + ConfigOverride.config( + "rateLimiter.requestsPerSecond", String.valueOf(REQUESTS_PER_SECOND)), + ConfigOverride.config("rateLimiter.windowSeconds", String.valueOf(WINDOW_SECONDS))); private static String userToken; private static String realm; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/test/PolarisApplicationUtils.java b/polaris-service/src/test/java/org/apache/polaris/service/test/PolarisApplicationUtils.java new file mode 100644 index 000000000..f4660e7af --- /dev/null +++ b/polaris-service/src/test/java/org/apache/polaris/service/test/PolarisApplicationUtils.java @@ -0,0 +1,48 @@ +/* + * 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 io.dropwizard.testing.ConfigOverride; +import io.dropwizard.testing.ResourceHelpers; +import io.dropwizard.testing.junit5.DropwizardAppExtension; +import org.apache.polaris.service.PolarisApplication; +import org.apache.polaris.service.config.PolarisApplicationConfig; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +public class PolarisApplicationUtils { + + public static DropwizardAppExtension createTestPolarisApplication(ConfigOverride... configOverrides) { + List appConfigOverrides = new ArrayList<>(); + // Bind to random port to support parallelism + appConfigOverrides.add(ConfigOverride.config("server.applicationConnectors[0].port", "0")); + appConfigOverrides.add(ConfigOverride.config("server.adminConnectors[0].port", "0")); + // add the other input configurations + appConfigOverrides.addAll(Arrays.asList(configOverrides)); + + return new DropwizardAppExtension<>( + PolarisApplication.class, + ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), + appConfigOverrides.toArray(new ConfigOverride[0]) + ); + } +} \ No newline at end of file From c4ab31e339a35761f86b45283e24f746e014fdbe Mon Sep 17 00:00:00 2001 From: Yun Zou Date: Mon, 2 Dec 2024 11:30:58 -0800 Subject: [PATCH 2/2] refactor test --- .../PolarisApplicationConfigurationTest.java | 13 ++++--- .../PolarisApplicationIntegrationTest.java | 5 ++- .../TimedApplicationEventListenerTest.java | 4 +-- .../admin/PolarisOverlappingTableTest.java | 18 +++++----- .../PolarisServiceImplIntegrationTest.java | 14 ++++---- .../PolarisRestCatalogIntegrationTest.java | 5 +-- ...PolarisRestCatalogViewIntegrationTest.java | 5 +-- .../catalog/PolarisSparkIntegrationTest.java | 5 +-- .../catalog/io/FileIOIntegrationTest.java | 5 ++- .../ratelimiter/RateLimiterFilterTest.java | 12 +++---- .../service/test/PolarisApplicationUtils.java | 34 +++++++++---------- 11 files changed, 49 insertions(+), 71 deletions(-) diff --git a/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationConfigurationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationConfigurationTest.java index 00ca77f29..5a20e785f 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationConfigurationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationConfigurationTest.java @@ -21,7 +21,6 @@ import static org.assertj.core.api.Assertions.assertThat; import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.ResourceHelpers; import io.dropwizard.testing.junit5.DropwizardAppExtension; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import org.apache.polaris.extension.persistence.impl.eclipselink.EclipseLinkPolarisMetaStoreManagerFactory; @@ -37,7 +36,8 @@ public class PolarisApplicationConfigurationTest { @Nested class DefaultMetastore { - private final DropwizardAppExtension app = PolarisApplicationUtils.createTestPolarisApplication(); + private final DropwizardAppExtension app = + PolarisApplicationUtils.createTestPolarisApplication(); @Test void testMetastoreType() { @@ -49,11 +49,10 @@ void testMetastoreType() { @Nested class EclipseLinkMetastore { private final DropwizardAppExtension app = - PolarisApplicationUtils.createTestPolarisApplication( - ConfigOverride.config("metaStoreManager.type", "eclipse-link"), - ConfigOverride.config("metaStoreManager.persistence-unit", "test-unit"), - ConfigOverride.config("metaStoreManager.conf-file", "/test-conf-file")); - + PolarisApplicationUtils.createTestPolarisApplication( + ConfigOverride.config("metaStoreManager.type", "eclipse-link"), + ConfigOverride.config("metaStoreManager.persistence-unit", "test-unit"), + ConfigOverride.config("metaStoreManager.conf-file", "/test-conf-file")); @Test void testMetastoreType() { diff --git a/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java index 336a066c8..953638e38 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java @@ -25,8 +25,6 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.ResourceHelpers; import io.dropwizard.testing.junit5.DropwizardAppExtension; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import jakarta.ws.rs.ProcessingException; @@ -106,7 +104,8 @@ public class PolarisApplicationIntegrationTest { LoggerFactory.getLogger(PolarisApplicationIntegrationTest.class); public static final String PRINCIPAL_ROLE_NAME = "admin"; - private static final DropwizardAppExtension EXT = PolarisApplicationUtils.createTestPolarisApplication(); + private static final DropwizardAppExtension EXT = + PolarisApplicationUtils.createTestPolarisApplication(); private static String userToken; private static SnowmanCredentialsExtension.SnowmanCredentials snowmanCredentials; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/TimedApplicationEventListenerTest.java b/polaris-service/src/test/java/org/apache/polaris/service/TimedApplicationEventListenerTest.java index 64c0c2642..4dd14644a 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/TimedApplicationEventListenerTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/TimedApplicationEventListenerTest.java @@ -23,8 +23,6 @@ import static org.apache.polaris.service.TimedApplicationEventListener.TAG_API_NAME; import static org.apache.polaris.service.context.DefaultContextResolver.REALM_PROPERTY_KEY; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.ResourceHelpers; import io.dropwizard.testing.junit5.DropwizardAppExtension; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import io.micrometer.core.instrument.Tag; @@ -52,7 +50,7 @@ }) public class TimedApplicationEventListenerTest { private static final DropwizardAppExtension EXT = - PolarisApplicationUtils.createTestPolarisApplication(); + PolarisApplicationUtils.createTestPolarisApplication(); private static final int ERROR_CODE = Response.Status.NOT_FOUND.getStatusCode(); private static final String ENDPOINT = "api/management/v1/principals"; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisOverlappingTableTest.java b/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisOverlappingTableTest.java index 0bd868c53..04cc88288 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisOverlappingTableTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisOverlappingTableTest.java @@ -23,7 +23,6 @@ import static org.assertj.core.api.Assertions.assertThat; import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.ResourceHelpers; import io.dropwizard.testing.junit5.DropwizardAppExtension; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import jakarta.ws.rs.client.Entity; @@ -41,7 +40,6 @@ import org.apache.polaris.core.admin.model.CreateCatalogRequest; import org.apache.polaris.core.admin.model.FileStorageConfigInfo; import org.apache.polaris.core.admin.model.StorageConfigInfo; -import org.apache.polaris.service.PolarisApplication; import org.apache.polaris.service.config.PolarisApplicationConfig; import org.apache.polaris.service.test.PolarisApplicationUtils; import org.apache.polaris.service.test.PolarisConnectionExtension; @@ -60,16 +58,16 @@ }) public class PolarisOverlappingTableTest { private static final DropwizardAppExtension BASE_EXT = - PolarisApplicationUtils.createTestPolarisApplication( - // Enforce table location constraints - ConfigOverride.config("featureConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION", "false"), - ConfigOverride.config("featureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP", "false")); + PolarisApplicationUtils.createTestPolarisApplication( + // Enforce table location constraints + ConfigOverride.config("featureConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION", "false"), + ConfigOverride.config("featureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP", "false")); private static final DropwizardAppExtension LAX_EXT = - PolarisApplicationUtils.createTestPolarisApplication( - // Relax table location constraints - ConfigOverride.config("featureConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION", "true"), - ConfigOverride.config("featureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP", "true")); + PolarisApplicationUtils.createTestPolarisApplication( + // Relax table location constraints + ConfigOverride.config("featureConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION", "true"), + ConfigOverride.config("featureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP", "true")); private static PolarisConnectionExtension.PolarisToken adminToken; private static String userToken; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisServiceImplIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisServiceImplIntegrationTest.java index d00de6968..34eebbe92 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisServiceImplIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisServiceImplIntegrationTest.java @@ -30,7 +30,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.ResourceHelpers; import io.dropwizard.testing.junit5.DropwizardAppExtension; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import jakarta.ws.rs.client.Entity; @@ -86,7 +85,6 @@ import org.apache.polaris.core.admin.model.UpdatePrincipalRoleRequest; import org.apache.polaris.core.entity.PolarisEntityConstants; import org.apache.polaris.core.entity.PolarisPrincipalSecrets; -import org.apache.polaris.service.PolarisApplication; import org.apache.polaris.service.auth.BasePolarisAuthenticator; import org.apache.polaris.service.auth.TokenUtils; import org.apache.polaris.service.config.PolarisApplicationConfig; @@ -119,12 +117,12 @@ public class PolarisServiceImplIntegrationTest { // slate on every test case; otherwise, leftover state from one test from failures will interfere // with other test cases. private static final DropwizardAppExtension EXT = - PolarisApplicationUtils.createTestPolarisApplication( - // disallow FILE urls for the sake of tests below - ConfigOverride.config( - "featureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES", "S3,GCS,AZURE"), - ConfigOverride.config("gcp_credentials.access_token", "abc"), - ConfigOverride.config("gcp_credentials.expires_in", "12345")); + PolarisApplicationUtils.createTestPolarisApplication( + // disallow FILE urls for the sake of tests below + ConfigOverride.config( + "featureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES", "S3,GCS,AZURE"), + ConfigOverride.config("gcp_credentials.access_token", "abc"), + ConfigOverride.config("gcp_credentials.expires_in", "12345")); private static String userToken; private static String realm; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogIntegrationTest.java index a27172294..6f4775293 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogIntegrationTest.java @@ -23,8 +23,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.google.common.collect.ImmutableMap; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.ResourceHelpers; import io.dropwizard.testing.junit5.DropwizardAppExtension; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import jakarta.ws.rs.client.Entity; @@ -79,7 +77,6 @@ import org.apache.polaris.core.admin.model.ViewPrivilege; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.PolarisEntityConstants; -import org.apache.polaris.service.PolarisApplication; import org.apache.polaris.service.auth.TokenUtils; import org.apache.polaris.service.config.PolarisApplicationConfig; import org.apache.polaris.service.test.*; @@ -114,7 +111,7 @@ public class PolarisRestCatalogIntegrationTest extends CatalogTests Optional.ofNullable(System.getenv("INTEGRATION_TEST_S3_PATH")) .orElse("file:///tmp/buckets/my-bucket"); private static final DropwizardAppExtension EXT = - PolarisApplicationUtils.createTestPolarisApplication(); + PolarisApplicationUtils.createTestPolarisApplication(); protected static final String VIEW_QUERY = "select * from ns1.layer1_table"; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogViewIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogViewIntegrationTest.java index 7575fcb57..c808bf3c2 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogViewIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisRestCatalogViewIntegrationTest.java @@ -20,8 +20,6 @@ import static org.apache.polaris.service.context.DefaultContextResolver.REALM_PROPERTY_KEY; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.ResourceHelpers; import io.dropwizard.testing.junit5.DropwizardAppExtension; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import jakarta.ws.rs.core.Response; @@ -34,7 +32,6 @@ import org.apache.polaris.core.admin.model.PolarisCatalog; import org.apache.polaris.core.admin.model.StorageConfigInfo; import org.apache.polaris.core.entity.CatalogEntity; -import org.apache.polaris.service.PolarisApplication; import org.apache.polaris.service.config.PolarisApplicationConfig; import org.apache.polaris.service.test.*; import org.apache.polaris.service.test.PolarisConnectionExtension.PolarisToken; @@ -57,7 +54,7 @@ }) public abstract class PolarisRestCatalogViewIntegrationTest extends ViewCatalogTests { private static final DropwizardAppExtension EXT = - PolarisApplicationUtils.createTestPolarisApplication(); + PolarisApplicationUtils.createTestPolarisApplication(); private RESTCatalog restCatalog; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisSparkIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisSparkIntegrationTest.java index c6d34a583..ff06e1c5d 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisSparkIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/catalog/PolarisSparkIntegrationTest.java @@ -23,8 +23,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.adobe.testing.s3mock.testcontainers.S3MockContainer; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.ResourceHelpers; import io.dropwizard.testing.junit5.DropwizardAppExtension; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import jakarta.ws.rs.client.Entity; @@ -41,7 +39,6 @@ import org.apache.polaris.core.admin.model.ExternalCatalog; import org.apache.polaris.core.admin.model.PolarisCatalog; import org.apache.polaris.core.admin.model.StorageConfigInfo; -import org.apache.polaris.service.PolarisApplication; import org.apache.polaris.service.config.PolarisApplicationConfig; import org.apache.polaris.service.test.PolarisApplicationUtils; import org.apache.polaris.service.test.PolarisConnectionExtension; @@ -69,7 +66,7 @@ }) public class PolarisSparkIntegrationTest { private static final DropwizardAppExtension EXT = - PolarisApplicationUtils.createTestPolarisApplication(); + PolarisApplicationUtils.createTestPolarisApplication(); public static final String CATALOG_NAME = "mycatalog"; public static final String EXTERNAL_CATALOG_NAME = "external_catalog"; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/catalog/io/FileIOIntegrationTest.java b/polaris-service/src/test/java/org/apache/polaris/service/catalog/io/FileIOIntegrationTest.java index 151afe593..7ef0240af 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/catalog/io/FileIOIntegrationTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/catalog/io/FileIOIntegrationTest.java @@ -26,7 +26,6 @@ import com.google.cloud.storage.StorageException; import com.google.common.collect.Iterators; import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.ResourceHelpers; import io.dropwizard.testing.junit5.DropwizardAppExtension; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import java.util.Collection; @@ -51,7 +50,6 @@ import org.apache.polaris.core.admin.model.FileStorageConfigInfo; import org.apache.polaris.core.admin.model.PolarisCatalog; import org.apache.polaris.core.admin.model.StorageConfigInfo; -import org.apache.polaris.service.PolarisApplication; import org.apache.polaris.service.catalog.TestUtil; import org.apache.polaris.service.config.PolarisApplicationConfig; import org.apache.polaris.service.exception.IcebergExceptionMapper; @@ -73,7 +71,8 @@ }) public class FileIOIntegrationTest { private static final DropwizardAppExtension EXT = - PolarisApplicationUtils.createTestPolarisApplication(ConfigOverride.config("io.factoryType", "test")); + PolarisApplicationUtils.createTestPolarisApplication( + ConfigOverride.config("io.factoryType", "test")); private static final String catalogBaseLocation = "file:/tmp/buckets/my-bucket/path/to/data"; private static TestFileIOFactory ioFactory; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java b/polaris-service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java index 8fd9b0a3a..dbc0b6357 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java @@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.ResourceHelpers; import io.dropwizard.testing.junit5.DropwizardAppExtension; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import io.micrometer.core.instrument.Tag; @@ -32,7 +31,6 @@ import java.time.Duration; import java.util.List; import java.util.function.Consumer; -import org.apache.polaris.service.PolarisApplication; import org.apache.polaris.service.config.PolarisApplicationConfig; import org.apache.polaris.service.test.*; import org.junit.jupiter.api.AfterEach; @@ -53,11 +51,11 @@ public class RateLimiterFilterTest { private static final long REQUESTS_PER_SECOND = 5; private static final long WINDOW_SECONDS = 10; private static final DropwizardAppExtension EXT = - PolarisApplicationUtils.createTestPolarisApplication( - ConfigOverride.config("rateLimiter.type", "mock-realm-token-bucket"), - ConfigOverride.config( - "rateLimiter.requestsPerSecond", String.valueOf(REQUESTS_PER_SECOND)), - ConfigOverride.config("rateLimiter.windowSeconds", String.valueOf(WINDOW_SECONDS))); + PolarisApplicationUtils.createTestPolarisApplication( + ConfigOverride.config("rateLimiter.type", "mock-realm-token-bucket"), + ConfigOverride.config( + "rateLimiter.requestsPerSecond", String.valueOf(REQUESTS_PER_SECOND)), + ConfigOverride.config("rateLimiter.windowSeconds", String.valueOf(WINDOW_SECONDS))); private static String userToken; private static String realm; diff --git a/polaris-service/src/test/java/org/apache/polaris/service/test/PolarisApplicationUtils.java b/polaris-service/src/test/java/org/apache/polaris/service/test/PolarisApplicationUtils.java index f4660e7af..304348700 100644 --- a/polaris-service/src/test/java/org/apache/polaris/service/test/PolarisApplicationUtils.java +++ b/polaris-service/src/test/java/org/apache/polaris/service/test/PolarisApplicationUtils.java @@ -21,28 +21,26 @@ import io.dropwizard.testing.ConfigOverride; import io.dropwizard.testing.ResourceHelpers; import io.dropwizard.testing.junit5.DropwizardAppExtension; -import org.apache.polaris.service.PolarisApplication; -import org.apache.polaris.service.config.PolarisApplicationConfig; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; - +import org.apache.polaris.service.PolarisApplication; +import org.apache.polaris.service.config.PolarisApplicationConfig; public class PolarisApplicationUtils { - public static DropwizardAppExtension createTestPolarisApplication(ConfigOverride... configOverrides) { - List appConfigOverrides = new ArrayList<>(); - // Bind to random port to support parallelism - appConfigOverrides.add(ConfigOverride.config("server.applicationConnectors[0].port", "0")); - appConfigOverrides.add(ConfigOverride.config("server.adminConnectors[0].port", "0")); - // add the other input configurations - appConfigOverrides.addAll(Arrays.asList(configOverrides)); + public static DropwizardAppExtension createTestPolarisApplication( + ConfigOverride... configOverrides) { + List appConfigOverrides = new ArrayList<>(); + // Bind to random port to support parallelism + appConfigOverrides.add(ConfigOverride.config("server.applicationConnectors[0].port", "0")); + appConfigOverrides.add(ConfigOverride.config("server.adminConnectors[0].port", "0")); + // add the other input configurations + appConfigOverrides.addAll(Arrays.asList(configOverrides)); - return new DropwizardAppExtension<>( - PolarisApplication.class, - ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), - appConfigOverrides.toArray(new ConfigOverride[0]) - ); - } -} \ No newline at end of file + return new DropwizardAppExtension<>( + PolarisApplication.class, + ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"), + appConfigOverrides.toArray(new ConfigOverride[0])); + } +}