-
Notifications
You must be signed in to change notification settings - Fork 331
Replace getConfiguration usage with PolarisCallContext to use RealmContext (PART 1) #1780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,11 +78,11 @@ public InMemoryStorageIntegration(String identifierOrId) { | |
|
|
||
| boolean allowWildcardLocation = | ||
| Optional.ofNullable(CallContext.getCurrentContext()) | ||
| .flatMap(c -> Optional.ofNullable(c.getPolarisCallContext())) | ||
| .map( | ||
| pc -> | ||
| pc.getConfigurationStore() | ||
| .getConfiguration(pc, "ALLOW_WILDCARD_LOCATION", false)) | ||
| ctx -> | ||
| ctx.getPolarisCallContext() | ||
| .getConfigurationStore() | ||
| .getConfiguration(ctx.getRealmContext(), "ALLOW_WILDCARD_LOCATION", false)) | ||
|
Comment on lines
-81
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this change?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so, because we need to "undo" the translation from CallContext to PolarisCallContext so that we can recover the RealmContext.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad, didn't notice there was a |
||
| .orElse(false); | ||
|
|
||
| if (allowWildcardLocation && allowedLocationStrings.contains("*")) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,18 +23,19 @@ | |
| import java.util.Map; | ||
| import java.util.function.Function; | ||
| import java.util.function.Supplier; | ||
| import org.apache.polaris.core.PolarisCallContext; | ||
| import org.apache.polaris.core.config.BehaviorChangeConfiguration; | ||
| import org.apache.polaris.core.config.FeatureConfiguration; | ||
| import org.apache.polaris.core.config.PolarisConfiguration; | ||
| import org.apache.polaris.core.config.PolarisConfigurationStore; | ||
| import org.apache.polaris.core.context.RealmContext; | ||
| import org.apache.polaris.core.entity.CatalogEntity; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| /** Unit test for the default behaviors of the PolarisConfigurationStore interface. */ | ||
| public class PolarisConfigurationStoreTest { | ||
| private final RealmContext testRealmContext = () -> "testRealm"; | ||
|
|
||
| @Test | ||
| public void testConfigsCanBeCastedFromString() { | ||
| List<PolarisConfiguration<?>> configs = | ||
|
|
@@ -52,7 +53,7 @@ public void testConfigsCanBeCastedFromString() { | |
| */ | ||
| @SuppressWarnings("unchecked") | ||
| @Override | ||
| public <T> @Nullable T getConfiguration(PolarisCallContext ctx, String configName) { | ||
| public <T> @Nullable T getConfiguration(RealmContext ctx, String configName) { | ||
| for (PolarisConfiguration<?> c : configs) { | ||
| if (c.key.equals(configName)) { | ||
| return (T) String.valueOf(c.defaultValue); | ||
|
|
@@ -68,9 +69,8 @@ public void testConfigsCanBeCastedFromString() { | |
|
|
||
| // Ensure that we can fetch all the configs and that the value is what we expect, which | ||
| // is the config's default value based on how we've implemented PolarisConfigurationStore above. | ||
| PolarisCallContext polarisCallContext = Mockito.mock(PolarisCallContext.class); | ||
| for (PolarisConfiguration<?> c : configs) { | ||
| Assertions.assertEquals(c.defaultValue, store.getConfiguration(polarisCallContext, c)); | ||
| Assertions.assertEquals(c.defaultValue, store.getConfiguration(testRealmContext, c)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -84,15 +84,14 @@ public void testInvalidCastThrowsException() { | |
| new PolarisConfigurationStore() { | ||
| @SuppressWarnings("unchecked") | ||
| @Override | ||
| public <T> T getConfiguration(PolarisCallContext ctx, String configName) { | ||
| public <T> T getConfiguration(RealmContext ctx, String configName) { | ||
| return (T) "abc123"; | ||
| } | ||
| }; | ||
|
|
||
| PolarisCallContext polarisCallContext = Mockito.mock(PolarisCallContext.class); | ||
| for (PolarisConfiguration<?> c : configs) { | ||
| Assertions.assertThrows( | ||
| NumberFormatException.class, () -> store.getConfiguration(polarisCallContext, c)); | ||
| NumberFormatException.class, () -> store.getConfiguration(testRealmContext, c)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -106,18 +105,18 @@ private static <T> PolarisConfiguration<T> buildConfig(String key, T defaultValu | |
|
|
||
| private static class PolarisConfigurationConsumer { | ||
|
|
||
| private final PolarisCallContext polarisCallContext; | ||
| private final RealmContext realmContext; | ||
| private final PolarisConfigurationStore configurationStore; | ||
|
|
||
| public PolarisConfigurationConsumer( | ||
| PolarisCallContext polarisCallContext, PolarisConfigurationStore configurationStore) { | ||
| this.polarisCallContext = polarisCallContext; | ||
| RealmContext realmContext, PolarisConfigurationStore configurationStore) { | ||
| this.realmContext = realmContext; | ||
| this.configurationStore = configurationStore; | ||
| } | ||
|
|
||
| public <T> T consumeConfiguration( | ||
| PolarisConfiguration<Boolean> config, Supplier<T> code, T defaultVal) { | ||
| if (configurationStore.getConfiguration(polarisCallContext, config)) { | ||
| if (configurationStore.getConfiguration(realmContext, config)) { | ||
| return code.get(); | ||
| } | ||
| return defaultVal; | ||
|
|
@@ -127,7 +126,7 @@ public <T> T consumeConfiguration( | |
| @Test | ||
| public void testBehaviorAndFeatureConfigs() { | ||
| PolarisConfigurationConsumer consumer = | ||
| new PolarisConfigurationConsumer(null, new PolarisConfigurationStore() {}); | ||
| new PolarisConfigurationConsumer(testRealmContext, new PolarisConfigurationStore() {}); | ||
|
|
||
| FeatureConfiguration<Boolean> featureConfig = | ||
| PolarisConfiguration.<Boolean>builder() | ||
|
|
@@ -164,22 +163,25 @@ public void testEntityOverrides() { | |
| PolarisConfigurationStore store = | ||
| new PolarisConfigurationStore() { | ||
| @Override | ||
| public <T> @Nullable T getConfiguration(PolarisCallContext ctx, String configName) { | ||
| public <T> @Nullable T getConfiguration(RealmContext realmContext, String configName) { | ||
| //noinspection unchecked | ||
| return (T) Map.of("key2", "config-value2").get(configName); | ||
| } | ||
| }; | ||
|
|
||
| PolarisCallContext ctx = null; | ||
| CatalogEntity entity = | ||
| new CatalogEntity.Builder() | ||
| .addProperty("polaris.config.catalog-key3", "entity-new3") | ||
| .addProperty("legacy-key4", "entity-legacy4") | ||
| .build(); | ||
|
|
||
| Assertions.assertEquals("test-default1", store.getConfiguration(ctx, entity, cfg.apply(1))); | ||
| Assertions.assertEquals("config-value2", store.getConfiguration(ctx, entity, cfg.apply(2))); | ||
| Assertions.assertEquals("entity-new3", store.getConfiguration(ctx, entity, cfg.apply(3))); | ||
| Assertions.assertEquals("entity-legacy4", store.getConfiguration(ctx, entity, cfg.apply(4))); | ||
| Assertions.assertEquals( | ||
| "test-default1", store.getConfiguration(testRealmContext, entity, cfg.apply(1))); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sg! I will update this in my part 2 PR. |
||
| Assertions.assertEquals( | ||
| "config-value2", store.getConfiguration(testRealmContext, entity, cfg.apply(2))); | ||
| Assertions.assertEquals( | ||
| "entity-new3", store.getConfiguration(testRealmContext, entity, cfg.apply(3))); | ||
| Assertions.assertEquals( | ||
| "entity-legacy4", store.getConfiguration(testRealmContext, entity, cfg.apply(4))); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why not keep the old param name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think realmContext is a better parameter name that indicates clearly what the parameter is. "ctx" is very confusing by during the read of code like whether it is for CallContext or PolarisCallContext.