RedisClusterConfig.java

1
package org.cardanofoundation.explorer.api.config.redis.cluster;
2
3
import java.util.Arrays;
4
import java.util.List;
5
6
import lombok.extern.log4j.Log4j2;
7
import lombok.val;
8
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.beans.factory.annotation.Qualifier;
11
import org.springframework.beans.factory.annotation.Value;
12
import org.springframework.cache.annotation.CachingConfigurer;
13
import org.springframework.cache.interceptor.KeyGenerator;
14
import org.springframework.context.annotation.Bean;
15
import org.springframework.context.annotation.Configuration;
16
import org.springframework.context.annotation.Profile;
17
import org.springframework.data.redis.cache.RedisCacheManager;
18
import org.springframework.data.redis.connection.RedisClusterConfiguration;
19
import org.springframework.data.redis.connection.RedisConnectionFactory;
20
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
21
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
22
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
23
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
24
import org.springframework.data.redis.core.RedisTemplate;
25
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
26
import org.springframework.data.redis.serializer.GenericToStringSerializer;
27
import org.springframework.data.redis.serializer.StringRedisSerializer;
28
29
@Log4j2
30
@Configuration
31
@Profile("cluster")
32
public class RedisClusterConfig implements CachingConfigurer {
33
34
  @Value("${spring.redis.cluster.nodes}")
35
  private List<String> nodes;
36
37
  @Value("${spring.redis.password}")
38
  private String password;
39
40
  @Bean
41
  RedisClusterConfiguration redisClusterConfiguration() {
42
    RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(nodes);
43 1 1. redisClusterConfiguration : removed call to org/springframework/data/redis/connection/RedisClusterConfiguration::setPassword → NO_COVERAGE
    redisClusterConfiguration.setPassword(password);
44 1 1. redisClusterConfiguration : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::redisClusterConfiguration → NO_COVERAGE
    return redisClusterConfiguration;
45
  }
46
47
  @Bean(name = "lettuceConnectionFactory")
48
  @Autowired
49
  LettuceConnectionFactory lettuceConnectionFactory(
50
      RedisClusterConfiguration redisClusterConfiguration) {
51
    LettuceClientConfiguration lettuceClientConfiguration =
52
        LettuceClientConfiguration.builder().useSsl().build();
53 1 1. lettuceConnectionFactory : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::lettuceConnectionFactory → NO_COVERAGE
    return new LettuceConnectionFactory(redisClusterConfiguration, lettuceClientConfiguration);
54
  }
55
56
  @Bean
57
  @Autowired
58
  RedisTemplate<String, ?> redisTemplate( // NOSONAR
59
      final LettuceConnectionFactory lettuceConnectionFactory) {
60
    var redisTemplate = new RedisTemplate<String, Object>();
61 1 1. redisTemplate : removed call to org/springframework/data/redis/core/RedisTemplate::setConnectionFactory → NO_COVERAGE
    redisTemplate.setConnectionFactory(lettuceConnectionFactory);
62 1 1. redisTemplate : removed call to org/springframework/data/redis/core/RedisTemplate::setKeySerializer → NO_COVERAGE
    redisTemplate.setKeySerializer(new StringRedisSerializer());
63 1 1. redisTemplate : removed call to org/springframework/data/redis/core/RedisTemplate::setValueSerializer → NO_COVERAGE
    redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
64 1 1. redisTemplate : removed call to org/springframework/data/redis/core/RedisTemplate::setDefaultSerializer → NO_COVERAGE
    redisTemplate.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());
65 1 1. redisTemplate : removed call to org/springframework/data/redis/core/RedisTemplate::setHashValueSerializer → NO_COVERAGE
    redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
66 1 1. redisTemplate : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::redisTemplate → NO_COVERAGE
    return redisTemplate;
67
  }
68
69
  @Bean
70
  @Autowired
71
  RedisTemplate<String, String> redisTemplateString( // NOSONAR // TODO will remove in next version
72
      final LettuceConnectionFactory lettuceConnectionFactory) {
73
    var redisTemplate = new RedisTemplate<String, String>();
74 1 1. redisTemplateString : removed call to org/springframework/data/redis/core/RedisTemplate::setConnectionFactory → NO_COVERAGE
    redisTemplate.setConnectionFactory(lettuceConnectionFactory);
75 1 1. redisTemplateString : removed call to org/springframework/data/redis/core/RedisTemplate::setValueSerializer → NO_COVERAGE
    redisTemplate.setValueSerializer(new GenericToStringSerializer<>(Object.class));
76 1 1. redisTemplateString : removed call to org/springframework/data/redis/core/RedisTemplate::setKeySerializer → NO_COVERAGE
    redisTemplate.setKeySerializer(new StringRedisSerializer());
77 1 1. redisTemplateString : removed call to org/springframework/data/redis/core/RedisTemplate::setDefaultSerializer → NO_COVERAGE
    redisTemplate.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());
