jerryshao commented on code in PR #8698:
URL: https://github.com/apache/gravitino/pull/8698#discussion_r2386794215
##########
core/src/test/java/org/apache/gravitino/cache/TestCacheConfig.java:
##########
@@ -33,10 +45,81 @@ void testDefaultCacheConfig() {
Assertions.assertTrue(config.get(Configs.CACHE_WEIGHER_ENABLED));
Assertions.assertEquals(10_000, config.get(Configs.CACHE_MAX_ENTRIES));
Assertions.assertEquals(3_600_000L,
config.get(Configs.CACHE_EXPIRATION_TIME));
- Assertions.assertEquals(200_302_000L, EntityCacheWeigher.getMaxWeight());
+ Assertions.assertEquals(40_000_000L, EntityCacheWeigher.getMaxWeight());
Assertions.assertEquals("caffeine",
config.get(Configs.CACHE_IMPLEMENTATION));
}
+ @Test
+ void testCaffeineCacheWithWeight() throws Exception {
+ Caffeine<Object, Object> builder = Caffeine.newBuilder();
+ builder.maximumWeight(500);
+ builder.weigher(EntityCacheWeigher.getInstance());
+ Cache<EntityCacheRelationKey, List<Entity>> cache = builder.build();
+
+ // Insert 3 metalakes
+ for (int i = 0; i < 3; i++) {
+ BaseMetalake baseMetalake =
+ BaseMetalake.builder()
+ .withName("metalake" + 1)
+ .withId((long) i)
+ .withVersion(SchemaVersion.V_0_1)
+ .withAuditInfo(AuditInfo.EMPTY)
+ .build();
+ cache.put(
+ EntityCacheRelationKey.of(NameIdentifier.of("metalake" + i),
Entity.EntityType.METALAKE),
+ List.of(baseMetalake));
+ }
+
+ // Insert 10 catalogs
+ for (int i = 0; i < 10; i++) {
+ CatalogEntity catalogEntity =
+ CatalogEntity.builder()
+ .withNamespace(Namespace.of("metalake1"))
+ .withName("catalog" + i)
+ .withProvider("provider")
+ .withAuditInfo(AuditInfo.EMPTY)
+ .withId((long) ((i + 1) * 100))
+ .withType(Catalog.Type.RELATIONAL)
+ .build();
+ cache.put(
+ EntityCacheRelationKey.of(
+ NameIdentifier.of("metalake1.catalog" + i),
Entity.EntityType.CATALOG),
+ List.of(catalogEntity));
+ }
+
+ // insert 100 schemas
+ for (int i = 0; i < 100; i++) {
+ SchemaEntity schemaEntity =
+ SchemaEntity.builder()
+ .withNamespace(Namespace.of("metalake1", "catalog1"))
+ .withName("schema" + i)
+ .withAuditInfo(AuditInfo.EMPTY)
+ .withId((long) ((i + 1) * 1000))
+ .build();
+
+ cache.put(
+ EntityCacheRelationKey.of(
+ NameIdentifier.of("metalake1.catalog1.schema" + i),
Entity.EntityType.SCHEMA),
+ List.of(schemaEntity));
+ }
+
+ Thread.sleep(100);
Review Comment:
Using awaitibility, please avoid using `sleep` directly.
--
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]