You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by ad...@apache.org on 2026/06/17 09:45:33 UTC
(polaris) branch main updated: Remove PolarisIntegrationTestFixture (#4792)
This is an automated email from the ASF dual-hosted git repository.
adutra pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new bec4a7e794 Remove PolarisIntegrationTestFixture (#4792)
bec4a7e794 is described below
commit bec4a7e794cdc57f0a381e21cfbc8b3d175097c5
Author: Alexandre Dutra <ad...@apache.org>
AuthorDate: Wed Jun 17 11:45:28 2026 +0200
Remove PolarisIntegrationTestFixture (#4792)
This change removes `PolarisIntegrationTestFixture` and `PolarisIntegrationTestHelper`. This functionality was outdated and is now largely covered by the more robust `PolarisIntegrationTestExtension`.
This change also simplifies the two tests that were using that fixture class: `RateLimiterFilterTest` and `MetricsTestBase` (+ subclasses).
It also removes two usages of `TestRealmContextResolver` in tests.
---
.../java/org/apache/polaris/service/Profiles.java | 17 +-
.../service/auth/internal/broker/TokenUtils.java | 67 -------
.../polaris/service/metrics/MetricsTestBase.java | 56 +++---
.../service/ratelimiter/RateLimiterFilterTest.java | 88 +++++----
.../polaris/service/ratelimiter/TestUtil.java | 52 -----
.../test/PolarisIntegrationTestFixture.java | 217 ---------------------
.../service/test/PolarisIntegrationTestHelper.java | 40 ----
.../polaris/service/test/TestMetricsUtil.java | 35 ++--
8 files changed, 112 insertions(+), 460 deletions(-)
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/Profiles.java b/runtime/service/src/test/java/org/apache/polaris/service/Profiles.java
index db3476e9fa..5bda6cf615 100644
--- a/runtime/service/src/test/java/org/apache/polaris/service/Profiles.java
+++ b/runtime/service/src/test/java/org/apache/polaris/service/Profiles.java
@@ -215,14 +215,12 @@ public final class Profiles {
return Map.of(
"polaris.metrics.tags.environment",
"prod",
- "polaris.realm-context.type",
- "test",
+ "polaris.metrics.user-principal-tag.enable-in-api-metrics",
+ "false",
"polaris.metrics.realm-id-tag.enable-in-api-metrics",
"true",
"polaris.metrics.realm-id-tag.enable-in-http-metrics",
- "true",
- "polaris.metrics.user-principal-tag.enable-in-api-metrics",
- "false");
+ "true");
}
}
@@ -245,7 +243,14 @@ public final class Profiles {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
- "polaris.metrics.tags.environment", "prod", "polaris.realm-context.type", "test");
+ "polaris.metrics.tags.environment",
+ "prod",
+ "polaris.metrics.user-principal-tag.enable-in-api-metrics",
+ "false",
+ "polaris.metrics.realm-id-tag.enable-in-api-metrics",
+ "false",
+ "polaris.metrics.realm-id-tag.enable-in-http-metrics",
+ "false");
}
}
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/broker/TokenUtils.java b/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/broker/TokenUtils.java
deleted file mode 100644
index 95b2b4db93..0000000000
--- a/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/broker/TokenUtils.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.auth.internal.broker;
-
-import static org.apache.polaris.service.auth.DefaultAuthenticator.PRINCIPAL_ROLE_ALL;
-import static org.apache.polaris.service.context.TestRealmContextResolver.REALM_PROPERTY_KEY;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import jakarta.ws.rs.client.Client;
-import jakarta.ws.rs.client.Entity;
-import jakarta.ws.rs.client.Invocation;
-import jakarta.ws.rs.core.MultivaluedHashMap;
-import jakarta.ws.rs.core.Response;
-import java.net.URI;
-import java.util.Map;
-import org.apache.iceberg.rest.responses.OAuthTokenResponse;
-
-public class TokenUtils {
-
- /** Get token against specified realm */
- public static String getTokenFromSecrets(
- Client client, URI baseUrl, String clientId, String clientSecret, String realm) {
- String token;
-
- Invocation.Builder builder =
- client
- .target(String.format("%s/api/catalog/v1/oauth/tokens", baseUrl))
- .request("application/json");
- if (realm != null) {
- builder = builder.header(REALM_PROPERTY_KEY, realm);
- }
-
- try (Response response =
- builder.post(
- Entity.form(
- new MultivaluedHashMap<>(
- Map.of(
- "grant_type",
- "client_credentials",
- "scope",
- PRINCIPAL_ROLE_ALL,
- "client_id",
- clientId,
- "client_secret",
- clientSecret))))) {
- assertThat(response).returns(Response.Status.OK.getStatusCode(), Response::getStatus);
- token = response.readEntity(OAuthTokenResponse.class).token();
- }
- return token;
- }
-}
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/metrics/MetricsTestBase.java b/runtime/service/src/test/java/org/apache/polaris/service/metrics/MetricsTestBase.java
index 5c13d89da7..a04fc7d04c 100644
--- a/runtime/service/src/test/java/org/apache/polaris/service/metrics/MetricsTestBase.java
+++ b/runtime/service/src/test/java/org/apache/polaris/service/metrics/MetricsTestBase.java
@@ -18,7 +18,6 @@
*/
package org.apache.polaris.service.metrics;
-import static org.apache.polaris.service.context.TestRealmContextResolver.REALM_PROPERTY_KEY;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.type;
@@ -28,42 +27,59 @@ import jakarta.ws.rs.core.Response;
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.polaris.service.test.PolarisIntegrationTestFixture;
-import org.apache.polaris.service.test.PolarisIntegrationTestHelper;
+import org.apache.polaris.service.it.env.ClientPrincipal;
+import org.apache.polaris.service.it.env.PolarisApiEndpoints;
+import org.apache.polaris.service.it.env.PolarisClient;
+import org.apache.polaris.service.it.ext.PolarisIntegrationTestExtension;
+import org.apache.polaris.service.ratelimiter.MockRateLimiter;
import org.apache.polaris.service.test.TestEnvironment;
import org.apache.polaris.service.test.TestEnvironmentExtension;
import org.apache.polaris.service.test.TestMetricsUtil;
import org.awaitility.Awaitility;
import org.hawkular.agent.prometheus.types.MetricFamily;
import org.hawkular.agent.prometheus.types.Summary;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(TestEnvironmentExtension.class)
+@ExtendWith(PolarisIntegrationTestExtension.class)
public abstract class MetricsTestBase {
private static final int ERROR_CODE = Response.Status.NOT_FOUND.getStatusCode();
- private static final String ENDPOINT = "api/management/v1/principals";
private static final String API_METRIC_NAME = "polaris_principals_getPrincipal_seconds";
private static final String HTTP_METRIC_NAME = "http_server_requests_seconds";
- @Inject PolarisIntegrationTestHelper helper;
@Inject MeterRegistry registry;
@Inject MetricsConfiguration metricsConfiguration;
private TestEnvironment testEnv;
- private PolarisIntegrationTestFixture fixture;
+ private PolarisApiEndpoints endpoints;
+ private PolarisClient client;
+ private ClientPrincipal principal;
+ private String adminToken;
@BeforeAll
- public void createFixture(TestEnvironment testEnv, TestInfo testInfo) {
+ public void setUp(
+ TestEnvironment testEnv, PolarisApiEndpoints endpoints, ClientPrincipal principal) {
+ MockRateLimiter.allowProceed = true;
this.testEnv = testEnv;
- fixture = helper.createFixture(testEnv, testInfo);
+ this.endpoints = endpoints;
+ this.principal = principal;
+ client = PolarisClient.polarisClient(this.endpoints);
+ adminToken = client.obtainToken(principal.credentials());
+ }
+
+ @AfterAll
+ public void tearDown() throws Exception {
+ if (client != null) {
+ client.close();
+ }
}
@BeforeEach
@@ -77,7 +93,7 @@ public abstract class MetricsTestBase {
.atMost(Duration.ofMinutes(2))
.untilAsserted(
() -> {
- value.set(TestMetricsUtil.fetchMetrics(fixture.client, testEnv.baseManagementUri()));
+ value.set(TestMetricsUtil.fetchMetrics(testEnv.baseManagementUri()));
assertThat(value.get()).containsKey(API_METRIC_NAME);
assertThat(value.get()).containsKey(HTTP_METRIC_NAME);
});
@@ -99,7 +115,7 @@ public abstract class MetricsTestBase {
Map.entry(
"realm_id",
metricsConfiguration.realmIdTag().enableInApiMetrics()
- ? fixture.realm
+ ? endpoints.realmId()
: ""),
Map.entry(
"principal",
@@ -128,7 +144,7 @@ public abstract class MetricsTestBase {
Map.entry("status", "200"),
Map.entry("uri", "/api/management/v1/principals/{principalName}"));
if (metricsConfiguration.realmIdTag().enableInHttpMetrics()) {
- assertThat(metric.getLabels()).containsEntry("realm_id", fixture.realm);
+ assertThat(metric.getLabels()).containsEntry("realm_id", endpoints.realmId());
} else {
assertThat(metric.getLabels()).doesNotContainKey("realm_id");
}
@@ -154,7 +170,7 @@ public abstract class MetricsTestBase {
Map.entry(
"realm_id",
metricsConfiguration.realmIdTag().enableInApiMetrics()
- ? fixture.realm
+ ? endpoints.realmId()
: ""),
Map.entry(
"principal",
@@ -182,7 +198,7 @@ public abstract class MetricsTestBase {
Map.entry("status", "404"),
Map.entry("uri", "/api/management/v1/principals/{principalName}"));
if (metricsConfiguration.realmIdTag().enableInHttpMetrics()) {
- assertThat(metric.getLabels()).containsEntry("realm_id", fixture.realm);
+ assertThat(metric.getLabels()).containsEntry("realm_id", endpoints.realmId());
} else {
assertThat(metric.getLabels()).doesNotContainKey("realm_id");
}
@@ -195,12 +211,9 @@ public abstract class MetricsTestBase {
private int sendRequest(String principalName) {
try (Response response =
- fixture
- .client
- .target(String.format("%s/%s/%s", testEnv.baseUri(), ENDPOINT, principalName))
- .request("application/json")
- .header("Authorization", "Bearer " + fixture.adminToken)
- .header(REALM_PROPERTY_KEY, fixture.realm)
+ client
+ .managementApi(adminToken)
+ .request("v1/principals/{name}", Map.of("name", principalName))
.get()) {
return response.getStatus();
}
@@ -208,8 +221,7 @@ public abstract class MetricsTestBase {
private void sendSuccessfulRequest() {
Assertions.assertEquals(
- Response.Status.OK.getStatusCode(),
- sendRequest(fixture.snowmanCredentials.identifier().principalName()));
+ Response.Status.OK.getStatusCode(), sendRequest(principal.principalName()));
}
private void sendFailingRequest() {
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java b/runtime/service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java
index 3f01020317..9322a9159b 100644
--- a/runtime/service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java
+++ b/runtime/service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java
@@ -18,7 +18,6 @@
*/
package org.apache.polaris.service.ratelimiter;
-import static org.apache.polaris.service.context.TestRealmContextResolver.REALM_PROPERTY_KEY;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.type;
@@ -29,6 +28,8 @@ import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import io.smallrye.common.annotation.Identifier;
import jakarta.inject.Inject;
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
@@ -40,11 +41,12 @@ import org.apache.iceberg.rest.responses.ErrorResponseParser;
import org.apache.polaris.service.events.EventAttributes;
import org.apache.polaris.service.events.PolarisEvent;
import org.apache.polaris.service.events.PolarisEventType;
-import org.apache.polaris.service.events.listeners.PolarisEventListener;
import org.apache.polaris.service.events.listeners.TestPolarisEventListener;
+import org.apache.polaris.service.it.env.ClientCredentials;
+import org.apache.polaris.service.it.env.PolarisApiEndpoints;
+import org.apache.polaris.service.it.env.PolarisClient;
+import org.apache.polaris.service.it.ext.PolarisIntegrationTestExtension;
import org.apache.polaris.service.ratelimiter.RateLimiterFilterTest.Profile;
-import org.apache.polaris.service.test.PolarisIntegrationTestFixture;
-import org.apache.polaris.service.test.PolarisIntegrationTestHelper;
import org.apache.polaris.service.test.TestEnvironment;
import org.apache.polaris.service.test.TestEnvironmentExtension;
import org.apache.polaris.service.test.TestMetricsUtil;
@@ -54,7 +56,6 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -64,6 +65,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
@TestInstance(Lifecycle.PER_CLASS)
@TestProfile(Profile.class)
@ExtendWith(TestEnvironmentExtension.class)
+@ExtendWith(PolarisIntegrationTestExtension.class)
public class RateLimiterFilterTest {
public static class Profile implements QuarkusTestProfile {
@@ -79,9 +81,9 @@ public class RateLimiterFilterTest {
.put("polaris.rate-limiter.filter.type", "mock")
.put("polaris.rate-limiter.token-bucket.type", "default")
.put("polaris.metrics.tags.environment", "prod")
+ .put("polaris.realm-context.realms", "POLARIS,POLARIS2")
.put("polaris.metrics.realm-id-tag.enable-in-api-metrics", "true")
.put("polaris.metrics.realm-id-tag.enable-in-http-metrics", "true")
- .put("polaris.realm-context.type", "test")
.put("polaris.authentication.token-broker.type", "symmetric-key")
.put("polaris.authentication.token-broker.symmetric-key.secret", "secret")
.put("polaris.event-listener.types", "test")
@@ -89,29 +91,31 @@ public class RateLimiterFilterTest {
}
}
- @Inject PolarisIntegrationTestHelper helper;
@Inject MeterRegistry meterRegistry;
@Inject
@Identifier("test")
- PolarisEventListener polarisEventListener;
-
- private TestPolarisEventListener testPolarisEventListener;
+ TestPolarisEventListener polarisEventListener;
private TestEnvironment testEnv;
- private PolarisIntegrationTestFixture fixture;
+ private PolarisApiEndpoints endpoints;
+ private PolarisClient client;
+ private String adminToken;
@BeforeAll
- public void createFixture(TestEnvironment testEnv, TestInfo testInfo) {
+ public void setUp(
+ TestEnvironment testEnv, PolarisApiEndpoints endpoints, ClientCredentials credentials) {
MockRateLimiter.allowProceed = true;
this.testEnv = testEnv;
- fixture = helper.createFixture(testEnv, testInfo);
+ this.endpoints = endpoints;
+ client = PolarisClient.polarisClient(endpoints);
+ adminToken = client.obtainToken(credentials);
}
@AfterAll
- public void destroyFixture() {
- if (fixture != null) {
- fixture.destroy();
+ public void tearDown() throws Exception {
+ if (client != null) {
+ client.close();
}
}
@@ -119,15 +123,12 @@ public class RateLimiterFilterTest {
public void resetMeterRegistry() {
MockRateLimiter.allowProceed = true;
meterRegistry.clear();
-
- testPolarisEventListener = (TestPolarisEventListener) polarisEventListener;
- testPolarisEventListener.clear();
+ polarisEventListener.clear();
}
@Test
public void testRateLimiter() {
- Consumer<Status> requestAsserter =
- TestUtil.constructRequestAsserter(testEnv, fixture, fixture.realm);
+ Consumer<Status> requestAsserter = constructRequestAsserter(testEnv, adminToken, "POLARIS");
for (int i = 0; i < 3; i++) {
MockRateLimiter.allowProceed = true;
@@ -138,22 +139,14 @@ public class RateLimiterFilterTest {
// Ensure that a different realm identifier gets a separate limit
MockRateLimiter.allowProceed = true;
- Consumer<Status> requestAsserter2 =
- TestUtil.constructRequestAsserter(testEnv, fixture, fixture.realm + "2");
+ Consumer<Status> requestAsserter2 = constructRequestAsserter(testEnv, adminToken, "POLARIS2");
requestAsserter2.accept(Status.OK);
}
@Test
public void testRateLimitedResponseHasIcebergErrorBody() {
MockRateLimiter.allowProceed = false;
- try (Response response =
- fixture
- .client
- .target(String.format("%s/api/management/v1/principal-roles", testEnv.baseUri()))
- .request("application/json")
- .header("Authorization", "Bearer " + fixture.adminToken)
- .header(REALM_PROPERTY_KEY, fixture.realm)
- .get()) {
+ try (Response response = client.managementApi(adminToken).request("v1/principal-roles").get()) {
assertThat(response.getStatus()).isEqualTo(Status.TOO_MANY_REQUESTS.getStatusCode());
assertThat(response.getMediaType()).isEqualTo(MediaType.APPLICATION_JSON_TYPE);
@@ -168,7 +161,7 @@ public class RateLimiterFilterTest {
@Test
public void testMetricsAreEmittedWhenRateLimiting() {
Consumer<Status> requestAsserter =
- TestUtil.constructRequestAsserter(testEnv, fixture, fixture.realm);
+ constructRequestAsserter(testEnv, adminToken, endpoints.realmId());
for (int i = 0; i < 3; i++) {
MockRateLimiter.allowProceed = true;
@@ -177,16 +170,14 @@ public class RateLimiterFilterTest {
requestAsserter.accept(Status.TOO_MANY_REQUESTS);
}
- PolarisEvent event =
- testPolarisEventListener.getLatest(PolarisEventType.BEFORE_LIMIT_REQUEST_RATE);
+ PolarisEvent event = polarisEventListener.getLatest(PolarisEventType.BEFORE_LIMIT_REQUEST_RATE);
assertThat(event.attributes().getRequired(EventAttributes.HTTP_METHOD)).isEqualTo("GET");
// Examples of expected metrics:
// http_server_requests_seconds_count{application="Polaris",environment="prod",method="GET",outcome="CLIENT_ERROR",realm_id="org_apache_polaris_service_ratelimiter_RateLimiterFilterTest",status="429",uri="/api/management/v1/principal-roles"} 1.0
// polaris_principal_roles_listPrincipalRoles_seconds_count{application="Polaris",class="org.apache.polaris.service.admin.api.PolarisPrincipalRolesApi",environment="prod",exception="none",method="listPrincipalRoles"} 50.0
- Map<String, MetricFamily> metrics =
- TestMetricsUtil.fetchMetrics(fixture.client, testEnv.baseManagementUri());
+ Map<String, MetricFamily> metrics = TestMetricsUtil.fetchMetrics(testEnv.baseManagementUri());
assertThat(metrics)
.isNotEmpty()
@@ -200,7 +191,7 @@ public class RateLimiterFilterTest {
.contains(
Map.entry("application", "Polaris"),
Map.entry("environment", "prod"),
- Map.entry("realm_id", fixture.realm),
+ Map.entry("realm_id", endpoints.realmId()),
Map.entry("method", "GET"),
Map.entry("outcome", "CLIENT_ERROR"),
Map.entry("status", String.valueOf(Status.TOO_MANY_REQUESTS.getStatusCode())),
@@ -218,7 +209,7 @@ public class RateLimiterFilterTest {
.contains(
Map.entry("application", "Polaris"),
Map.entry("environment", "prod"),
- Map.entry("realm_id", fixture.realm),
+ Map.entry("realm_id", endpoints.realmId()),
Map.entry(
"class", "org.apache.polaris.service.admin.api.PolarisPrincipalRolesApi"),
Map.entry("exception", "none"),
@@ -229,4 +220,25 @@ public class RateLimiterFilterTest {
.isEqualTo(3L);
});
}
+
+ /**
+ * Constructs a function that makes a request to list all principal roles and asserts the status
+ * of the response. This is a relatively simple type of request that can be used for validating
+ * whether the rate limiter intervenes.
+ */
+ private static Consumer<Status> constructRequestAsserter(
+ TestEnvironment testEnv, String adminToken, String realm) {
+ return (Status status) -> {
+ try (Client client = ClientBuilder.newBuilder().build();
+ Response response =
+ client
+ .target(String.format("%s/api/management/v1/principal-roles", testEnv.baseUri()))
+ .request("application/json")
+ .header("Authorization", "Bearer " + adminToken)
+ .header("Polaris-Realm", realm)
+ .get()) {
+ assertThat(response).returns(status.getStatusCode(), Response::getStatus);
+ }
+ };
+ }
}
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/ratelimiter/TestUtil.java b/runtime/service/src/test/java/org/apache/polaris/service/ratelimiter/TestUtil.java
deleted file mode 100644
index 0d2e8ef06f..0000000000
--- a/runtime/service/src/test/java/org/apache/polaris/service/ratelimiter/TestUtil.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.ratelimiter;
-
-import static org.apache.polaris.service.context.TestRealmContextResolver.REALM_PROPERTY_KEY;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import jakarta.ws.rs.core.Response;
-import jakarta.ws.rs.core.Response.Status;
-import java.util.function.Consumer;
-import org.apache.polaris.service.test.PolarisIntegrationTestFixture;
-import org.apache.polaris.service.test.TestEnvironment;
-
-/** Common test utils for testing rate limiting */
-public class TestUtil {
- /**
- * Constructs a function that makes a request to list all principal roles and asserts the status
- * of the response. This is a relatively simple type of request that can be used for validating
- * whether the rate limiter intervenes.
- */
- public static Consumer<Status> constructRequestAsserter(
- TestEnvironment testEnv, PolarisIntegrationTestFixture fixture, String realm) {
- return (Response.Status status) -> {
- try (Response response =
- fixture
- .client
- .target(String.format("%s/api/management/v1/principal-roles", testEnv.baseUri()))
- .request("application/json")
- .header("Authorization", "Bearer " + fixture.adminToken)
- .header(REALM_PROPERTY_KEY, realm)
- .get()) {
- assertThat(response).returns(status.getStatusCode(), Response::getStatus);
- }
- };
- }
-}
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestFixture.java b/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestFixture.java
deleted file mode 100644
index 74240efcb1..0000000000
--- a/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestFixture.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * 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 static org.apache.polaris.service.context.TestRealmContextResolver.REALM_PROPERTY_KEY;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import jakarta.ws.rs.client.Client;
-import jakarta.ws.rs.client.ClientBuilder;
-import jakarta.ws.rs.client.Entity;
-import jakarta.ws.rs.core.MediaType;
-import jakarta.ws.rs.core.Response;
-import java.net.URI;
-import java.util.List;
-import java.util.Map;
-import org.apache.polaris.core.PolarisCallContext;
-import org.apache.polaris.core.admin.model.GrantPrincipalRoleRequest;
-import org.apache.polaris.core.admin.model.Principal;
-import org.apache.polaris.core.admin.model.PrincipalRole;
-import org.apache.polaris.core.admin.model.PrincipalWithCredentials;
-import org.apache.polaris.core.context.RealmContext;
-import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
-import org.apache.polaris.core.entity.PrincipalEntity;
-import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
-import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet;
-import org.apache.polaris.service.auth.internal.broker.TokenUtils;
-import org.apache.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory;
-import org.junit.jupiter.api.TestInfo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PolarisIntegrationTestFixture {
-
- public record SnowmanIdentifier(String principalName, String principalRoleName) {}
-
- public record SnowmanCredentials(
- String clientId, String clientSecret, SnowmanIdentifier identifier) {}
-
- private static final Logger LOGGER = LoggerFactory.getLogger(PolarisIntegrationTestFixture.class);
-
- private final PolarisIntegrationTestHelper helper;
-
- public final String realm;
- public final PolarisPrincipalSecrets adminSecrets;
- public final SnowmanCredentials snowmanCredentials;
- public final String adminToken;
- public final String userToken;
- public final Client client;
-
- private final URI baseUri;
-
- public PolarisIntegrationTestFixture(
- PolarisIntegrationTestHelper helper, TestEnvironment testEnv, TestInfo testInfo) {
- this.helper = helper;
- this.client = ClientBuilder.newClient();
- this.baseUri = testEnv.baseUri();
- // Generate unique realm using test name for each test since the tests can run in parallel
- realm = testInfo.getTestClass().orElseThrow().getName().replace('.', '_');
- adminSecrets = fetchAdminSecrets();
- adminToken =
- TokenUtils.getTokenFromSecrets(
- client,
- baseUri,
- adminSecrets.getPrincipalClientId(),
- adminSecrets.getMainSecret(),
- realm);
- snowmanCredentials = createSnowmanCredentials(testEnv);
- userToken =
- TokenUtils.getTokenFromSecrets(
- client,
- baseUri,
- snowmanCredentials.clientId(),
- snowmanCredentials.clientSecret(),
- realm);
- }
-
- private PolarisPrincipalSecrets fetchAdminSecrets() {
- if (!(helper.metaStoreManagerFactory instanceof InMemoryPolarisMetaStoreManagerFactory)) {
- helper.metaStoreManagerFactory.bootstrapRealms(
- List.of(realm), RootCredentialsSet.fromEnvironment());
- }
-
- RealmContext realmContext =
- helper
- .realmContextResolver
- .resolveRealmContext(baseUri.toString(), "GET", "/", Map.of(REALM_PROPERTY_KEY, realm))
- .toCompletableFuture()
- .join();
-
- PolarisCallContext polarisContext =
- new PolarisCallContext(
- realmContext,
- helper.metaStoreManagerFactory.getOrCreateSession(realmContext),
- helper.metaStoreManagerFactory.getOrCreateMetricsPersistence(realmContext),
- helper.configurationSource);
- PolarisMetaStoreManager metaStoreManager =
- helper.metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext);
- PrincipalEntity principal = metaStoreManager.findRootPrincipal(polarisContext).orElseThrow();
- return metaStoreManager
- .loadPrincipalSecrets(polarisContext, principal.getClientId())
- .getPrincipalSecrets();
- }
-
- private SnowmanCredentials createSnowmanCredentials(TestEnvironment testEnv) {
-
- SnowmanIdentifier snowmanIdentifier = getSnowmanIdentifier(testEnv);
- PrincipalRole principalRole = new PrincipalRole(snowmanIdentifier.principalRoleName());
-
- try (Response createPrResponse =
- client
- .target(String.format("%s/api/management/v1/principal-roles", baseUri))
- .request("application/json")
- .header("Authorization", "Bearer " + adminToken)
- .header(REALM_PROPERTY_KEY, realm)
- .post(Entity.json(principalRole))) {
- assertThat(createPrResponse)
- .returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);
- }
-
- Principal principal = new Principal(snowmanIdentifier.principalName());
- SnowmanCredentials snowmanCredentials;
-
- try (Response createPResponse =
- client
- .target(String.format("%s/api/management/v1/principals", baseUri))
- .request("application/json")
- .header("Authorization", "Bearer " + adminToken) // how is token getting used?
- .header(REALM_PROPERTY_KEY, realm)
- .post(Entity.json(principal))) {
- assertThat(createPResponse)
- .returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);
-
- PrincipalWithCredentials snowmanWithCredentials =
- createPResponse.readEntity(PrincipalWithCredentials.class);
- try (Response rotateResp =
- client
- .target(
- String.format(
- "%s/api/management/v1/principals/%s/rotate", baseUri, principal.getName()))
- .request(MediaType.APPLICATION_JSON)
- .header(
- "Authorization",
- "Bearer "
- + TokenUtils.getTokenFromSecrets(
- client,
- baseUri,
- snowmanWithCredentials.getCredentials().getClientId(),
- snowmanWithCredentials.getCredentials().getClientSecret(),
- realm))
- .header(REALM_PROPERTY_KEY, realm)
- .post(Entity.json(snowmanWithCredentials))) {
-
- assertThat(rotateResp).returns(Response.Status.OK.getStatusCode(), Response::getStatus);
-
- // Use the rotated credentials.
- snowmanWithCredentials = rotateResp.readEntity(PrincipalWithCredentials.class);
- }
- snowmanCredentials =
- new SnowmanCredentials(
- snowmanWithCredentials.getCredentials().getClientId(),
- snowmanWithCredentials.getCredentials().getClientSecret(),
- snowmanIdentifier);
- }
- try (Response assignPrResponse =
- client
- .target(
- String.format(
- "%s/api/management/v1/principals/%s/principal-roles",
- baseUri, principal.getName()))
- .request("application/json")
- .header("Authorization", "Bearer " + adminToken) // how is token getting used?
- .header(REALM_PROPERTY_KEY, realm)
- .put(Entity.json(new GrantPrincipalRoleRequest(principalRole)))) {
- assertThat(assignPrResponse)
- .returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);
- }
- return snowmanCredentials;
- }
-
- public void destroy() {
- try {
- if (realm != null) {
- helper.metaStoreManagerFactory.purgeRealms(List.of(realm));
- }
- } catch (Exception e) {
- LOGGER.error("Failed to purge realm", e);
- } finally {
- if (client != null) {
- try {
- client.close();
- } catch (Exception e) {
- LOGGER.error("Failed to close client", e);
- }
- }
- }
- }
-
- private static SnowmanIdentifier getSnowmanIdentifier(TestEnvironment testEnv) {
- return new SnowmanIdentifier("snowman" + testEnv.testId(), "catalog-admin" + testEnv.testId());
- }
-}
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestHelper.java b/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestHelper.java
deleted file mode 100644
index 4f97c191e8..0000000000
--- a/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestHelper.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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 jakarta.inject.Inject;
-import jakarta.inject.Singleton;
-import org.apache.polaris.core.PolarisDiagnostics;
-import org.apache.polaris.core.config.RealmConfigurationSource;
-import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
-import org.apache.polaris.service.context.RealmContextResolver;
-import org.junit.jupiter.api.TestInfo;
-
-@Singleton
-public class PolarisIntegrationTestHelper {
-
- @Inject MetaStoreManagerFactory metaStoreManagerFactory;
- @Inject RealmContextResolver realmContextResolver;
- @Inject PolarisDiagnostics diagServices;
- @Inject RealmConfigurationSource configurationSource;
-
- public PolarisIntegrationTestFixture createFixture(TestEnvironment testEnv, TestInfo testInfo) {
- return new PolarisIntegrationTestFixture(this, testEnv, testInfo);
- }
-}
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/test/TestMetricsUtil.java b/runtime/service/src/test/java/org/apache/polaris/service/test/TestMetricsUtil.java
index 7a74570bf9..088cdd4f7a 100644
--- a/runtime/service/src/test/java/org/apache/polaris/service/test/TestMetricsUtil.java
+++ b/runtime/service/src/test/java/org/apache/polaris/service/test/TestMetricsUtil.java
@@ -21,8 +21,8 @@ package org.apache.polaris.service.test;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.core.Response;
-import jakarta.ws.rs.core.Response.Status;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URI;
@@ -36,23 +36,22 @@ import org.hawkular.agent.prometheus.walkers.CollectorPrometheusMetricsWalker;
/** Utils for working with metrics in tests */
public class TestMetricsUtil {
- public static Map<String, MetricFamily> fetchMetrics(Client client, URI baseManagementUri) {
- Response response = client.target(baseManagementUri.resolve("q/metrics")).request().get();
- if (response.getStatus() == Status.MOVED_PERMANENTLY.getStatusCode()) {
- response = client.target(response.getLocation()).request().get();
+ public static Map<String, MetricFamily> fetchMetrics(URI baseManagementUri) {
+ try (Client client = ClientBuilder.newBuilder().build();
+ Response response = client.target(baseManagementUri.resolve("q/metrics")).request().get()) {
+ assertThat(response).returns(Response.Status.OK.getStatusCode(), Response::getStatus);
+ String body = response.readEntity(String.class);
+ InputStream inputStream = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
+ CollectorPrometheusMetricsWalker walker = new CollectorPrometheusMetricsWalker();
+ new TextPrometheusMetricsProcessor(inputStream, walker).walk();
+ return walker.getAllMetricFamilies().stream()
+ .collect(
+ Collectors.toMap(
+ MetricFamily::getName,
+ metricFamily -> metricFamily,
+ (mf1, mf2) -> {
+ throw new IllegalStateException("Duplicate metric family: " + mf1.getName());
+ }));
}
- assertThat(response).returns(Response.Status.OK.getStatusCode(), Response::getStatus);
- String body = response.readEntity(String.class);
- InputStream inputStream = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
- CollectorPrometheusMetricsWalker walker = new CollectorPrometheusMetricsWalker();
- new TextPrometheusMetricsProcessor(inputStream, walker).walk();
- return walker.getAllMetricFamilies().stream()
- .collect(
- Collectors.toMap(
- MetricFamily::getName,
- metricFamily -> metricFamily,
- (mf1, mf2) -> {
- throw new IllegalStateException("Duplicate metric family: " + mf1.getName());
- }));
}
}