Skip to content

Commit 633cedf

Browse files
authored
Add newIcebergCatalog helper (#2134)
creation of `IcebergCatalog` instances was quite redundant as tests mostly use the same parameters most of the time. also remove an unused field in 2 other tests.
1 parent 8c0d967 commit 633cedf

File tree

3 files changed

+34
-113
lines changed

3 files changed

+34
-113
lines changed

runtime/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAuthzTestBase.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
7373
import org.apache.polaris.core.persistence.dao.entity.EntityResult;
7474
import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
75-
import org.apache.polaris.core.persistence.transactional.TransactionalPersistence;
7675
import org.apache.polaris.core.policy.PredefinedPolicyTypes;
7776
import org.apache.polaris.core.secrets.UserSecretsManager;
7877
import org.apache.polaris.core.secrets.UserSecretsManagerFactory;
@@ -200,7 +199,6 @@ public Map<String, String> getConfigOverrides() {
200199
protected PolarisEntityManager entityManager;
201200
protected PolarisMetaStoreManager metaStoreManager;
202201
protected UserSecretsManager userSecretsManager;
203-
protected TransactionalPersistence metaStoreSession;
204202
protected PolarisBaseEntity catalogEntity;
205203
protected PrincipalEntity principalEntity;
206204
protected CallContext callContext;

runtime/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisS3InteroperabilityTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.apache.iceberg.catalog.Namespace;
3232
import org.apache.iceberg.exceptions.ForbiddenException;
3333
import org.apache.iceberg.inmemory.InMemoryFileIO;
34-
import org.apache.iceberg.io.FileIO;
3534
import org.apache.iceberg.rest.requests.CreateNamespaceRequest;
3635
import org.apache.iceberg.rest.requests.CreateTableRequest;
3736
import org.apache.iceberg.rest.responses.GetNamespaceResponse;
@@ -61,8 +60,6 @@ public class PolarisS3InteroperabilityTest {
6160
"true",
6261
"SUPPORTED_CATALOG_STORAGE_TYPES",
6362
List.of("FILE", "S3"));
64-
private static final FileIO fileIO = new InMemoryFileIO();
65-
6663
private final TestServices services;
6764

6865
private static String makeNamespaceLocation(String catalogName, String namespace, String scheme) {

runtime/service/src/test/java/org/apache/polaris/service/quarkus/catalog/AbstractIcebergCatalogTest.java

Lines changed: 34 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -400,20 +400,7 @@ protected IcebergCatalog catalog() {
400400
@Override
401401
protected IcebergCatalog initCatalog(
402402
String catalogName, Map<String, String> additionalProperties) {
403-
PolarisPassthroughResolutionView passthroughView =
404-
new PolarisPassthroughResolutionView(
405-
polarisContext, entityManager, securityContext, CATALOG_NAME);
406-
TaskExecutor taskExecutor = Mockito.mock();
407-
IcebergCatalog icebergCatalog =
408-
new IcebergCatalog(
409-
entityManager,
410-
metaStoreManager,
411-
polarisContext,
412-
passthroughView,
413-
securityContext,
414-
taskExecutor,
415-
fileIOFactory,
416-
polarisEventListener);
403+
IcebergCatalog icebergCatalog = newIcebergCatalog(CATALOG_NAME);
417404
fileIO = new InMemoryFileIO();
418405
icebergCatalog.setCatalogFileIo(fileIO);
419406
ImmutableMap.Builder<String, String> propertiesBuilder =
@@ -444,6 +431,32 @@ protected boolean supportsNotifications() {
444431
return true;
445432
}
446433

434+
protected IcebergCatalog newIcebergCatalog(String catalogName) {
435+
return newIcebergCatalog(catalogName, metaStoreManager);
436+
}
437+
438+
protected IcebergCatalog newIcebergCatalog(
439+
String catalogName, PolarisMetaStoreManager metaStoreManager) {
440+
return newIcebergCatalog(catalogName, metaStoreManager, fileIOFactory);
441+
}
442+
443+
protected IcebergCatalog newIcebergCatalog(
444+
String catalogName, PolarisMetaStoreManager metaStoreManager, FileIOFactory fileIOFactory) {
445+
PolarisPassthroughResolutionView passthroughView =
446+
new PolarisPassthroughResolutionView(
447+
polarisContext, entityManager, securityContext, catalogName);
448+
TaskExecutor taskExecutor = Mockito.mock(TaskExecutor.class);
449+
return new IcebergCatalog(
450+
entityManager,
451+
metaStoreManager,
452+
polarisContext,
453+
passthroughView,
454+
securityContext,
455+
taskExecutor,
456+
fileIOFactory,
457+
polarisEventListener);
458+
}
459+
447460
@Test
448461
public void testEmptyNamespace() {
449462
IcebergCatalog catalog = catalog();
@@ -982,21 +995,9 @@ public void testValidateNotificationFailToCreateFileIO() {
982995
// filename.
983996
final String tableLocation = "s3://externally-owned-bucket/validate_table/";
984997
final String tableMetadataLocation = tableLocation + "metadata/";
985-
PolarisPassthroughResolutionView passthroughView =
986-
new PolarisPassthroughResolutionView(
987-
polarisContext, entityManager, securityContext, catalog().name());
988998
FileIOFactory fileIOFactory =
989999
spy(new DefaultFileIOFactory(realmEntityManagerFactory, metaStoreManagerFactory));
990-
IcebergCatalog catalog =
991-
new IcebergCatalog(
992-
entityManager,
993-
metaStoreManager,
994-
polarisContext,
995-
passthroughView,
996-
securityContext,
997-
Mockito.mock(TaskExecutor.class),
998-
fileIOFactory,
999-
polarisEventListener);
1000+
IcebergCatalog catalog = newIcebergCatalog(catalog().name(), metaStoreManager, fileIOFactory);
10001001
catalog.initialize(
10011002
CATALOG_NAME,
10021003
ImmutableMap.of(
@@ -1314,20 +1315,7 @@ public void testUpdateNotificationCreateTableWithLocalFilePrefix() {
13141315
.build()
13151316
.asCatalog()));
13161317

1317-
PolarisPassthroughResolutionView passthroughView =
1318-
new PolarisPassthroughResolutionView(
1319-
polarisContext, entityManager, securityContext, catalogWithoutStorage);
1320-
TaskExecutor taskExecutor = Mockito.mock();
1321-
IcebergCatalog catalog =
1322-
new IcebergCatalog(
1323-
entityManager,
1324-
metaStoreManager,
1325-
polarisContext,
1326-
passthroughView,
1327-
securityContext,
1328-
taskExecutor,
1329-
fileIOFactory,
1330-
polarisEventListener);
1318+
IcebergCatalog catalog = newIcebergCatalog(catalogWithoutStorage);
13311319
catalog.initialize(
13321320
catalogWithoutStorage,
13331321
ImmutableMap.of(
@@ -1378,21 +1366,7 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() {
13781366
.build()
13791367
.asCatalog()));
13801368

1381-
PolarisPassthroughResolutionView passthroughView =
1382-
new PolarisPassthroughResolutionView(
1383-
polarisContext, entityManager, securityContext, catalogName);
1384-
TaskExecutor taskExecutor = Mockito.mock();
1385-
InMemoryFileIO localFileIO = new InMemoryFileIO();
1386-
IcebergCatalog catalog =
1387-
new IcebergCatalog(
1388-
entityManager,
1389-
metaStoreManager,
1390-
polarisContext,
1391-
passthroughView,
1392-
securityContext,
1393-
taskExecutor,
1394-
fileIOFactory,
1395-
polarisEventListener);
1369+
IcebergCatalog catalog = newIcebergCatalog(catalogName);
13961370
catalog.initialize(
13971371
catalogName,
13981372
ImmutableMap.of(
@@ -1909,19 +1883,8 @@ public void testDropTableWithPurgeDisabled() {
19091883
polarisContext, noPurgeStorageConfigModel, storageLocation)
19101884
.build()
19111885
.asCatalog()));
1912-
PolarisPassthroughResolutionView passthroughView =
1913-
new PolarisPassthroughResolutionView(
1914-
polarisContext, entityManager, securityContext, noPurgeCatalogName);
19151886
IcebergCatalog noPurgeCatalog =
1916-
new IcebergCatalog(
1917-
entityManager,
1918-
metaStoreManager,
1919-
polarisContext,
1920-
passthroughView,
1921-
securityContext,
1922-
Mockito.mock(),
1923-
fileIOFactory,
1924-
polarisEventListener);
1887+
newIcebergCatalog(noPurgeCatalogName, metaStoreManager, fileIOFactory);
19251888
noPurgeCatalog.initialize(
19261889
noPurgeCatalogName,
19271890
ImmutableMap.of(
@@ -2012,22 +1975,9 @@ static Stream<Arguments> testRetriableException() {
20121975

20131976
@Test
20141977
public void testFileIOWrapper() {
2015-
PolarisPassthroughResolutionView passthroughView =
2016-
new PolarisPassthroughResolutionView(
2017-
polarisContext, entityManager, securityContext, CATALOG_NAME);
2018-
20191978
MeasuredFileIOFactory measured =
20201979
new MeasuredFileIOFactory(realmEntityManagerFactory, metaStoreManagerFactory);
2021-
IcebergCatalog catalog =
2022-
new IcebergCatalog(
2023-
entityManager,
2024-
metaStoreManager,
2025-
polarisContext,
2026-
passthroughView,
2027-
securityContext,
2028-
Mockito.mock(),
2029-
measured,
2030-
polarisEventListener);
1980+
IcebergCatalog catalog = newIcebergCatalog(CATALOG_NAME, metaStoreManager, measured);
20311981
catalog.initialize(
20321982
CATALOG_NAME,
20331983
ImmutableMap.of(
@@ -2116,19 +2066,7 @@ public void testConcurrencyConflictCreateTableUpdatedDuringFinalTransaction() {
21162066
// Use a spy so that non-transactional pre-requisites succeed normally, but we inject
21172067
// a concurrency failure at final commit.
21182068
PolarisMetaStoreManager spyMetaStore = spy(metaStoreManager);
2119-
PolarisPassthroughResolutionView passthroughView =
2120-
new PolarisPassthroughResolutionView(
2121-
polarisContext, entityManager, securityContext, CATALOG_NAME);
2122-
final IcebergCatalog catalog =
2123-
new IcebergCatalog(
2124-
entityManager,
2125-
spyMetaStore,
2126-
polarisContext,
2127-
passthroughView,
2128-
securityContext,
2129-
Mockito.mock(TaskExecutor.class),
2130-
fileIOFactory,
2131-
polarisEventListener);
2069+
final IcebergCatalog catalog = newIcebergCatalog(CATALOG_NAME, spyMetaStore);
21322070
catalog.initialize(
21332071
CATALOG_NAME,
21342072
ImmutableMap.of(
@@ -2165,19 +2103,7 @@ public void testConcurrencyConflictUpdateTableDuringFinalTransaction() {
21652103
// Use a spy so that non-transactional pre-requisites succeed normally, but we inject
21662104
// a concurrency failure at final commit.
21672105
PolarisMetaStoreManager spyMetaStore = spy(metaStoreManager);
2168-
PolarisPassthroughResolutionView passthroughView =
2169-
new PolarisPassthroughResolutionView(
2170-
polarisContext, entityManager, securityContext, CATALOG_NAME);
2171-
final IcebergCatalog catalog =
2172-
new IcebergCatalog(
2173-
entityManager,
2174-
spyMetaStore,
2175-
polarisContext,
2176-
passthroughView,
2177-
securityContext,
2178-
Mockito.mock(TaskExecutor.class),
2179-
fileIOFactory,
2180-
polarisEventListener);
2106+
final IcebergCatalog catalog = newIcebergCatalog(CATALOG_NAME, spyMetaStore);
21812107
catalog.initialize(
21822108
CATALOG_NAME,
21832109
ImmutableMap.of(

0 commit comments

Comments
 (0)