Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-yzou committed Dec 2, 2024
1 parent 12ddaf5 commit 5b91c75
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +36,8 @@ public class PolarisApplicationConfigurationTest {

@Nested
class DefaultMetastore {
private final DropwizardAppExtension<PolarisApplicationConfig> app = PolarisApplicationUtils.createTestPolarisApplication();
private final DropwizardAppExtension<PolarisApplicationConfig> app =
PolarisApplicationUtils.createTestPolarisApplication();

@Test
void testMetastoreType() {
Expand All @@ -49,11 +49,10 @@ void testMetastoreType() {
@Nested
class EclipseLinkMetastore {
private final DropwizardAppExtension<PolarisApplicationConfig> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,7 +104,8 @@ public class PolarisApplicationIntegrationTest {
LoggerFactory.getLogger(PolarisApplicationIntegrationTest.class);

public static final String PRINCIPAL_ROLE_NAME = "admin";
private static final DropwizardAppExtension<PolarisApplicationConfig> EXT = PolarisApplicationUtils.createTestPolarisApplication();
private static final DropwizardAppExtension<PolarisApplicationConfig> EXT =
PolarisApplicationUtils.createTestPolarisApplication();

private static String userToken;
private static SnowmanCredentialsExtension.SnowmanCredentials snowmanCredentials;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,7 +50,7 @@
})
public class TimedApplicationEventListenerTest {
private static final DropwizardAppExtension<PolarisApplicationConfig> 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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -60,16 +58,16 @@
})
public class PolarisOverlappingTableTest {
private static final DropwizardAppExtension<PolarisApplicationConfig> 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<PolarisApplicationConfig> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
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;
Expand Down Expand Up @@ -90,7 +89,6 @@
import org.apache.polaris.core.admin.model.UpdatePrincipalRequest;
import org.apache.polaris.core.admin.model.UpdatePrincipalRoleRequest;
import org.apache.polaris.core.entity.PolarisEntityConstants;
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;
Expand Down Expand Up @@ -123,12 +121,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<PolarisApplicationConfig> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.*;
Expand Down Expand Up @@ -114,7 +111,7 @@ public class PolarisRestCatalogIntegrationTest extends CatalogTests<RESTCatalog>
Optional.ofNullable(System.getenv("INTEGRATION_TEST_S3_PATH"))
.orElse("file:///tmp/buckets/my-bucket");
private static final DropwizardAppExtension<PolarisApplicationConfig> EXT =
PolarisApplicationUtils.createTestPolarisApplication();
PolarisApplicationUtils.createTestPolarisApplication();

protected static final String VIEW_QUERY = "select * from ns1.layer1_table";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -57,7 +54,7 @@
})
public abstract class PolarisRestCatalogViewIntegrationTest extends ViewCatalogTests<RESTCatalog> {
private static final DropwizardAppExtension<PolarisApplicationConfig> EXT =
PolarisApplicationUtils.createTestPolarisApplication();
PolarisApplicationUtils.createTestPolarisApplication();

private RESTCatalog restCatalog;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -69,7 +66,7 @@
})
public class PolarisSparkIntegrationTest {
private static final DropwizardAppExtension<PolarisApplicationConfig> EXT =
PolarisApplicationUtils.createTestPolarisApplication();
PolarisApplicationUtils.createTestPolarisApplication();

public static final String CATALOG_NAME = "mycatalog";
public static final String EXTERNAL_CATALOG_NAME = "external_catalog";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -73,7 +71,8 @@
})
public class FileIOIntegrationTest {
private static final DropwizardAppExtension<PolarisApplicationConfig> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
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;
import jakarta.ws.rs.core.Response;
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;
Expand All @@ -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<PolarisApplicationConfig> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PolarisApplicationConfig> createTestPolarisApplication(ConfigOverride... configOverrides) {
List<ConfigOverride> 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<PolarisApplicationConfig> createTestPolarisApplication(
ConfigOverride... configOverrides) {
List<ConfigOverride> 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])
);
}
}
return new DropwizardAppExtension<>(
PolarisApplication.class,
ResourceHelpers.resourceFilePath("polaris-server-integrationtest.yml"),
appConfigOverrides.toArray(new ConfigOverride[0]));
}
}

0 comments on commit 5b91c75

Please sign in to comment.