Skip to content

Commit

Permalink
prepare next release; SonarLint; organize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcGiffing committed Jan 16, 2024
1 parent 9577231 commit b6b61df
Show file tree
Hide file tree
Showing 30 changed files with 103 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import com.hazelcast.core.EntryEvent;
import com.hazelcast.map.IMap;
import com.hazelcast.map.listener.EntryUpdatedListener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;

/**
* This class is intended to be used as bean.
*
* <p>
* It will listen to changes in the cache, parse them to a CacheUpdateEvent<K, V>
* and publish the event to the Spring ApplicationEventPublisher.
*
Expand All @@ -20,17 +18,17 @@
*/
public class HazelcastCacheListener<K, V> implements EntryUpdatedListener<K, V> {

@Autowired
private ApplicationEventPublisher eventPublisher;
@Autowired
private ApplicationEventPublisher eventPublisher;

public HazelcastCacheListener(IMap<K, V> map){
map.addEntryListener(this, true);
}
public HazelcastCacheListener(IMap<K, V> map) {
map.addEntryListener(this, true);
}

@Override
public void entryUpdated(EntryEvent<K, V> entryEvent) {
CacheUpdateEvent<K, V> updateEvent = new CacheUpdateEvent<>(entryEvent.getKey(), entryEvent.getOldValue(), entryEvent.getValue());
eventPublisher.publishEvent(updateEvent);
}
@Override
public void entryUpdated(EntryEvent<K, V> entryEvent) {
CacheUpdateEvent<K, V> updateEvent = new CacheUpdateEvent<>(entryEvent.getKey(), entryEvent.getOldValue(), entryEvent.getValue());
eventPublisher.publishEvent(updateEvent);
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.giffing.bucket4j.spring.boot.starter.config.cache.hazelcast;

import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.giffing.bucket4j.spring.boot.starter.config.cache.AsyncCacheResolver;
import com.giffing.bucket4j.spring.boot.starter.config.cache.CacheManager;
import com.giffing.bucket4j.spring.boot.starter.config.cache.jcache.JCacheBucket4jConfiguration;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JBootProperties;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configures the asynchronous support for Hazelcast. The synchronous support of Hazelcast
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.giffing.bucket4j.spring.boot.starter.config.cache.hazelcast;

import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.giffing.bucket4j.spring.boot.starter.config.cache.AsyncCacheResolver;
import com.giffing.bucket4j.spring.boot.starter.config.cache.CacheManager;
import com.giffing.bucket4j.spring.boot.starter.config.cache.SyncCacheResolver;
import com.giffing.bucket4j.spring.boot.starter.config.cache.jcache.JCacheBucket4jConfiguration;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JBootProperties;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import com.hazelcast.spring.cache.HazelcastCacheManager;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configures the asynchronous support for Hazelcast. The synchronous support of Hazelcast
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.giffing.bucket4j.spring.boot.starter.config.cache.ignite;

import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.giffing.bucket4j.spring.boot.starter.config.cache.AsyncCacheResolver;
import com.giffing.bucket4j.spring.boot.starter.config.cache.CacheManager;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JBootProperties;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration;

import org.apache.ignite.Ignite;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.giffing.bucket4j.spring.boot.starter.config.cache.infinispan;

import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.giffing.bucket4j.spring.boot.starter.config.cache.AsyncCacheResolver;
import com.giffing.bucket4j.spring.boot.starter.config.cache.CacheManager;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JBootProperties;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration;

import org.infinispan.manager.CacheContainer;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration;
import io.github.bucket4j.redis.jedis.cas.JedisBasedProxyManager.JedisBasedProxyManagerBuilder;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.github.bucket4j.redis.lettuce.cas.LettuceBasedProxyManager;
import io.lettuce.core.RedisClient;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.redisson.command.CommandAsyncExecutor;
import org.redisson.config.Config;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import com.giffing.bucket4j.spring.boot.starter.config.cache.CacheUpdateEvent;
import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;

/**
* This class is intended to be used as bean.
*
* <p>
* It will listen to Redisson events on the {cacheName}:update channel
* and publish these to the Spring ApplicationEventPublisher as CacheUpdateEvent<K, V>
*
Expand All @@ -19,15 +17,15 @@
*/
public class RedissonCacheListener<K, V> {

@Autowired
private ApplicationEventPublisher eventPublisher;
@Autowired
private ApplicationEventPublisher eventPublisher;

public RedissonCacheListener(RedissonClient redisson, String cacheName) {
RTopic pubSubTopic = redisson.getTopic(cacheName);
pubSubTopic.addListener(CacheUpdateEvent.class, this::onCacheUpdateEvent);
}
public RedissonCacheListener(RedissonClient redisson, String cacheName) {
RTopic pubSubTopic = redisson.getTopic(cacheName);
pubSubTopic.addListener(CacheUpdateEvent.class, this::onCacheUpdateEvent);
}

public void onCacheUpdateEvent(CharSequence channel, CacheUpdateEvent<K, V> event) {
eventPublisher.publishEvent(event);
}
public void onCacheUpdateEvent(CharSequence channel, CacheUpdateEvent<K, V> event) {
eventPublisher.publishEvent(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import java.util.Objects;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Bucket4JUtils {

public static ResponseEntity<String> validateConfigurationUpdate(Bucket4JConfiguration oldConfig, Bucket4JConfiguration newConfig){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package com.giffing.bucket4j.spring.boot.starter.config.filter;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collections;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.giffing.bucket4j.spring.boot.starter.context.properties.BandWidth;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration;
import com.giffing.bucket4j.spring.boot.starter.context.properties.RateLimit;

import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.bucket4j.Bandwidth;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.Mockito;

import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;


public class Bucket4JConfigurationTest {
Expand All @@ -41,33 +35,33 @@ public void setup() {
}

@Test
public void setFilterIdTest() {
void setFilterIdTest() {
config.setId("id");
assert(config.getId().equals("id"));
validator.validateProperty(config, "id"); //validate that autoconfigure allows string values
}
@Test
public void setFilterIdWithSpacesTest() {
void setFilterIdWithSpacesTest() {
config.setId(" id ");
assert(config.getId().equals("id"));
validator.validateProperty(config, "id"); //validate that autoconfigure allows string values
}

@Test
public void setFilterIdNullTest() {
void setFilterIdNullTest() {
config.setId(null);
assert (config.getId() == null);
validator.validateProperty(config, "id"); //validate that autoconfigure allows null values
}

@Test
public void setFilterIdEmptyStringTest(){
void setFilterIdEmptyStringTest(){
config.setId("");
assert (config.getId() == null);
}

@Test
public void setFilterIdSpacesTest(){
void setFilterIdSpacesTest(){
config.setId(" ");
assert (config.getId() == null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import io.github.bucket4j.TokensInheritanceStrategy;

public class RateLimitBandWidthIdTest {
class RateLimitBandWidthIdTest {

final RateLimitBandWidthIdsValidator validator = new RateLimitBandWidthIdsValidator();
ConstraintValidatorContext context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.giffing.bucket4j.spring.boot.starter.examples.caffeine;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import com.giffing.bucket4j.spring.boot.starter.context.ExecutePredicate;

import jakarta.servlet.http.HttpServletRequest;

@Component
@Slf4j
public class CustomQueryExecutePredicate extends ExecutePredicate<HttpServletRequest> {

private String query;

@Override
public boolean test(HttpServletRequest t) {
boolean result = t.getParameterMap().containsKey(query);
System.out.println("query-parametetr;value:%s;result:%s".formatted(query, result));
log.info("query-parametetr;value:%s;result:%s".formatted(query, result));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import java.util.List;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import com.giffing.bucket4j.spring.boot.starter.context.metrics.MetricHandler;
import com.giffing.bucket4j.spring.boot.starter.context.metrics.MetricTagResult;
import com.giffing.bucket4j.spring.boot.starter.context.metrics.MetricType;

@Component
@Slf4j
public class DebugMetricHandler implements MetricHandler {

@Override
public void handle(MetricType type, String name, long tokens, List<MetricTagResult> tags) {
System.out.println(String.format("type: %s; name: %s; tags: %s; tokens: %s",
log.info(String.format("type: %s; name: %s; tags: %s; tokens: %s",
type,
name,
tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
import java.util.List;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import com.giffing.bucket4j.spring.boot.starter.context.metrics.MetricHandler;
import com.giffing.bucket4j.spring.boot.starter.context.metrics.MetricTagResult;
import com.giffing.bucket4j.spring.boot.starter.context.metrics.MetricType;

@Component

@Slf4j
public class DebugMetricHandler implements MetricHandler {

@Override
public void handle(MetricType type, String name, long tokens, List<MetricTagResult> tags) {
System.out.println(String.format("type: %s; name: %s; tags: %s",
log.info(String.format("type: %s; name: %s; tags: %s",
type,
name,
tags
Expand Down
4 changes: 4 additions & 0 deletions examples/gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<groupId>com.bucket4j</groupId>
<artifactId>bucket4j-hazelcast</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down
Loading

0 comments on commit b6b61df

Please sign in to comment.