dimas-b commented on code in PR #1959:
URL: https://github.com/apache/polaris/pull/1959#discussion_r2180955338


##########
polaris-core/src/test/java/org/apache/polaris/service/storage/PolarisConfigurationStoreTest.java:
##########
@@ -186,4 +185,104 @@ public void testEntityOverrides() {
     Assertions.assertEquals(
         "entity-legacy4", store.getConfiguration(testRealmContext, entity, 
cfg.apply(4)));
   }
+
+  @Test
+  public void testLegacyKeyLookup() {
+    FeatureConfiguration<String> config =
+        PolarisConfiguration.<String>builder()
+            .key("LEGACY_KEY_TEST_NEW_KEY")
+            .legacyKey("LEGACY_TEST_OLD_KEY_1")
+            .legacyKey("LEGACY_TEST_OLD_KEY_2")
+            .description("Test config with legacy keys")
+            .defaultValue("default-value")
+            .buildFeatureConfiguration();
+
+    PolarisConfigurationStore store =
+        new PolarisConfigurationStore() {
+          @SuppressWarnings("unchecked")
+          @Override
+          public <T> T getConfiguration(@Nonnull RealmContext ctx, String 
configName) {
+            Map<String, String> values = Map.of("LEGACY_TEST_OLD_KEY_1", 
"legacy-value-1");
+            return (T) values.get(configName);
+          }
+        };
+
+    String result = store.getConfiguration(testRealmContext, config);
+    Assertions.assertEquals("legacy-value-1", result);
+  }
+
+  @Test
+  public void testMainKeyTakesPrecedenceOverLegacyKeys() {
+    FeatureConfiguration<String> config =
+        PolarisConfiguration.<String>builder()
+            .key("PRECEDENCE_TEST_NEW_KEY")
+            .legacyKey("PRECEDENCE_TEST_OLD_KEY")
+            .description("Test config with legacy keys")
+            .defaultValue("default-value")
+            .buildFeatureConfiguration();
+
+    PolarisConfigurationStore store =
+        new PolarisConfigurationStore() {
+          @SuppressWarnings("unchecked")
+          @Override
+          public <T> T getConfiguration(@Nonnull RealmContext ctx, String 
configName) {
+            Map<String, String> values =
+                Map.of(
+                    "PRECEDENCE_TEST_NEW_KEY", "new-value",
+                    "PRECEDENCE_TEST_OLD_KEY", "legacy-value");
+            return (T) values.get(configName);
+          }
+        };
+
+    String result = store.getConfiguration(testRealmContext, config);
+    Assertions.assertEquals("new-value", result);
+  }
+
+  @Test
+  public void testFallbackToDefaultWhenNoKeysFound() {
+    FeatureConfiguration<String> config =
+        PolarisConfiguration.<String>builder()
+            .key("FALLBACK_TEST_NEW_KEY")
+            .legacyKey("FALLBACK_TEST_OLD_KEY")
+            .description("Test config with legacy keys")
+            .defaultValue("default-value")
+            .buildFeatureConfiguration();
+
+    PolarisConfigurationStore store =
+        new PolarisConfigurationStore() {
+          @Override
+          public <T> T getConfiguration(@Nonnull RealmContext ctx, String 
configName) {
+            return null;
+          }
+        };
+
+    String result = store.getConfiguration(testRealmContext, config);
+    Assertions.assertEquals("default-value", result);
+  }
+
+  @Test
+  public void testLegacyKeyWarningIsLogged() {

Review Comment:
   I'd be ok without this test too :)



##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -41,6 +43,7 @@ public abstract class PolarisConfiguration<T> {
 
   public final String key;
   public final String description;
+  public final Set<String> legacyKeys;

Review Comment:
   Sorry, I did not notice this before, but I think having `public` fiends in 
general is not a good idea. Since you're toughing this code in current PR, 
would you mind following up with another PR to convert them to `private` fields?



##########
polaris-core/src/test/java/org/apache/polaris/service/storage/PolarisConfigurationStoreTest.java:
##########
@@ -186,4 +185,104 @@ public void testEntityOverrides() {
     Assertions.assertEquals(
         "entity-legacy4", store.getConfiguration(testRealmContext, entity, 
cfg.apply(4)));
   }
+
+  @Test
+  public void testLegacyKeyLookup() {
+    FeatureConfiguration<String> config =
+        PolarisConfiguration.<String>builder()
+            .key("LEGACY_KEY_TEST_NEW_KEY")
+            .legacyKey("LEGACY_TEST_OLD_KEY_1")
+            .legacyKey("LEGACY_TEST_OLD_KEY_2")
+            .description("Test config with legacy keys")
+            .defaultValue("default-value")
+            .buildFeatureConfiguration();
+
+    PolarisConfigurationStore store =
+        new PolarisConfigurationStore() {
+          @SuppressWarnings("unchecked")
+          @Override
+          public <T> T getConfiguration(@Nonnull RealmContext ctx, String 
configName) {
+            Map<String, String> values = Map.of("LEGACY_TEST_OLD_KEY_1", 
"legacy-value-1");
+            return (T) values.get(configName);
+          }
+        };
+
+    String result = store.getConfiguration(testRealmContext, config);
+    Assertions.assertEquals("legacy-value-1", result);
+  }
+
+  @Test
+  public void testMainKeyTakesPrecedenceOverLegacyKeys() {
+    FeatureConfiguration<String> config =
+        PolarisConfiguration.<String>builder()
+            .key("PRECEDENCE_TEST_NEW_KEY")
+            .legacyKey("PRECEDENCE_TEST_OLD_KEY")
+            .description("Test config with legacy keys")
+            .defaultValue("default-value")
+            .buildFeatureConfiguration();
+
+    PolarisConfigurationStore store =
+        new PolarisConfigurationStore() {
+          @SuppressWarnings("unchecked")
+          @Override
+          public <T> T getConfiguration(@Nonnull RealmContext ctx, String 
configName) {
+            Map<String, String> values =
+                Map.of(
+                    "PRECEDENCE_TEST_NEW_KEY", "new-value",
+                    "PRECEDENCE_TEST_OLD_KEY", "legacy-value");
+            return (T) values.get(configName);
+          }
+        };
+
+    String result = store.getConfiguration(testRealmContext, config);
+    Assertions.assertEquals("new-value", result);
+  }
+
+  @Test
+  public void testFallbackToDefaultWhenNoKeysFound() {
+    FeatureConfiguration<String> config =
+        PolarisConfiguration.<String>builder()
+            .key("FALLBACK_TEST_NEW_KEY")
+            .legacyKey("FALLBACK_TEST_OLD_KEY")
+            .description("Test config with legacy keys")
+            .defaultValue("default-value")
+            .buildFeatureConfiguration();
+
+    PolarisConfigurationStore store =
+        new PolarisConfigurationStore() {
+          @Override
+          public <T> T getConfiguration(@Nonnull RealmContext ctx, String 
configName) {
+            return null;
+          }
+        };
+
+    String result = store.getConfiguration(testRealmContext, config);
+    Assertions.assertEquals("default-value", result);
+  }
+
+  @Test
+  public void testLegacyKeyWarningIsLogged() {

Review Comment:
   How does this test ensure the warning is logged?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@polaris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to