78 1 1. redisTemplateString : removed call to org/springframework/data/redis/core/RedisTemplate::setHashValueSerializer → NO_COVERAGE
    redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
79 1 1. redisTemplateString : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::redisTemplateString → NO_COVERAGE
    return redisTemplate;
80
  }
81
82
  @Override
83
  public KeyGenerator keyGenerator() {
84 1 1. keyGenerator : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::keyGenerator → NO_COVERAGE
    return (target, method, params) -> {
85
      val sb = new StringBuilder();
86
      sb.append(target.getClass().getName());
87
      sb.append(method.getName());
88 1 1. lambda$keyGenerator$0 : removed call to java/util/stream/Stream::forEach → NO_COVERAGE
      Arrays.stream(params).sequential().forEach(sb::append);
89
      log.info("call Redis cache Key : " + sb);
90 1 1. lambda$keyGenerator$0 : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::lambda$keyGenerator$0 → NO_COVERAGE
      return sb.toString();
91
    };
92
  }
93
94
  @Bean(name = "jedisConnectionFactory")
95
  @Autowired
96
  JedisConnectionFactory jedisConnectionFactory(
97
      RedisClusterConfiguration redisClusterConfiguration) {
98 1 1. jedisConnectionFactory : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::jedisConnectionFactory → NO_COVERAGE
    return new JedisConnectionFactory(
99
        redisClusterConfiguration, JedisClientConfiguration.builder().useSsl().build());
100
  }
101
102
  @Bean(name = "cacheManager")
103
  public RedisCacheManager cacheManager(
104
      @Qualifier("jedisConnectionFactory") RedisConnectionFactory connectionFactory) {
105 1 1. cacheManager : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::cacheManager → NO_COVERAGE
    return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(connectionFactory)
106
        .build();
107
  }
108
}

Mutations

43

1.1
Location : redisClusterConfiguration
Killed by : none
removed call to org/springframework/data/redis/connection/RedisClusterConfiguration::setPassword → NO_COVERAGE

44

1.1
Location : redisClusterConfiguration
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::redisClusterConfiguration → NO_COVERAGE

53

1.1
Location : lettuceConnectionFactory
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::lettuceConnectionFactory → NO_COVERAGE

61

1.1
Location : redisTemplate
Killed by : none
removed call to org/springframework/data/redis/core/RedisTemplate::setConnectionFactory → NO_COVERAGE

62

1.1
Location : redisTemplate
Killed by : none
removed call to org/springframework/data/redis/core/RedisTemplate::setKeySerializer → NO_COVERAGE

63

1.1
Location : redisTemplate
Killed by : none
removed call to org/springframework/data/redis/core/RedisTemplate::setValueSerializer → NO_COVERAGE

64

1.1
Location : redisTemplate
Killed by : none
removed call to org/springframework/data/redis/core/RedisTemplate::setDefaultSerializer → NO_COVERAGE

65

1.1
Location : redisTemplate
Killed by : none
removed call to org/springframework/data/redis/core/RedisTemplate::setHashValueSerializer → NO_COVERAGE

66

1.1
Location : redisTemplate
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::redisTemplate → NO_COVERAGE

74

1.1
Location : redisTemplateString
Killed by : none
removed call to org/springframework/data/redis/core/RedisTemplate::setConnectionFactory → NO_COVERAGE

75

1.1
Location : redisTemplateString
Killed by : none
removed call to org/springframework/data/redis/core/RedisTemplate::setValueSerializer → NO_COVERAGE

76

1.1
Location : redisTemplateString
Killed by : none
removed call to org/springframework/data/redis/core/RedisTemplate::setKeySerializer → NO_COVERAGE

77

1.1
Location : redisTemplateString
Killed by : none
removed call to org/springframework/data/redis/core/RedisTemplate::setDefaultSerializer → NO_COVERAGE

78

1.1
Location : redisTemplateString
Killed by : none
removed call to org/springframework/data/redis/core/RedisTemplate::setHashValueSerializer → NO_COVERAGE

79

1.1
Location : redisTemplateString
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::redisTemplateString → NO_COVERAGE

84

1.1
Location : keyGenerator
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::keyGenerator → NO_COVERAGE

88

1.1
Location : lambda$keyGenerator$0
Killed by : none
removed call to java/util/stream/Stream::forEach → NO_COVERAGE

90

1.1
Location : lambda$keyGenerator$0
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::lambda$keyGenerator$0 → NO_COVERAGE

98

1.1
Location : jedisConnectionFactory
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::jedisConnectionFactory → NO_COVERAGE

105

1.1
Location : cacheManager
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/redis/cluster/RedisClusterConfig::cacheManager → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.14.2