Skip to content

Commit 511df8c

Browse files
authored
Remove CallContext.of (#1812)
This PR is a follow-up of #1806 to remove all usage of CallContext.of() in tests and the method itself
1 parent 5132312 commit 511df8c

File tree

15 files changed

+71
-110
lines changed

15 files changed

+71
-110
lines changed

polaris-core/src/main/java/org/apache/polaris/core/context/CallContext.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,6 @@ static void unsetCurrentContext() {
4949
CURRENT_CONTEXT.remove();
5050
}
5151

52-
// only tests are using this method now, we can get rid of them easily in a followup
53-
static CallContext of(
54-
final RealmContext realmContext, final PolarisCallContext polarisCallContext) {
55-
return new CallContext() {
56-
@Override
57-
public RealmContext getRealmContext() {
58-
return realmContext;
59-
}
60-
61-
@Override
62-
public PolarisCallContext getPolarisCallContext() {
63-
return polarisCallContext;
64-
}
65-
};
66-
}
67-
6852
/** Copy the {@link CallContext}. */
6953
static CallContext copyOf(CallContext base) {
7054
String realmId = base.getRealmContext().getRealmIdentifier();

polaris-core/src/test/java/org/apache/polaris/core/storage/InMemoryStorageIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void testValidateAccessToLocationsWithWildcard() {
107107
}
108108
},
109109
Clock.systemUTC());
110-
CallContext.setCurrentContext(CallContext.of(() -> "realm", polarisCallContext));
110+
CallContext.setCurrentContext(polarisCallContext);
111111
Map<String, Map<PolarisStorageActions, PolarisStorageIntegration.ValidationResult>> result =
112112
storage.validateAccessToLocations(
113113
new FileStorageConfigurationInfo(List.of("file://", "*")),

polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BasePolarisMetaStoreManagerTest.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ protected void testBrowse() {
104104
@Test
105105
protected void testCreateEntities() {
106106
PolarisMetaStoreManager metaStoreManager = polarisTestMetaStoreManager.polarisMetaStoreManager;
107-
CallContext callCtx =
108-
CallContext.of(() -> "testRealm", polarisTestMetaStoreManager.polarisCallContext);
109107
if (CallContext.getCurrentContext() == null) {
110-
CallContext.setCurrentContext(callCtx);
108+
CallContext.setCurrentContext(polarisTestMetaStoreManager.polarisCallContext);
111109
}
112110
TaskEntity task1 = createTask("task1", 100L);
113111
TaskEntity task2 = createTask("task2", 101L);
@@ -155,10 +153,8 @@ protected void testCreateEntities() {
155153
@Test
156154
protected void testCreateEntitiesAlreadyExisting() {
157155
PolarisMetaStoreManager metaStoreManager = polarisTestMetaStoreManager.polarisMetaStoreManager;
158-
CallContext callCtx =
159-
CallContext.of(() -> "testRealm", polarisTestMetaStoreManager.polarisCallContext);
160156
if (CallContext.getCurrentContext() == null) {
161-
CallContext.setCurrentContext(callCtx);
157+
CallContext.setCurrentContext(polarisTestMetaStoreManager.polarisCallContext);
162158
}
163159
TaskEntity task1 = createTask("task1", 100L);
164160
TaskEntity task2 = createTask("task2", 101L);
@@ -194,10 +190,8 @@ protected void testCreateEntitiesAlreadyExisting() {
194190
@Test
195191
protected void testCreateEntitiesWithConflict() {
196192
PolarisMetaStoreManager metaStoreManager = polarisTestMetaStoreManager.polarisMetaStoreManager;
197-
CallContext callCtx =
198-
CallContext.of(() -> "testRealm", polarisTestMetaStoreManager.polarisCallContext);
199193
if (CallContext.getCurrentContext() == null) {
200-
CallContext.setCurrentContext(callCtx);
194+
CallContext.setCurrentContext(polarisTestMetaStoreManager.polarisCallContext);
201195
}
202196
TaskEntity task1 = createTask("task1", 100L);
203197
TaskEntity task2 = createTask("task2", 101L);

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/ManagementServiceTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void setup() {
7676
fakeServices.polarisDiagnostics(),
7777
fakeServices.configurationStore(),
7878
Mockito.mock(Clock.class));
79-
CallContext.setCurrentContext(CallContext.of(fakeServices.realmContext(), polarisCallContext));
79+
CallContext.setCurrentContext(polarisCallContext);
8080
services =
8181
TestServices.builder()
8282
.config(Map.of("SUPPORTED_CATALOG_STORAGE_TYPES", List.of("S3", "GCS", "AZURE")))
@@ -193,10 +193,9 @@ private PolarisCallContext setupCallContext(PolarisMetaStoreManager metaStoreMan
193193

194194
private PolarisAdminService setupPolarisAdminService(
195195
PolarisMetaStoreManager metaStoreManager, PolarisCallContext callContext) {
196-
RealmContext realmContext = services.realmContext();
197196
return new PolarisAdminService(
198-
CallContext.of(realmContext, callContext),
199-
services.entityManagerFactory().getOrCreateEntityManager(realmContext),
197+
callContext,
198+
services.entityManagerFactory().getOrCreateEntityManager(callContext.getRealmContext()),
200199
metaStoreManager,
201200
new UnsafeInMemorySecretsManager(),
202201
new SecurityContext() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public void before(TestInfo testInfo) {
244244
clock);
245245
this.entityManager = realmEntityManagerFactory.getOrCreateEntityManager(realmContext);
246246

247-
callContext = CallContext.of(realmContext, polarisContext);
247+
callContext = polarisContext;
248248
CallContext.setCurrentContext(callContext);
249249

250250
PrincipalEntity rootEntity =

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/IcebergCatalogTest.java

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ public Map<String, String> getConfigOverrides() {
212212
@Inject PolarisEventListener polarisEventListener;
213213

214214
private IcebergCatalog catalog;
215-
private CallContext callContext;
216215
private String realmName;
217216
private PolarisMetaStoreManager metaStoreManager;
218217
private UserSecretsManager userSecretsManager;
@@ -260,8 +259,6 @@ public void before(TestInfo testInfo) {
260259
new PolarisEntityManager(
261260
metaStoreManager, new StorageCredentialCache(), createEntityCache(metaStoreManager));
262261

263-
callContext = CallContext.of(realmContext, polarisContext);
264-
265262
PrincipalEntity rootEntity =
266263
new PrincipalEntity(
267264
PolarisEntity.of(
@@ -285,7 +282,7 @@ public void before(TestInfo testInfo) {
285282

286283
adminService =
287284
new PolarisAdminService(
288-
callContext,
285+
polarisContext,
289286
entityManager,
290287
metaStoreManager,
291288
userSecretsManager,
@@ -369,13 +366,13 @@ protected IcebergCatalog initCatalog(
369366
String catalogName, Map<String, String> additionalProperties) {
370367
PolarisPassthroughResolutionView passthroughView =
371368
new PolarisPassthroughResolutionView(
372-
callContext, entityManager, securityContext, CATALOG_NAME);
369+
polarisContext, entityManager, securityContext, CATALOG_NAME);
373370
TaskExecutor taskExecutor = Mockito.mock();
374371
IcebergCatalog icebergCatalog =
375372
new IcebergCatalog(
376373
entityManager,
377374
metaStoreManager,
378-
callContext,
375+
polarisContext,
379376
passthroughView,
380377
securityContext,
381378
taskExecutor,
@@ -661,7 +658,7 @@ public void testValidateNotificationFailToCreateFileIO() {
661658
final String tableMetadataLocation = tableLocation + "metadata/";
662659
PolarisPassthroughResolutionView passthroughView =
663660
new PolarisPassthroughResolutionView(
664-
callContext, entityManager, securityContext, catalog().name());
661+
polarisContext, entityManager, securityContext, catalog().name());
665662
FileIOFactory fileIOFactory =
666663
spy(
667664
new DefaultFileIOFactory(
@@ -672,7 +669,7 @@ public void testValidateNotificationFailToCreateFileIO() {
672669
new IcebergCatalog(
673670
entityManager,
674671
metaStoreManager,
675-
callContext,
672+
polarisContext,
676673
passthroughView,
677674
securityContext,
678675
Mockito.mock(TaskExecutor.class),
@@ -997,13 +994,13 @@ public void testUpdateNotificationCreateTableWithLocalFilePrefix() {
997994

998995
PolarisPassthroughResolutionView passthroughView =
999996
new PolarisPassthroughResolutionView(
1000-
callContext, entityManager, securityContext, catalogWithoutStorage);
997+
polarisContext, entityManager, securityContext, catalogWithoutStorage);
1001998
TaskExecutor taskExecutor = Mockito.mock();
1002999
IcebergCatalog catalog =
10031000
new IcebergCatalog(
10041001
entityManager,
10051002
metaStoreManager,
1006-
callContext,
1003+
polarisContext,
10071004
passthroughView,
10081005
securityContext,
10091006
taskExecutor,
@@ -1030,11 +1027,10 @@ public void testUpdateNotificationCreateTableWithLocalFilePrefix() {
10301027
metadataLocation,
10311028
TableMetadataParser.toJson(createSampleTableMetadata(metadataLocation)).getBytes(UTF_8));
10321029

1033-
PolarisCallContext polarisCallContext = callContext.getPolarisCallContext();
1034-
if (!polarisCallContext
1030+
if (!polarisContext
10351031
.getConfigurationStore()
10361032
.getConfiguration(
1037-
callContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
1033+
polarisContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
10381034
.contains("FILE")) {
10391035
Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, request))
10401036
.isInstanceOf(ForbiddenException.class)
@@ -1063,14 +1059,14 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() {
10631059

10641060
PolarisPassthroughResolutionView passthroughView =
10651061
new PolarisPassthroughResolutionView(
1066-
callContext, entityManager, securityContext, catalogName);
1062+
polarisContext, entityManager, securityContext, catalogName);
10671063
TaskExecutor taskExecutor = Mockito.mock();
10681064
InMemoryFileIO localFileIO = new InMemoryFileIO();
10691065
IcebergCatalog catalog =
10701066
new IcebergCatalog(
10711067
entityManager,
10721068
metaStoreManager,
1073-
callContext,
1069+
polarisContext,
10741070
passthroughView,
10751071
securityContext,
10761072
taskExecutor,
@@ -1099,11 +1095,10 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() {
10991095
metadataLocation,
11001096
TableMetadataParser.toJson(createSampleTableMetadata(metadataLocation)).getBytes(UTF_8));
11011097

1102-
PolarisCallContext polarisCallContext = callContext.getPolarisCallContext();
1103-
if (!polarisCallContext
1098+
if (!polarisContext
11041099
.getConfigurationStore()
11051100
.getConfiguration(
1106-
callContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
1101+
polarisContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
11071102
.contains("FILE")) {
11081103
Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, request))
11091104
.isInstanceOf(ForbiddenException.class)
@@ -1122,10 +1117,10 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() {
11221117
httpsMetadataLocation,
11231118
TableMetadataParser.toJson(createSampleTableMetadata(metadataLocation)).getBytes(UTF_8));
11241119

1125-
if (!polarisCallContext
1120+
if (!polarisContext
11261121
.getConfigurationStore()
11271122
.getConfiguration(
1128-
callContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
1123+
polarisContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
11291124
.contains("FILE")) {
11301125
Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, newRequest))
11311126
.isInstanceOf(ForbiddenException.class)
@@ -1566,7 +1561,7 @@ public void testDropTableWithPurge() {
15661561
new RealmEntityManagerFactory(metaStoreManagerFactory),
15671562
metaStoreManagerFactory,
15681563
configurationStore))
1569-
.apply(taskEntity, callContext);
1564+
.apply(taskEntity, polarisContext);
15701565
Assertions.assertThat(fileIO).isNotNull().isInstanceOf(ExceptionMappingFileIO.class);
15711566
Assertions.assertThat(((ExceptionMappingFileIO) fileIO).getInnerIo())
15721567
.isInstanceOf(InMemoryFileIO.class);
@@ -1600,12 +1595,12 @@ public void testDropTableWithPurgeDisabled() {
16001595
.asCatalog()));
16011596
PolarisPassthroughResolutionView passthroughView =
16021597
new PolarisPassthroughResolutionView(
1603-
callContext, entityManager, securityContext, noPurgeCatalogName);
1598+
polarisContext, entityManager, securityContext, noPurgeCatalogName);
16041599
IcebergCatalog noPurgeCatalog =
16051600
new IcebergCatalog(
16061601
entityManager,
16071602
metaStoreManager,
1608-
callContext,
1603+
polarisContext,
16091604
passthroughView,
16101605
securityContext,
16111606
Mockito.mock(),
@@ -1703,7 +1698,7 @@ static Stream<Arguments> testRetriableException() {
17031698
public void testFileIOWrapper() {
17041699
PolarisPassthroughResolutionView passthroughView =
17051700
new PolarisPassthroughResolutionView(
1706-
callContext, entityManager, securityContext, CATALOG_NAME);
1701+
polarisContext, entityManager, securityContext, CATALOG_NAME);
17071702

17081703
MeasuredFileIOFactory measured =
17091704
new MeasuredFileIOFactory(
@@ -1714,7 +1709,7 @@ public void testFileIOWrapper() {
17141709
new IcebergCatalog(
17151710
entityManager,
17161711
metaStoreManager,
1717-
callContext,
1712+
polarisContext,
17181713
passthroughView,
17191714
securityContext,
17201715
Mockito.mock(),
@@ -1748,8 +1743,7 @@ public void testFileIOWrapper() {
17481743
TaskEntity taskEntity =
17491744
TaskEntity.of(
17501745
metaStoreManager
1751-
.loadTasks(
1752-
callContext.getPolarisCallContext(), "testExecutor", PageToken.fromLimit(1))
1746+
.loadTasks(polarisContext, "testExecutor", PageToken.fromLimit(1))
17531747
.getEntities()
17541748
.getFirst());
17551749
Map<String, String> properties = taskEntity.getInternalPropertiesAsMap();
@@ -1781,7 +1775,7 @@ public FileIO loadFileIO(
17811775
TableCleanupTaskHandler handler =
17821776
new TableCleanupTaskHandler(
17831777
Mockito.mock(), createMockMetaStoreManagerFactory(), taskFileIOSupplier);
1784-
handler.handleTask(taskEntity, callContext);
1778+
handler.handleTask(taskEntity, polarisContext);
17851779
Assertions.assertThat(measured.getNumDeletedFiles()).as("A table was deleted").isGreaterThan(0);
17861780
}
17871781

@@ -1810,12 +1804,12 @@ public void testConcurrencyConflictCreateTableUpdatedDuringFinalTransaction() {
18101804
PolarisMetaStoreManager spyMetaStore = spy(metaStoreManager);
18111805
PolarisPassthroughResolutionView passthroughView =
18121806
new PolarisPassthroughResolutionView(
1813-
callContext, entityManager, securityContext, CATALOG_NAME);
1807+
polarisContext, entityManager, securityContext, CATALOG_NAME);
18141808
final IcebergCatalog catalog =
18151809
new IcebergCatalog(
18161810
entityManager,
18171811
spyMetaStore,
1818-
callContext,
1812+
polarisContext,
18191813
passthroughView,
18201814
securityContext,
18211815
Mockito.mock(TaskExecutor.class),
@@ -1859,12 +1853,12 @@ public void testConcurrencyConflictUpdateTableDuringFinalTransaction() {
18591853
PolarisMetaStoreManager spyMetaStore = spy(metaStoreManager);
18601854
PolarisPassthroughResolutionView passthroughView =
18611855
new PolarisPassthroughResolutionView(
1862-
callContext, entityManager, securityContext, CATALOG_NAME);
1856+
polarisContext, entityManager, securityContext, CATALOG_NAME);
18631857
final IcebergCatalog catalog =
18641858
new IcebergCatalog(
18651859
entityManager,
18661860
spyMetaStore,
1867-
callContext,
1861+
polarisContext,
18681862
passthroughView,
18691863
securityContext,
18701864
Mockito.mock(TaskExecutor.class),

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/IcebergCatalogViewTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ public void before(TestInfo testInfo) {
182182
new StorageCredentialCache(),
183183
new InMemoryEntityCache(metaStoreManager));
184184

185-
CallContext callContext = CallContext.of(realmContext, polarisContext);
186-
CallContext.setCurrentContext(callContext);
185+
CallContext.setCurrentContext(polarisContext);
187186

188187
PrincipalEntity rootEntity =
189188
new PrincipalEntity(
@@ -207,7 +206,7 @@ public void before(TestInfo testInfo) {
207206

208207
PolarisAdminService adminService =
209208
new PolarisAdminService(
210-
callContext,
209+
polarisContext,
211210
entityManager,
212211
metaStoreManager,
213212
userSecretsManager,
@@ -233,7 +232,7 @@ public void before(TestInfo testInfo) {
233232

234233
PolarisPassthroughResolutionView passthroughView =
235234
new PolarisPassthroughResolutionView(
236-
callContext, entityManager, securityContext, CATALOG_NAME);
235+
polarisContext, entityManager, securityContext, CATALOG_NAME);
237236
FileIOFactory fileIOFactory =
238237
new DefaultFileIOFactory(
239238
new RealmEntityManagerFactory(managerFactory), managerFactory, configurationStore);
@@ -243,7 +242,7 @@ public void before(TestInfo testInfo) {
243242
new IcebergCatalog(
244243
entityManager,
245244
metaStoreManager,
246-
callContext,
245+
polarisContext,
247246
passthroughView,
248247
securityContext,
249248
Mockito.mock(),

0 commit comments

Comments
 (0)