flyingImer commented on code in PR #3896:
URL: https://github.com/apache/polaris/pull/3896#discussion_r2887836690


##########
polaris-core/src/main/java/org/apache/polaris/core/policy/PolicyType.java:
##########
@@ -31,6 +34,39 @@
  */
 public interface PolicyType {
 
+  /**
+   * Registry for custom policy types. This allows tests to register 
non-predefined policy types
+   * that can be resolved via {@link #fromCode(int)} and {@link 
#fromName(String)}.
+   */
+  Map<Integer, PolicyType> CUSTOM_POLICY_TYPE_REGISTRY = new 
ConcurrentHashMap<>();

Review Comment:
   This is an awkward impl IMO, `CUSTOM_POLICY_TYPE_REGISTRY` is a mutable 
`public static` field on PolicyType, i.e., any code can mutate it. Leaks 
implementation detail into a public contract.
   
   2 cents: I feel a dedicated `PolicyTypeRegistry` can properly separate the 
duty, i.e., `PolicyType` will sit on top of `PredefinedPolicyTypes` and 
`PolicyTypeRegistry`, `PolicyTypeRegistry` is a fallback



##########
runtime/service/src/test/java/org/apache/polaris/service/catalog/policy/PolicyCatalogEffectivePoliciesTest.java:
##########
@@ -0,0 +1,375 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.service.catalog.policy;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Stream;
+import org.apache.polaris.core.policy.PolicyType;
+import org.apache.polaris.core.policy.PredefinedPolicyTypes;
+import org.apache.polaris.core.policy.TestNonInheritablePolicyType;
+import org.junit.jupiter.api.Test;
+
+/** Unit tests for the effective policies calculation logic in PolicyCatalog. 
*/
+class PolicyCatalogEffectivePoliciesTest {
+
+  /** Simplified policy record for testing the algorithm. */
+  private record TestPolicy(String name, PolicyType policyType, long id) {}
+
+  /** Result record for applicable policy. */
+  private record ApplicablePolicyResult(String name, PolicyType policyType, 
boolean inherited) {}
+
+  /** Extracted algorithm from PolicyCatalog.getEffectivePolicies() for unit 
testing. */
+  private List<ApplicablePolicyResult> getEffectivePolicies(

Review Comment:
   why not just extracting the logic from 
`PolicyCatalog.getEffectivePolicies()` into a package private method called 
something like `resolveEffectivePolicies` for unit testing? so that we can 
avoid discrepancy 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to