jerryshao commented on code in PR #7414:
URL: https://github.com/apache/gravitino/pull/7414#discussion_r2155011148


##########
jcstress-tests/src/jcstress/java/org/apache/gravitino/cache/TestCaffeineEntityCacheCoherence.java:
##########
@@ -0,0 +1,530 @@
+/*
+ * 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 static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+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.Namespace;
+import org.apache.gravitino.SupportsRelationOperations;
+import org.apache.gravitino.meta.AuditInfo;
+import org.apache.gravitino.meta.ColumnEntity;
+import org.apache.gravitino.meta.GroupEntity;
+import org.apache.gravitino.meta.RoleEntity;
+import org.apache.gravitino.meta.SchemaEntity;
+import org.apache.gravitino.meta.TableEntity;
+import org.apache.gravitino.meta.UserEntity;
+import org.apache.gravitino.rel.types.Types;
+import org.apache.gravitino.utils.NamespaceUtil;
+import org.openjdk.jcstress.annotations.Actor;
+import org.openjdk.jcstress.annotations.Arbiter;
+import org.openjdk.jcstress.annotations.Description;
+import org.openjdk.jcstress.annotations.Expect;
+import org.openjdk.jcstress.annotations.JCStressTest;
+import org.openjdk.jcstress.annotations.Outcome;
+import org.openjdk.jcstress.annotations.State;
+import org.openjdk.jcstress.infra.results.I_Result;
+import org.openjdk.jcstress.infra.results.L_Result;
+
+public class TestCaffeineEntityCacheCoherence {
+  private static final SchemaEntity schemaEntity =
+      getTestSchemaEntity(1L, "schema1", Namespace.of("metalake1", 
"catalog1"), "test_schema1");
+  private static final TableEntity tableEntity =
+      getTestTableEntity(3L, "table1", Namespace.of("metalake1", "catalog1", 
"schema1"));
+  private static final GroupEntity groupEntity =
+      getTestGroupEntity(4L, "group1", "metalake1", ImmutableList.of("role1"));
+  private static final UserEntity userEntity =
+      getTestUserEntity(5L, "user1", "metalake1", ImmutableList.of(6L));
+  private static final RoleEntity roleEntity = getTestRoleEntity(6L, "role1", 
"metalake1");
+
+  private static SchemaEntity getTestSchemaEntity(
+      long id, String name, Namespace namespace, String comment) {
+    return SchemaEntity.builder()
+        .withId(id)
+        .withName(name)
+        .withNamespace(namespace)
+        .withAuditInfo(getTestAuditInfo())
+        .withComment(comment)
+        .withProperties(ImmutableMap.of())
+        .build();
+  }
+
+  private static TableEntity getTestTableEntity(long id, String name, 
Namespace namespace) {
+    return TableEntity.builder()
+        .withId(id)
+        .withName(name)
+        .withAuditInfo(getTestAuditInfo())
+        .withNamespace(namespace)
+        .withColumns(ImmutableList.of(getMockColumnEntity()))
+        .build();
+  }
+
+  private static RoleEntity getTestRoleEntity(long id, String name, String 
metalake) {
+    return RoleEntity.builder()
+        .withId(id)
+        .withName(name)
+        .withNamespace(NamespaceUtil.ofRole(metalake))
+        .withAuditInfo(getTestAuditInfo())
+        .withSecurableObjects(ImmutableList.of())
+        .build();
+  }
+
+  private static GroupEntity getTestGroupEntity(
+      long id, String name, String metalake, List<String> roles) {
+    return GroupEntity.builder()
+        .withId(id)
+        .withName(name)
+        .withNamespace(NamespaceUtil.ofGroup(metalake))
+        .withAuditInfo(getTestAuditInfo())
+        .withRoleNames(roles)
+        .build();
+  }
+
+  private static UserEntity getTestUserEntity(
+      long id, String name, String metalake, List<Long> roles) {
+    return UserEntity.builder()
+        .withId(id)
+        .withName(name)
+        .withNamespace(NamespaceUtil.ofUser(metalake))
+        .withAuditInfo(getTestAuditInfo())
+        .withRoleIds(roles)
+        .build();
+  }
+
+  private static AuditInfo getTestAuditInfo() {
+    return AuditInfo.builder()
+        .withCreator("admin")
+        .withCreateTime(Instant.now())
+        .withLastModifier("admin")
+        .withLastModifiedTime(Instant.now())
+        .build();
+  }
+
+  private static ColumnEntity getMockColumnEntity() {
+    ColumnEntity mockColumn = mock(ColumnEntity.class);
+    when(mockColumn.name()).thenReturn("filed1");
+    when(mockColumn.dataType()).thenReturn(Types.StringType.get());
+    when(mockColumn.nullable()).thenReturn(false);
+    when(mockColumn.auditInfo()).thenReturn(getTestAuditInfo());
+
+    return mockColumn;
+  }
+
+  @JCStressTest
+  @Outcome.Outcomes({
+    @Outcome(id = "ENTITY", expect = Expect.ACCEPTABLE, desc = "getIfPresent 
observed the entity."),
+    @Outcome(
+        id = "NULL",
+        expect = Expect.FORBIDDEN,
+        desc = "getIfPresent did not observe entity, which violates visibility 
guarantees.")
+  })
+  @Description(
+      "Tests visibility between put() and getIfPresent() on an existing 
entity. "
+          + "Entity should remain visible; NULL indicates broken visibility or 
invalidation.")
+  @State
+  public static class PutVsGetIfPresentTest {

Review Comment:
   Can we change the name to `PutWithGetIfPresentTest`? Replacing `Vs` to 
`With`.



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