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 @@ -49,22 +49,6 @@ static void unsetCurrentContext() {
CURRENT_CONTEXT.remove();
}

// only tests are using this method now, we can get rid of them easily in a followup
static CallContext of(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to go through a deprecation process for this even though it is a test only thing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have to do that. We can follow the process after 1.0.

final RealmContext realmContext, final PolarisCallContext polarisCallContext) {
return new CallContext() {
@Override
public RealmContext getRealmContext() {
return realmContext;
}

@Override
public PolarisCallContext getPolarisCallContext() {
return polarisCallContext;
}
};
}

/** Copy the {@link CallContext}. */
static CallContext copyOf(CallContext base) {
String realmId = base.getRealmContext().getRealmIdentifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void testValidateAccessToLocationsWithWildcard() {
}
},
Clock.systemUTC());
CallContext.setCurrentContext(CallContext.of(() -> "realm", polarisCallContext));
CallContext.setCurrentContext(polarisCallContext);
Map<String, Map<PolarisStorageActions, PolarisStorageIntegration.ValidationResult>> result =
storage.validateAccessToLocations(
new FileStorageConfigurationInfo(List.of("file://", "*")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ protected void testBrowse() {
@Test
protected void testCreateEntities() {
PolarisMetaStoreManager metaStoreManager = polarisTestMetaStoreManager.polarisMetaStoreManager;
CallContext callCtx =
CallContext.of(() -> "testRealm", polarisTestMetaStoreManager.polarisCallContext);
if (CallContext.getCurrentContext() == null) {
CallContext.setCurrentContext(callCtx);
CallContext.setCurrentContext(polarisTestMetaStoreManager.polarisCallContext);
}
TaskEntity task1 = createTask("task1", 100L);
TaskEntity task2 = createTask("task2", 101L);
Expand Down Expand Up @@ -155,10 +153,8 @@ protected void testCreateEntities() {
@Test
protected void testCreateEntitiesAlreadyExisting() {
PolarisMetaStoreManager metaStoreManager = polarisTestMetaStoreManager.polarisMetaStoreManager;
CallContext callCtx =
CallContext.of(() -> "testRealm", polarisTestMetaStoreManager.polarisCallContext);
if (CallContext.getCurrentContext() == null) {
CallContext.setCurrentContext(callCtx);
CallContext.setCurrentContext(polarisTestMetaStoreManager.polarisCallContext);
}
TaskEntity task1 = createTask("task1", 100L);
TaskEntity task2 = createTask("task2", 101L);
Expand Down Expand Up @@ -194,10 +190,8 @@ protected void testCreateEntitiesAlreadyExisting() {
@Test
protected void testCreateEntitiesWithConflict() {
PolarisMetaStoreManager metaStoreManager = polarisTestMetaStoreManager.polarisMetaStoreManager;
CallContext callCtx =
CallContext.of(() -> "testRealm", polarisTestMetaStoreManager.polarisCallContext);
if (CallContext.getCurrentContext() == null) {
CallContext.setCurrentContext(callCtx);
CallContext.setCurrentContext(polarisTestMetaStoreManager.polarisCallContext);
}
TaskEntity task1 = createTask("task1", 100L);
TaskEntity task2 = createTask("task2", 101L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void setup() {
fakeServices.polarisDiagnostics(),
fakeServices.configurationStore(),
Mockito.mock(Clock.class));
CallContext.setCurrentContext(CallContext.of(fakeServices.realmContext(), polarisCallContext));
CallContext.setCurrentContext(polarisCallContext);
services =
TestServices.builder()
.config(Map.of("SUPPORTED_CATALOG_STORAGE_TYPES", List.of("S3", "GCS", "AZURE")))
Expand Down Expand Up @@ -193,10 +193,9 @@ private PolarisCallContext setupCallContext(PolarisMetaStoreManager metaStoreMan

private PolarisAdminService setupPolarisAdminService(
PolarisMetaStoreManager metaStoreManager, PolarisCallContext callContext) {
RealmContext realmContext = services.realmContext();
return new PolarisAdminService(
CallContext.of(realmContext, callContext),
services.entityManagerFactory().getOrCreateEntityManager(realmContext),
callContext,
services.entityManagerFactory().getOrCreateEntityManager(callContext.getRealmContext()),
metaStoreManager,
new UnsafeInMemorySecretsManager(),
new SecurityContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public void before(TestInfo testInfo) {
clock);
this.entityManager = realmEntityManagerFactory.getOrCreateEntityManager(realmContext);

callContext = CallContext.of(realmContext, polarisContext);
callContext = polarisContext;
CallContext.setCurrentContext(callContext);

PrincipalEntity rootEntity =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public Map<String, String> getConfigOverrides() {
@Inject PolarisEventListener polarisEventListener;

private IcebergCatalog catalog;
private CallContext callContext;
private String realmName;
private PolarisMetaStoreManager metaStoreManager;
private UserSecretsManager userSecretsManager;
Expand Down Expand Up @@ -260,8 +259,6 @@ public void before(TestInfo testInfo) {
new PolarisEntityManager(
metaStoreManager, new StorageCredentialCache(), createEntityCache(metaStoreManager));

callContext = CallContext.of(realmContext, polarisContext);

PrincipalEntity rootEntity =
new PrincipalEntity(
PolarisEntity.of(
Expand All @@ -285,7 +282,7 @@ public void before(TestInfo testInfo) {

adminService =
new PolarisAdminService(
callContext,
polarisContext,
entityManager,
metaStoreManager,
userSecretsManager,
Expand Down Expand Up @@ -369,13 +366,13 @@ protected IcebergCatalog initCatalog(
String catalogName, Map<String, String> additionalProperties) {
PolarisPassthroughResolutionView passthroughView =
new PolarisPassthroughResolutionView(
callContext, entityManager, securityContext, CATALOG_NAME);
polarisContext, entityManager, securityContext, CATALOG_NAME);
TaskExecutor taskExecutor = Mockito.mock();
IcebergCatalog icebergCatalog =
new IcebergCatalog(
entityManager,
metaStoreManager,
callContext,
polarisContext,
passthroughView,
securityContext,
taskExecutor,
Expand Down Expand Up @@ -661,7 +658,7 @@ public void testValidateNotificationFailToCreateFileIO() {
final String tableMetadataLocation = tableLocation + "metadata/";
PolarisPassthroughResolutionView passthroughView =
new PolarisPassthroughResolutionView(
callContext, entityManager, securityContext, catalog().name());
polarisContext, entityManager, securityContext, catalog().name());
FileIOFactory fileIOFactory =
spy(
new DefaultFileIOFactory(
Expand All @@ -672,7 +669,7 @@ public void testValidateNotificationFailToCreateFileIO() {
new IcebergCatalog(
entityManager,
metaStoreManager,
callContext,
polarisContext,
passthroughView,
securityContext,
Mockito.mock(TaskExecutor.class),
Expand Down Expand Up @@ -997,13 +994,13 @@ public void testUpdateNotificationCreateTableWithLocalFilePrefix() {

PolarisPassthroughResolutionView passthroughView =
new PolarisPassthroughResolutionView(
callContext, entityManager, securityContext, catalogWithoutStorage);
polarisContext, entityManager, securityContext, catalogWithoutStorage);
TaskExecutor taskExecutor = Mockito.mock();
IcebergCatalog catalog =
new IcebergCatalog(
entityManager,
metaStoreManager,
callContext,
polarisContext,
passthroughView,
securityContext,
taskExecutor,
Expand All @@ -1030,11 +1027,10 @@ public void testUpdateNotificationCreateTableWithLocalFilePrefix() {
metadataLocation,
TableMetadataParser.toJson(createSampleTableMetadata(metadataLocation)).getBytes(UTF_8));

PolarisCallContext polarisCallContext = callContext.getPolarisCallContext();
if (!polarisCallContext
if (!polarisContext
.getConfigurationStore()
.getConfiguration(
callContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
polarisContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
.contains("FILE")) {
Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, request))
.isInstanceOf(ForbiddenException.class)
Expand Down Expand Up @@ -1063,14 +1059,14 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() {

PolarisPassthroughResolutionView passthroughView =
new PolarisPassthroughResolutionView(
callContext, entityManager, securityContext, catalogName);
polarisContext, entityManager, securityContext, catalogName);
TaskExecutor taskExecutor = Mockito.mock();
InMemoryFileIO localFileIO = new InMemoryFileIO();
IcebergCatalog catalog =
new IcebergCatalog(
entityManager,
metaStoreManager,
callContext,
polarisContext,
passthroughView,
securityContext,
taskExecutor,
Expand Down Expand Up @@ -1099,11 +1095,10 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() {
metadataLocation,
TableMetadataParser.toJson(createSampleTableMetadata(metadataLocation)).getBytes(UTF_8));

PolarisCallContext polarisCallContext = callContext.getPolarisCallContext();
if (!polarisCallContext
if (!polarisContext
.getConfigurationStore()
.getConfiguration(
callContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
polarisContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
.contains("FILE")) {
Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, request))
.isInstanceOf(ForbiddenException.class)
Expand All @@ -1122,10 +1117,10 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() {
httpsMetadataLocation,
TableMetadataParser.toJson(createSampleTableMetadata(metadataLocation)).getBytes(UTF_8));

if (!polarisCallContext
if (!polarisContext
.getConfigurationStore()
.getConfiguration(
callContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
polarisContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
.contains("FILE")) {
Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, newRequest))
.isInstanceOf(ForbiddenException.class)
Expand Down Expand Up @@ -1566,7 +1561,7 @@ public void testDropTableWithPurge() {
new RealmEntityManagerFactory(metaStoreManagerFactory),
metaStoreManagerFactory,
configurationStore))
.apply(taskEntity, callContext);
.apply(taskEntity, polarisContext);
Assertions.assertThat(fileIO).isNotNull().isInstanceOf(ExceptionMappingFileIO.class);
Assertions.assertThat(((ExceptionMappingFileIO) fileIO).getInnerIo())
.isInstanceOf(InMemoryFileIO.class);
Expand Down Expand Up @@ -1600,12 +1595,12 @@ public void testDropTableWithPurgeDisabled() {
.asCatalog()));
PolarisPassthroughResolutionView passthroughView =
new PolarisPassthroughResolutionView(
callContext, entityManager, securityContext, noPurgeCatalogName);
polarisContext, entityManager, securityContext, noPurgeCatalogName);
IcebergCatalog noPurgeCatalog =
new IcebergCatalog(
entityManager,
metaStoreManager,
callContext,
polarisContext,
passthroughView,
securityContext,
Mockito.mock(),
Expand Down Expand Up @@ -1703,7 +1698,7 @@ static Stream<Arguments> testRetriableException() {
public void testFileIOWrapper() {
PolarisPassthroughResolutionView passthroughView =
new PolarisPassthroughResolutionView(
callContext, entityManager, securityContext, CATALOG_NAME);
polarisContext, entityManager, securityContext, CATALOG_NAME);

MeasuredFileIOFactory measured =
new MeasuredFileIOFactory(
Expand All @@ -1714,7 +1709,7 @@ public void testFileIOWrapper() {
new IcebergCatalog(
entityManager,
metaStoreManager,
callContext,
polarisContext,
passthroughView,
securityContext,
Mockito.mock(),
Expand Down Expand Up @@ -1748,8 +1743,7 @@ public void testFileIOWrapper() {
TaskEntity taskEntity =
TaskEntity.of(
metaStoreManager
.loadTasks(
callContext.getPolarisCallContext(), "testExecutor", PageToken.fromLimit(1))
.loadTasks(polarisContext, "testExecutor", PageToken.fromLimit(1))
.getEntities()
.getFirst());
Map<String, String> properties = taskEntity.getInternalPropertiesAsMap();
Expand Down Expand Up @@ -1781,7 +1775,7 @@ public FileIO loadFileIO(
TableCleanupTaskHandler handler =
new TableCleanupTaskHandler(
Mockito.mock(), createMockMetaStoreManagerFactory(), taskFileIOSupplier);
handler.handleTask(taskEntity, callContext);
handler.handleTask(taskEntity, polarisContext);
Assertions.assertThat(measured.getNumDeletedFiles()).as("A table was deleted").isGreaterThan(0);
}

Expand Down Expand Up @@ -1810,12 +1804,12 @@ public void testConcurrencyConflictCreateTableUpdatedDuringFinalTransaction() {
PolarisMetaStoreManager spyMetaStore = spy(metaStoreManager);
PolarisPassthroughResolutionView passthroughView =
new PolarisPassthroughResolutionView(
callContext, entityManager, securityContext, CATALOG_NAME);
polarisContext, entityManager, securityContext, CATALOG_NAME);
final IcebergCatalog catalog =
new IcebergCatalog(
entityManager,
spyMetaStore,
callContext,
polarisContext,
passthroughView,
securityContext,
Mockito.mock(TaskExecutor.class),
Expand Down Expand Up @@ -1859,12 +1853,12 @@ public void testConcurrencyConflictUpdateTableDuringFinalTransaction() {
PolarisMetaStoreManager spyMetaStore = spy(metaStoreManager);
PolarisPassthroughResolutionView passthroughView =
new PolarisPassthroughResolutionView(
callContext, entityManager, securityContext, CATALOG_NAME);
polarisContext, entityManager, securityContext, CATALOG_NAME);
final IcebergCatalog catalog =
new IcebergCatalog(
entityManager,
spyMetaStore,
callContext,
polarisContext,
passthroughView,
securityContext,
Mockito.mock(TaskExecutor.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ public void before(TestInfo testInfo) {
new StorageCredentialCache(),
new InMemoryEntityCache(metaStoreManager));

CallContext callContext = CallContext.of(realmContext, polarisContext);
CallContext.setCurrentContext(callContext);
CallContext.setCurrentContext(polarisContext);

PrincipalEntity rootEntity =
new PrincipalEntity(
Expand All @@ -207,7 +206,7 @@ public void before(TestInfo testInfo) {

PolarisAdminService adminService =
new PolarisAdminService(
callContext,
polarisContext,
entityManager,
metaStoreManager,
userSecretsManager,
Expand All @@ -233,7 +232,7 @@ public void before(TestInfo testInfo) {

PolarisPassthroughResolutionView passthroughView =
new PolarisPassthroughResolutionView(
callContext, entityManager, securityContext, CATALOG_NAME);
polarisContext, entityManager, securityContext, CATALOG_NAME);
FileIOFactory fileIOFactory =
new DefaultFileIOFactory(
new RealmEntityManagerFactory(managerFactory), managerFactory, configurationStore);
Expand All @@ -243,7 +242,7 @@ public void before(TestInfo testInfo) {
new IcebergCatalog(
entityManager,
metaStoreManager,
callContext,
polarisContext,
passthroughView,
securityContext,
Mockito.mock(),
Expand Down
Loading
Loading