This is an automated email from the ASF dual-hosted git repository.
dimas 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 7ca497026 Add TestFileIOFactory helper (#2105)
7ca497026 is described below
commit 7ca49702694f0200752d9d7e41a2d7f319b23fea
Author: Christopher Lambert <[email protected]>
AuthorDate: Wed Jul 16 19:36:20 2025 +0200
Add TestFileIOFactory helper (#2105)
* Add FileIOFactory.wrapExisting helper
---
.../task/BatchFileCleanupTaskHandlerTest.java | 21 +--------
.../task/ManifestFileCleanupTaskHandlerTest.java | 21 +--------
.../quarkus/task/TableCleanupTaskHandlerTest.java | 38 ++--------------
.../apache/polaris/service/TestFileIOFactory.java | 52 ++++++++++++++++++++++
4 files changed, 60 insertions(+), 72 deletions(-)
diff --git
a/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/BatchFileCleanupTaskHandlerTest.java
b/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/BatchFileCleanupTaskHandlerTest.java
index eaaf649b6..37162b5df 100644
---
a/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/BatchFileCleanupTaskHandlerTest.java
+++
b/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/BatchFileCleanupTaskHandlerTest.java
@@ -23,13 +23,11 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatPredicate;
import io.quarkus.test.junit.QuarkusTest;
-import jakarta.annotation.Nonnull;
import jakarta.inject.Inject;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
@@ -51,9 +49,7 @@ 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.MetaStoreManagerFactory;
-import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
-import org.apache.polaris.core.storage.PolarisStorageActions;
-import org.apache.polaris.service.catalog.io.FileIOFactory;
+import org.apache.polaris.service.TestFileIOFactory;
import org.apache.polaris.service.task.BatchFileCleanupTaskHandler;
import org.apache.polaris.service.task.TaskFileIOSupplier;
import org.apache.polaris.service.task.TaskUtils;
@@ -65,20 +61,7 @@ public class BatchFileCleanupTaskHandlerTest {
private final RealmContext realmContext = () -> "realmName";
private TaskFileIOSupplier buildTaskFileIOSupplier(FileIO fileIO) {
- return new TaskFileIOSupplier(
- new FileIOFactory() {
- @Override
- public FileIO loadFileIO(
- @Nonnull CallContext callContext,
- @Nonnull String ioImplClassName,
- @Nonnull Map<String, String> properties,
- @Nonnull TableIdentifier identifier,
- @Nonnull Set<String> tableLocations,
- @Nonnull Set<PolarisStorageActions> storageActions,
- @Nonnull PolarisResolvedPathWrapper resolvedEntityPath) {
- return fileIO;
- }
- });
+ return new TaskFileIOSupplier(new TestFileIOFactory(fileIO));
}
@Test
diff --git
a/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/ManifestFileCleanupTaskHandlerTest.java
b/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/ManifestFileCleanupTaskHandlerTest.java
index 8c370dc9f..381dfa8a8 100644
---
a/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/ManifestFileCleanupTaskHandlerTest.java
+++
b/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/ManifestFileCleanupTaskHandlerTest.java
@@ -24,12 +24,10 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatPredicate;
import io.quarkus.test.junit.QuarkusTest;
-import jakarta.annotation.Nonnull;
import jakarta.inject.Inject;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
@@ -49,9 +47,7 @@ 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.MetaStoreManagerFactory;
-import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
-import org.apache.polaris.core.storage.PolarisStorageActions;
-import org.apache.polaris.service.catalog.io.FileIOFactory;
+import org.apache.polaris.service.TestFileIOFactory;
import org.apache.polaris.service.task.ManifestFileCleanupTaskHandler;
import org.apache.polaris.service.task.TaskFileIOSupplier;
import org.apache.polaris.service.task.TaskUtils;
@@ -64,20 +60,7 @@ class ManifestFileCleanupTaskHandlerTest {
private final RealmContext realmContext = () -> "realmName";
private TaskFileIOSupplier buildTaskFileIOSupplier(FileIO fileIO) {
- return new TaskFileIOSupplier(
- new FileIOFactory() {
- @Override
- public FileIO loadFileIO(
- @Nonnull CallContext callContext,
- @Nonnull String ioImplClassName,
- @Nonnull Map<String, String> properties,
- @Nonnull TableIdentifier identifier,
- @Nonnull Set<String> tableLocations,
- @Nonnull Set<PolarisStorageActions> storageActions,
- @Nonnull PolarisResolvedPathWrapper resolvedEntityPath) {
- return fileIO;
- }
- });
+ return new TaskFileIOSupplier(new TestFileIOFactory(fileIO));
}
@Test
diff --git
a/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/TableCleanupTaskHandlerTest.java
b/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/TableCleanupTaskHandlerTest.java
index 9b03feee5..69304956b 100644
---
a/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/TableCleanupTaskHandlerTest.java
+++
b/runtime/service/src/test/java/org/apache/polaris/service/quarkus/task/TableCleanupTaskHandlerTest.java
@@ -23,13 +23,10 @@ import static org.assertj.core.api.Assertions.assertThat;
import io.quarkus.test.junit.QuarkusMock;
import io.quarkus.test.junit.QuarkusTest;
-import jakarta.annotation.Nonnull;
import jakarta.inject.Inject;
import java.io.IOException;
import java.time.Clock;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
import java.util.UUID;
import org.apache.commons.codec.binary.Base64;
import org.apache.iceberg.ManifestFile;
@@ -52,12 +49,9 @@ import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntityType;
import org.apache.polaris.core.entity.TaskEntity;
import org.apache.polaris.core.entity.table.IcebergTableLikeEntity;
-import org.apache.polaris.core.persistence.BasePersistence;
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
-import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
import org.apache.polaris.core.persistence.pagination.PageToken;
-import org.apache.polaris.core.storage.PolarisStorageActions;
-import org.apache.polaris.service.catalog.io.FileIOFactory;
+import org.apache.polaris.service.TestFileIOFactory;
import org.apache.polaris.service.task.BatchFileCleanupTaskHandler;
import org.apache.polaris.service.task.ManifestFileCleanupTaskHandler;
import org.apache.polaris.service.task.TableCleanupTaskHandler;
@@ -80,20 +74,7 @@ class TableCleanupTaskHandlerTest {
private final RealmContext realmContext = () -> "realmName";
private TaskFileIOSupplier buildTaskFileIOSupplier(FileIO fileIO) {
- return new TaskFileIOSupplier(
- new FileIOFactory() {
- @Override
- public FileIO loadFileIO(
- @Nonnull CallContext callContext,
- @Nonnull String ioImplClassName,
- @Nonnull Map<String, String> properties,
- @Nonnull TableIdentifier identifier,
- @Nonnull Set<String> tableLocations,
- @Nonnull Set<PolarisStorageActions> storageActions,
- @Nonnull PolarisResolvedPathWrapper resolvedEntityPath) {
- return fileIO;
- }
- });
+ return new TaskFileIOSupplier(new TestFileIOFactory(fileIO));
}
@BeforeEach
@@ -170,8 +151,7 @@ class TableCleanupTaskHandlerTest {
assertThat(taskEntity)
.returns(PolarisEntityType.TASK.getCode(),
PolarisBaseEntity::getTypeCode)
.extracting(TaskEntity::of)
- .returns(
- AsyncTaskType.BATCH_FILE_CLEANUP, taskEntity2 ->
taskEntity2.getTaskType())
+ .returns(AsyncTaskType.BATCH_FILE_CLEANUP,
TaskEntity::getTaskType)
.returns(
new BatchFileCleanupTaskHandler.BatchFileCleanupTask(
tableIdentifier,
@@ -183,8 +163,6 @@ class TableCleanupTaskHandlerTest {
@Test
public void testTableCleanupHandlesAlreadyDeletedMetadata() throws
IOException {
- BasePersistence metaStoreSession =
- metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get();
FileIO fileIO =
new InMemoryFileIO() {
@Override
@@ -237,8 +215,6 @@ class TableCleanupTaskHandlerTest {
@Test
public void testTableCleanupDuplicatesTasksIfFileStillExists() throws
IOException {
- BasePersistence metaStoreSession =
- metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get();
FileIO fileIO =
new InMemoryFileIO() {
@Override
@@ -333,9 +309,7 @@ class TableCleanupTaskHandlerTest {
assertThat(taskEntity)
.returns(PolarisEntityType.TASK.getCode(),
PolarisBaseEntity::getTypeCode)
.extracting(TaskEntity::of)
- .returns(
- AsyncTaskType.MANIFEST_FILE_CLEANUP,
- taskEntity4 -> taskEntity4.getTaskType())
+ .returns(AsyncTaskType.MANIFEST_FILE_CLEANUP,
TaskEntity::getTaskType)
.returns(
new ManifestFileCleanupTaskHandler.ManifestCleanupTask(
tableIdentifier,
@@ -347,8 +321,6 @@ class TableCleanupTaskHandlerTest {
@Test
public void testTableCleanupMultipleSnapshots() throws IOException {
- BasePersistence metaStoreSession =
- metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get();
FileIO fileIO = new InMemoryFileIO();
TableIdentifier tableIdentifier = TableIdentifier.of(Namespace.of("db1",
"schema1"), "table1");
TableCleanupTaskHandler handler =
@@ -492,8 +464,6 @@ class TableCleanupTaskHandlerTest {
@Test
public void testTableCleanupMultipleMetadata() throws IOException {
- BasePersistence metaStoreSession =
- metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get();
FileIO fileIO = new InMemoryFileIO();
TableIdentifier tableIdentifier = TableIdentifier.of(Namespace.of("db1",
"schema1"), "table1");
TableCleanupTaskHandler handler =
diff --git
a/service/common/src/testFixtures/java/org/apache/polaris/service/TestFileIOFactory.java
b/service/common/src/testFixtures/java/org/apache/polaris/service/TestFileIOFactory.java
new file mode 100644
index 000000000..67d15a94c
--- /dev/null
+++
b/service/common/src/testFixtures/java/org/apache/polaris/service/TestFileIOFactory.java
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import jakarta.annotation.Nonnull;
+import java.util.Map;
+import java.util.Set;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.io.FileIO;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
+import org.apache.polaris.core.storage.PolarisStorageActions;
+import org.apache.polaris.service.catalog.io.FileIOFactory;
+
+/** A FileIOFactory that always returns the same FileIO instance. */
+public class TestFileIOFactory implements FileIOFactory {
+
+ private final FileIO fileIO;
+
+ public TestFileIOFactory(@Nonnull FileIO fileIO) {
+ this.fileIO = fileIO;
+ }
+
+ @Override
+ public FileIO loadFileIO(
+ @Nonnull CallContext callContext,
+ @Nonnull String ioImplClassName,
+ @Nonnull Map<String, String> properties,
+ @Nonnull TableIdentifier identifier,
+ @Nonnull Set<String> tableLocations,
+ @Nonnull Set<PolarisStorageActions> storageActions,
+ @Nonnull PolarisResolvedPathWrapper resolvedEntityPath) {
+ return fileIO;
+ }
+}