From a8b99f5e6f992df2fc16b6f22f37e5d4e1f13def Mon Sep 17 00:00:00 2001 From: Edwin Heuver <139566@student.saxion.nl> Date: Mon, 18 Dec 2023 08:48:34 +0100 Subject: [PATCH] Resolve review comments --- .../DurationChronoUnitValidator.java | 8 ++++++++ .../HazelcastReactiveBucket4jCacheConfiguration.java | 1 + .../HazelcastSpringBucket4jCacheConfiguration.java | 1 + .../cache/ignite/IgniteBucket4jCacheConfiguration.java | 1 + .../infinispan/InfinispanBucket4jCacheConfiguration.java | 1 + .../jcache/InfinispanJCacheBucket4jConfiguration.java | 1 + .../config/cache/jcache/JCacheBucket4jConfiguration.java | 1 + .../cache/redis/jedis/JedisBucket4jConfiguration.java | 1 + .../cache/redis/lettuce/LettuceBucket4jConfiguration.java | 1 + .../redis/redisson/RedissonBucket4jConfiguration.java | 1 + 10 files changed, 17 insertions(+) diff --git a/bucket4j-spring-boot-starter-context/src/main/java/com/giffing/bucket4j/spring/boot/starter/context/constraintvalidations/DurationChronoUnitValidator.java b/bucket4j-spring-boot-starter-context/src/main/java/com/giffing/bucket4j/spring/boot/starter/context/constraintvalidations/DurationChronoUnitValidator.java index e9c3f0b0..1ad27c1b 100644 --- a/bucket4j-spring-boot-starter-context/src/main/java/com/giffing/bucket4j/spring/boot/starter/context/constraintvalidations/DurationChronoUnitValidator.java +++ b/bucket4j-spring-boot-starter-context/src/main/java/com/giffing/bucket4j/spring/boot/starter/context/constraintvalidations/DurationChronoUnitValidator.java @@ -5,6 +5,14 @@ import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; +/** + * This validator is used to check if a ChronoUnit is accepted by the Duration.of() method. + * + * The Duration.of() method does not allow estimated time units, but DAYS is an exception to this rule. + * ChronoUnit treats Days as estimated values because of daylight savings, while Duration.of() treats it + * as an exact value of 24 hours. For this reason the validator also allows Days as valid value. + * + */ public class DurationChronoUnitValidator implements ConstraintValidator { @Override diff --git a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/hazelcast/HazelcastReactiveBucket4jCacheConfiguration.java b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/hazelcast/HazelcastReactiveBucket4jCacheConfiguration.java index 77b5280f..f86e65f8 100644 --- a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/hazelcast/HazelcastReactiveBucket4jCacheConfiguration.java +++ b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/hazelcast/HazelcastReactiveBucket4jCacheConfiguration.java @@ -42,6 +42,7 @@ public AsyncCacheResolver hazelcastCacheResolver() { } @Bean + @ConditionalOnMissingBean(CacheManager.class) @ConditionalOnProperty(prefix = Bucket4JBootProperties.PROPERTY_PREFIX, name = "filter-config-caching-enabled", havingValue = "true", matchIfMissing = true) public CacheManager configCacheManager() { IMap map = hazelcastInstance.getMap(configCacheName); diff --git a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/hazelcast/HazelcastSpringBucket4jCacheConfiguration.java b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/hazelcast/HazelcastSpringBucket4jCacheConfiguration.java index ac6c2610..212a4002 100644 --- a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/hazelcast/HazelcastSpringBucket4jCacheConfiguration.java +++ b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/hazelcast/HazelcastSpringBucket4jCacheConfiguration.java @@ -43,6 +43,7 @@ public AsyncCacheResolver hazelcastCacheResolver() { } @Bean + @ConditionalOnMissingBean(CacheManager.class) @ConditionalOnProperty(prefix = Bucket4JBootProperties.PROPERTY_PREFIX, name = "filter-config-caching-enabled", havingValue = "true", matchIfMissing = true) public CacheManager configCacheManager() { IMap map = hazelcastInstance.getMap(configCacheName); diff --git a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/ignite/IgniteBucket4jCacheConfiguration.java b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/ignite/IgniteBucket4jCacheConfiguration.java index 0bf7b8fc..836388c2 100644 --- a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/ignite/IgniteBucket4jCacheConfiguration.java +++ b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/ignite/IgniteBucket4jCacheConfiguration.java @@ -34,6 +34,7 @@ public AsyncCacheResolver hazelcastCacheResolver() { } @Bean + @ConditionalOnMissingBean(CacheManager.class) @ConditionalOnProperty(prefix = Bucket4JBootProperties.PROPERTY_PREFIX, name = "filter-config-caching-enabled", havingValue = "true", matchIfMissing = true) public CacheManager configCacheManager() { return new IgniteCacheManager<>(ignite.cache(configCacheName)); diff --git a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/infinispan/InfinispanBucket4jCacheConfiguration.java b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/infinispan/InfinispanBucket4jCacheConfiguration.java index efd36418..b2df486e 100644 --- a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/infinispan/InfinispanBucket4jCacheConfiguration.java +++ b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/infinispan/InfinispanBucket4jCacheConfiguration.java @@ -34,6 +34,7 @@ public AsyncCacheResolver infinispanCacheResolver() { } @Bean + @ConditionalOnMissingBean(CacheManager.class) @ConditionalOnProperty(prefix = Bucket4JBootProperties.PROPERTY_PREFIX, name = "filter-config-caching-enabled", havingValue = "true", matchIfMissing = true) public CacheManager configCacheManager() { return new InfinispanCacheManager<>(cacheContainer.getCache(configCacheName)); diff --git a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/jcache/InfinispanJCacheBucket4jConfiguration.java b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/jcache/InfinispanJCacheBucket4jConfiguration.java index 3e1fd225..5a3d61c0 100644 --- a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/jcache/InfinispanJCacheBucket4jConfiguration.java +++ b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/jcache/InfinispanJCacheBucket4jConfiguration.java @@ -44,6 +44,7 @@ public SyncCacheResolver bucket4jCacheResolver() { } @Bean + @ConditionalOnMissingBean(CacheManager.class) @ConditionalOnProperty(prefix = Bucket4JBootProperties.PROPERTY_PREFIX, name = "filter-config-caching-enabled", havingValue = "true", matchIfMissing = true) public CacheManager configCacheManager() { return new InfinispanCacheManager<>(cacheContainer.getCache(configCacheName)); diff --git a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/jcache/JCacheBucket4jConfiguration.java b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/jcache/JCacheBucket4jConfiguration.java index d53fc209..c88f6b70 100644 --- a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/jcache/JCacheBucket4jConfiguration.java +++ b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/jcache/JCacheBucket4jConfiguration.java @@ -35,6 +35,7 @@ public SyncCacheResolver bucket4jCacheResolver() { } @Bean + @ConditionalOnMissingBean(com.giffing.bucket4j.spring.boot.starter.config.cache.CacheManager.class) @ConditionalOnProperty(prefix = Bucket4JBootProperties.PROPERTY_PREFIX, name = "filter-config-caching-enabled", havingValue = "true", matchIfMissing = true) public com.giffing.bucket4j.spring.boot.starter.config.cache.CacheManager configCacheManager( ) { diff --git a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/jedis/JedisBucket4jConfiguration.java b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/jedis/JedisBucket4jConfiguration.java index 1c8c2f89..086900dc 100644 --- a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/jedis/JedisBucket4jConfiguration.java +++ b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/jedis/JedisBucket4jConfiguration.java @@ -33,6 +33,7 @@ public SyncCacheResolver bucket4RedisResolver() { } @Bean + @ConditionalOnMissingBean(CacheManager.class) @ConditionalOnProperty(prefix = Bucket4JBootProperties.PROPERTY_PREFIX, name = "filter-config-caching-enabled", havingValue = "true", matchIfMissing = true) public CacheManager configCacheManager() { return new JedisCacheManager<>(jedisPool, configCacheName, Bucket4JConfiguration.class); diff --git a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/lettuce/LettuceBucket4jConfiguration.java b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/lettuce/LettuceBucket4jConfiguration.java index cca73daa..aa381702 100644 --- a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/lettuce/LettuceBucket4jConfiguration.java +++ b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/lettuce/LettuceBucket4jConfiguration.java @@ -32,6 +32,7 @@ public AsyncCacheResolver bucket4RedisResolver() { } @Bean + @ConditionalOnMissingBean(CacheManager.class) @ConditionalOnProperty(prefix = Bucket4JBootProperties.PROPERTY_PREFIX, name = "filter-config-caching-enabled", havingValue = "true", matchIfMissing = true) public CacheManager configCacheManager() { return new LettuceCacheManager<>(redisClient, configCacheName, Bucket4JConfiguration.class); diff --git a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/redisson/RedissonBucket4jConfiguration.java b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/redisson/RedissonBucket4jConfiguration.java index ca13c9e3..7d2480e7 100644 --- a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/redisson/RedissonBucket4jConfiguration.java +++ b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/cache/redis/redisson/RedissonBucket4jConfiguration.java @@ -43,6 +43,7 @@ public AsyncCacheResolver bucket4RedisResolver() { } @Bean + @ConditionalOnMissingBean(CacheManager.class) @ConditionalOnProperty(prefix = Bucket4JBootProperties.PROPERTY_PREFIX, name = "filter-config-caching-enabled", havingValue = "true", matchIfMissing = true) public CacheManager configCacheManager() { return new RedissonCacheManager<>(this.redissonClient, configCacheName);