Copilot commented on code in PR #11310:
URL: https://github.com/apache/gravitino/pull/11310#discussion_r3331551717


##########
core/src/test/java/org/apache/gravitino/cache/TestCaffeineEntityCacheInvalidation.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * 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.gravitino.cache;
+
+import com.google.common.collect.Lists;
+import java.time.Instant;
+import java.util.List;
+import java.util.Optional;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.SupportsRelationOperations;
+import org.apache.gravitino.authorization.AuthorizationUtils;
+import org.apache.gravitino.authorization.Privileges;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.authorization.SecurableObjects;
+import org.apache.gravitino.meta.AuditInfo;
+import org.apache.gravitino.meta.RoleEntity;
+import org.apache.gravitino.storage.RandomIdGenerator;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Unit tests for {@link CaffeineEntityCache} invalidation logic, specifically 
covering the bug
+ * where invalidating a role entity did not propagate to the 
METADATA_OBJECT_ROLE_REL relation cache
+ * entries for the role's securable objects.
+ *
+ * <p>See GitHub issue #11297: {@code listBindingRoleNames} returns stale role 
after {@code
+ * revokePrivilegesFromRole} removes the last privilege.
+ */
+public class TestCaffeineEntityCacheInvalidation {
+
+  private CaffeineEntityCache cache;
+  private AuditInfo auditInfo;
+
+  @BeforeEach
+  void setUp() {
+    Config config = new Config(false) {};
+    cache = new CaffeineEntityCache(config);
+    auditInfo = 
AuditInfo.builder().withCreator("test").withCreateTime(Instant.now()).build();
+  }
+
+  /**
+   * Builds a RoleEntity that has the given schema as its securable object.
+   *
+   * @param metalake the metalake name
+   * @param roleName the role name
+   * @param catalogName the catalog the schema belongs to
+   * @param schemaName the schema name used as the role's securable object
+   * @return the constructed RoleEntity
+   */
+  private RoleEntity buildRoleWithSchemaObject(
+      String metalake, String roleName, String catalogName, String schemaName) 
{
+    SecurableObject catalogObject = SecurableObjects.ofCatalog(catalogName, 
Lists.newArrayList());
+    SecurableObject schemaObject =
+        SecurableObjects.ofSchema(
+            catalogObject, schemaName, 
Lists.newArrayList(Privileges.UseSchema.allow()));
+    return RoleEntity.builder()
+        .withId(RandomIdGenerator.INSTANCE.nextId())
+        .withName(roleName)
+        .withNamespace(AuthorizationUtils.ofRoleNamespace(metalake))
+        .withProperties(null)
+        .withAuditInfo(auditInfo)
+        .withSecurableObjects(Lists.newArrayList(schemaObject))
+        .build();
+  }
+
+  /**
+   * Core scenario reproducing GitHub issue #11297: after caching the 
METADATA_OBJECT_ROLE_REL
+   * relation for a schema, invalidating the role entity must also remove the 
stale relation cache.
+   *
+   * <p>Flow: grant → listBindingRoleNames (caches relation) → revoke 
(invalidates role) →
+   * listBindingRoleNames must miss cache and re-query.
+   */
+  @Test
+  void testRoleInvalidationPropagatestoMetadataObjectRoleRelCache() {

Review Comment:
   Test method name has a typo/inconsistent camel-casing (`Propagatesto`). 
Renaming improves readability and makes it easier to locate the test by intent 
(propagates-to).



-- 
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