RedisAggregatedDateCacheServiceImpl.java

1
package org.cardanofoundation.explorer.api.service.impl.cache;
2
3
import java.time.LocalDateTime;
4
import java.time.format.DateTimeFormatter;
5
import java.util.Objects;
6
7
import lombok.RequiredArgsConstructor;
8
import lombok.extern.slf4j.Slf4j;
9
10
import org.springframework.beans.factory.annotation.Value;
11
import org.springframework.data.redis.core.HashOperations;
12
import org.springframework.data.redis.core.RedisTemplate;
13
import org.springframework.stereotype.Service;
14
import org.springframework.util.StringUtils;
15
16
import org.cardanofoundation.explorer.api.common.constant.CommonConstant;
17
import org.cardanofoundation.explorer.api.service.cache.AggregatedDataCacheService;
18
19
@Slf4j
20
@Service
21
@RequiredArgsConstructor
22
public class RedisAggregatedDateCacheServiceImpl implements AggregatedDataCacheService {
23
24
  private static final String AGGREGATED_CACHE_KEY = "AGGREGATED_CACHE";
25
  private static final String BLOCK_TIME_HASH_KEY = "LATEST_BLOCK_TIME";
26
  private static final String TOKEN_COUNT_HASH_KEY = "TOTAL_TOKEN_COUNT";
27
  private static final String BLOCK_INSERT_TIME_HASH_KEY = "LATEST_BLOCK_INSERT_TIME";
28
  private final RedisTemplate<String, String> redisTemplate;
29
30
  private static final DateTimeFormatter DATE_TIME_FORMATTER =
31
      DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
32
33
  @Value("${application.network}")
34
  private String network;
35
36
  @Override
37
  public LocalDateTime getLatestBlockTime() {
38
    String blockTime = getRedisHashValue(BLOCK_TIME_HASH_KEY);
39 1 1. getLatestBlockTime : negated conditional → NO_COVERAGE
    if (Objects.isNull(blockTime)) {
40
      return null;
41
    }
42 1 1. getLatestBlockTime : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/cache/RedisAggregatedDateCacheServiceImpl::getLatestBlockTime → NO_COVERAGE
    return LocalDateTime.parse(blockTime, DATE_TIME_FORMATTER);
43
  }
44
45
  @Override
46
  public LocalDateTime getLatestBlockInsertTime() {
47
    String blockTime = getRedisHashValue(BLOCK_INSERT_TIME_HASH_KEY);
48 1 1. getLatestBlockInsertTime : negated conditional → NO_COVERAGE
    if (Objects.isNull(blockTime)) {
49
      return null;
50
    }
51 1 1. getLatestBlockInsertTime : replaced return value with null for org/cardanofoundation/explorer/api/service/impl/cache/RedisAggregatedDateCacheServiceImpl::getLatestBlockInsertTime → NO_COVERAGE
    return LocalDateTime.parse(blockTime, DATE_TIME_FORMATTER);
52
  }
53
54
  @Override
55
  public int getTokenCount() {
56
    String redisValue = getRedisHashValue(TOKEN_COUNT_HASH_KEY);
57 1 1. getTokenCount : negated conditional → NO_COVERAGE
    return StringUtils.hasText(redisValue) ? Integer.parseInt(redisValue) : 0;
58
  }
59
60
  private String getRedisHashValue(String hashKey) {
61
    HashOperations<String, String, String> hashOperations = redisTemplate.opsForHash();
62
63
    String redisKey = getRedisKey(AGGREGATED_CACHE_KEY);
64 1 1. getRedisHashValue : replaced return value with "" for org/cardanofoundation/explorer/api/service/impl/cache/RedisAggregatedDateCacheServiceImpl::getRedisHashValue → NO_COVERAGE
    return hashOperations.get(redisKey, hashKey);
65
  }
66
67
  private String getRedisKey(String key) {
68 1 1. getRedisKey : replaced return value with "" for org/cardanofoundation/explorer/api/service/impl/cache/RedisAggregatedDateCacheServiceImpl::getRedisKey → NO_COVERAGE
    return String.join(CommonConstant.UNDERSCORE, network.toUpperCase(), key);
69
  }
70
}

Mutations

39

1.1
Location : getLatestBlockTime
Killed by : none
negated conditional → NO_COVERAGE

42

1.1
Location : getLatestBlockTime
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/service/impl/cache/RedisAggregatedDateCacheServiceImpl::getLatestBlockTime → NO_COVERAGE

48

1.1
Location : getLatestBlockInsertTime
Killed by : none
negated conditional → NO_COVERAGE

51

1.1
Location : getLatestBlockInsertTime
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/service/impl/cache/RedisAggregatedDateCacheServiceImpl::getLatestBlockInsertTime → NO_COVERAGE

57

1.1
Location : getTokenCount
Killed by : none
negated conditional → NO_COVERAGE

64

1.1
Location : getRedisHashValue
Killed by : none
replaced return value with "" for org/cardanofoundation/explorer/api/service/impl/cache/RedisAggregatedDateCacheServiceImpl::getRedisHashValue → NO_COVERAGE

68

1.1
Location : getRedisKey
Killed by : none
replaced return value with "" for org/cardanofoundation/explorer/api/service/impl/cache/RedisAggregatedDateCacheServiceImpl::getRedisKey → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.14.2