This is an automated email from the ASF dual-hosted git repository. snazy 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 f34adcaf2 Add TestServices.newCallContext (#2249) f34adcaf2 is described below commit f34adcaf2368c057a003a7bcd299fa6f0dcf4100 Author: Christopher Lambert <xn...@gmx.de> AuthorDate: Wed Aug 6 12:11:32 2025 +0200 Add TestServices.newCallContext (#2249) also add local `newCallContext` helper in some test classes --- .../service/admin/ManagementServiceTest.java | 13 ++------- .../service/catalog/io/FileIOFactoryTest.java | 10 +------ .../task/BatchFileCleanupTaskHandlerTest.java | 27 ++++++++---------- .../task/ManifestFileCleanupTaskHandlerTest.java | 33 ++++++++-------------- .../polaris/service/task/TaskExecutorImplTest.java | 5 +--- .../org/apache/polaris/service/TestServices.java | 6 ++++ 6 files changed, 33 insertions(+), 61 deletions(-) diff --git a/runtime/service/src/test/java/org/apache/polaris/service/admin/ManagementServiceTest.java b/runtime/service/src/test/java/org/apache/polaris/service/admin/ManagementServiceTest.java index ab8a58090..507a74d28 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/admin/ManagementServiceTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/admin/ManagementServiceTest.java @@ -170,15 +170,6 @@ public class ManagementServiceTest { return metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); } - private PolarisCallContext setupCallContext() { - MetaStoreManagerFactory metaStoreManagerFactory = services.metaStoreManagerFactory(); - RealmContext realmContext = services.realmContext(); - return new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - services.polarisDiagnostics()); - } - private PolarisAdminService setupPolarisAdminService( PolarisMetaStoreManager metaStoreManager, PolarisCallContext callContext) { return new PolarisAdminService( @@ -252,7 +243,7 @@ public class ManagementServiceTest { @Test public void testCannotAssignFederatedEntities() { PolarisMetaStoreManager metaStoreManager = setupMetaStoreManager(); - PolarisCallContext callContext = setupCallContext(); + PolarisCallContext callContext = services.newCallContext(); PolarisAdminService polarisAdminService = setupPolarisAdminService(metaStoreManager, callContext); @@ -272,7 +263,7 @@ public class ManagementServiceTest { @Test public void testCatalogNotReturnedWhenDeletedAfterListBeforeGet() { PolarisMetaStoreManager metaStoreManager = Mockito.spy(setupMetaStoreManager()); - PolarisCallContext callContext = setupCallContext(); + PolarisCallContext callContext = services.newCallContext(); PolarisAdminService polarisAdminService = setupPolarisAdminService(metaStoreManager, callContext); diff --git a/runtime/service/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java b/runtime/service/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java index 96dc25600..fd6e79f12 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java @@ -25,7 +25,6 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; import jakarta.annotation.Nonnull; import java.lang.reflect.Method; -import java.time.Clock; import java.util.List; import java.util.Map; import org.apache.iceberg.Schema; @@ -35,7 +34,6 @@ import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.inmemory.InMemoryFileIO; import org.apache.iceberg.io.FileIO; import org.apache.iceberg.types.Types; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.admin.model.AwsStorageConfigInfo; import org.apache.polaris.core.admin.model.Catalog; import org.apache.polaris.core.admin.model.CatalogProperties; @@ -136,13 +134,7 @@ public class FileIOFactoryTest { .fileIOFactorySupplier(fileIOFactorySupplier) .build(); - callContext = - new PolarisCallContext( - realmContext, - testServices.metaStoreManagerFactory().getOrCreateSession(realmContext), - testServices.polarisDiagnostics(), - testServices.configurationStore(), - Clock.systemUTC()); + callContext = testServices.newCallContext(); } @AfterEach diff --git a/runtime/service/src/test/java/org/apache/polaris/service/task/BatchFileCleanupTaskHandlerTest.java b/runtime/service/src/test/java/org/apache/polaris/service/task/BatchFileCleanupTaskHandlerTest.java index 1fc767eff..2ab24c396 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/task/BatchFileCleanupTaskHandlerTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/task/BatchFileCleanupTaskHandlerTest.java @@ -43,16 +43,18 @@ import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.inmemory.InMemoryFileIO; import org.apache.iceberg.io.FileIO; import org.apache.polaris.core.PolarisCallContext; -import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; +import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.TaskEntity; +import org.apache.polaris.core.persistence.BasePersistence; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.service.TestFileIOFactory; import org.junit.jupiter.api.Test; @QuarkusTest public class BatchFileCleanupTaskHandlerTest { + @Inject PolarisDiagnostics diagnostics; @Inject MetaStoreManagerFactory metaStoreManagerFactory; private final RealmContext realmContext = () -> "realmName"; @@ -60,13 +62,14 @@ public class BatchFileCleanupTaskHandlerTest { return new TaskFileIOSupplier(new TestFileIOFactory(fileIO)); } + private PolarisCallContext newCallContext() { + BasePersistence metaStore = metaStoreManagerFactory.getOrCreateSession(realmContext); + return new PolarisCallContext(realmContext, metaStore, diagnostics); + } + @Test public void testMetadataFileCleanup() throws IOException { - PolarisCallContext polarisCallContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - new PolarisDefaultDiagServiceImpl()); + PolarisCallContext polarisCallContext = newCallContext(); FileIO fileIO = new InMemoryFileIO() { @Override @@ -175,11 +178,7 @@ public class BatchFileCleanupTaskHandlerTest { @Test public void testMetadataFileCleanupIfFileNotExist() throws IOException { - PolarisCallContext polarisCallContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - new PolarisDefaultDiagServiceImpl()); + PolarisCallContext polarisCallContext = newCallContext(); FileIO fileIO = new InMemoryFileIO(); TableIdentifier tableIdentifier = TableIdentifier.of(Namespace.of("db1", "schema1"), "table1"); BatchFileCleanupTaskHandler handler = @@ -219,11 +218,7 @@ public class BatchFileCleanupTaskHandlerTest { @Test public void testCleanupWithRetries() throws IOException { - PolarisCallContext polarisCallContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - new PolarisDefaultDiagServiceImpl()); + PolarisCallContext polarisCallContext = newCallContext(); Map<String, AtomicInteger> retryCounter = new HashMap<>(); FileIO fileIO = new InMemoryFileIO() { diff --git a/runtime/service/src/test/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandlerTest.java b/runtime/service/src/test/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandlerTest.java index 3fb1eb70f..53afeecfa 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandlerTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandlerTest.java @@ -41,16 +41,18 @@ import org.apache.iceberg.io.FileIO; import org.apache.iceberg.io.OutputFile; import org.apache.iceberg.io.PositionOutputStream; import org.apache.polaris.core.PolarisCallContext; -import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; +import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.TaskEntity; +import org.apache.polaris.core.persistence.BasePersistence; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.service.TestFileIOFactory; import org.junit.jupiter.api.Test; @QuarkusTest class ManifestFileCleanupTaskHandlerTest { + @Inject PolarisDiagnostics diagnostics; @Inject MetaStoreManagerFactory metaStoreManagerFactory; private final RealmContext realmContext = () -> "realmName"; @@ -59,13 +61,14 @@ class ManifestFileCleanupTaskHandlerTest { return new TaskFileIOSupplier(new TestFileIOFactory(fileIO)); } + private PolarisCallContext newCallContext() { + BasePersistence metaStore = metaStoreManagerFactory.getOrCreateSession(realmContext); + return new PolarisCallContext(realmContext, metaStore, diagnostics); + } + @Test public void testCleanupFileNotExists() throws IOException { - PolarisCallContext polarisCallContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - new PolarisDefaultDiagServiceImpl()); + PolarisCallContext polarisCallContext = newCallContext(); FileIO fileIO = new InMemoryFileIO(); TableIdentifier tableIdentifier = TableIdentifier.of(Namespace.of("db1", "schema1"), "table1"); @@ -91,11 +94,7 @@ class ManifestFileCleanupTaskHandlerTest { @Test public void testCleanupFileManifestExistsDataFilesDontExist() throws IOException { - PolarisCallContext polarisCallContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - new PolarisDefaultDiagServiceImpl()); + PolarisCallContext polarisCallContext = newCallContext(); FileIO fileIO = new InMemoryFileIO(); TableIdentifier tableIdentifier = TableIdentifier.of(Namespace.of("db1", "schema1"), "table1"); ManifestFileCleanupTaskHandler handler = @@ -119,11 +118,7 @@ class ManifestFileCleanupTaskHandlerTest { @Test public void testCleanupFiles() throws IOException { - PolarisCallContext polarisCallContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - new PolarisDefaultDiagServiceImpl()); + PolarisCallContext polarisCallContext = newCallContext(); FileIO fileIO = new InMemoryFileIO() { @Override @@ -164,11 +159,7 @@ class ManifestFileCleanupTaskHandlerTest { @Test public void testCleanupFilesWithRetries() throws IOException { - PolarisCallContext polarisCallContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - new PolarisDefaultDiagServiceImpl()); + PolarisCallContext polarisCallContext = newCallContext(); Map<String, AtomicInteger> retryCounter = new HashMap<>(); FileIO fileIO = new InMemoryFileIO() { diff --git a/runtime/service/src/test/java/org/apache/polaris/service/task/TaskExecutorImplTest.java b/runtime/service/src/test/java/org/apache/polaris/service/task/TaskExecutorImplTest.java index 369e14ec4..9cdbadd72 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/task/TaskExecutorImplTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/task/TaskExecutorImplTest.java @@ -22,7 +22,6 @@ import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.context.CallContext; import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.TaskEntity; -import org.apache.polaris.core.persistence.BasePersistence; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.service.TestServices; @@ -47,10 +46,8 @@ public class TaskExecutorImplTest { MetaStoreManagerFactory metaStoreManagerFactory = testServices.metaStoreManagerFactory(); PolarisMetaStoreManager metaStoreManager = metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); - BasePersistence bp = metaStoreManagerFactory.getOrCreateSession(realmContext); - PolarisCallContext polarisCallCtx = - new PolarisCallContext(realmContext, bp, testServices.polarisDiagnostics()); + PolarisCallContext polarisCallCtx = testServices.newCallContext(); // This task doesn't have a type so it won't be handle-able by a real handler. We register a // test TaskHandler below that can handle any task. diff --git a/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java b/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java index 095b2acb1..ed78d8bfe 100644 --- a/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java +++ b/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java @@ -298,4 +298,10 @@ public record TestServices( polarisEventListener); } } + + public PolarisCallContext newCallContext() { + BasePersistence metaStore = metaStoreManagerFactory.getOrCreateSession(realmContext); + return new PolarisCallContext( + realmContext, metaStore, polarisDiagnostics, configurationStore, Clock.systemUTC()); + } }