Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
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;
Expand All @@ -51,9 +49,7 @@
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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
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;
Expand All @@ -49,9 +47,7 @@
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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@

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;
Expand All @@ -52,12 +49,9 @@
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;
Expand All @@ -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
Expand Down Expand Up @@ -170,8 +151,7 @@ public void testTableCleanup() throws IOException {
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,
Expand All @@ -183,8 +163,6 @@ public void testTableCleanup() throws IOException {

@Test
public void testTableCleanupHandlesAlreadyDeletedMetadata() throws IOException {
BasePersistence metaStoreSession =
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get();
FileIO fileIO =
new InMemoryFileIO() {
@Override
Expand Down Expand Up @@ -237,8 +215,6 @@ public void close() {

@Test
public void testTableCleanupDuplicatesTasksIfFileStillExists() throws IOException {
BasePersistence metaStoreSession =
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get();
FileIO fileIO =
new InMemoryFileIO() {
@Override
Expand Down Expand Up @@ -333,9 +309,7 @@ public void close() {
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,
Expand All @@ -347,8 +321,6 @@ public void close() {

@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 =
Expand Down Expand Up @@ -492,8 +464,6 @@ public void testTableCleanupMultipleSnapshots() throws IOException {

@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 =
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}