From 939301d5023ec9f0fa18194407f55a32bd613c8a Mon Sep 17 00:00:00 2001 From: Sotatek-ThinhVu Date: Tue, 30 Jan 2024 11:02:48 +0700 Subject: [PATCH 1/4] refactor: adapt code formatter for rewards service --- pom.xml | 35 ++++ .../AdaPostsConcurrentFetching.java | 32 ++-- .../concurrent/EpochConcurrentFetching.java | 40 +++-- .../EpochStakeConcurrentFetching.java | 30 ++-- .../PoolHistoryConcurrentFetching.java | 30 ++-- .../PoolInfoConcurrentFetching.java | 21 +-- .../concurrent/RewardConcurrentFetching.java | 29 +-- .../explorer/rewards/config/KoiosClient.java | 7 +- .../explorer/rewards/config/RetryConfig.java | 3 +- .../rewards/constant/NetworkConstants.java | 4 +- .../rewards/controller/AdaPotsController.java | 9 +- .../rewards/controller/EpochController.java | 13 +- .../rewards/repository/AdaPotsRepository.java | 2 +- .../rewards/repository/BlockRepository.java | 1 - .../rewards/repository/EpochRepository.java | 15 +- .../EpochStakeCheckpointRepository.java | 4 +- .../repository/EpochStakeRepository.java | 4 +- .../repository/PoolHashRepository.java | 1 + .../PoolHistoryCheckpointRepository.java | 4 +- .../repository/PoolHistoryRepository.java | 4 +- .../repository/PoolInfoRepository.java | 4 +- .../RewardCheckpointRepository.java | 5 +- .../rewards/repository/RewardRepository.java | 5 +- .../repository/StakeAddressRepository.java | 1 - .../JOOQEpochStakeCheckpointRepository.java | 16 +- .../jooq/JOOQEpochStakeRepository.java | 17 +- .../JOOQPoolHistoryCheckpointRepository.java | 19 +- .../jooq/JOOQPoolHistoryRepository.java | 16 +- .../JOOQPoolInfoCheckpointRepository.java | 9 +- .../jooq/JOOQPoolInfoRepository.java | 11 +- .../jooq/JOOQRewardCheckpointRepository.java | 16 +- .../repository/jooq/JOOQRewardRepository.java | 21 +-- .../schedule/PoolInfoDataSchedule.java | 26 +-- .../schedule/service/PoolInfoDataService.java | 54 +++--- .../rewards/service/EpochFetchingService.java | 4 +- .../rewards/service/EpochService.java | 1 - .../service/PoolInfoFetchingService.java | 2 - .../service/RewardFetchingService.java | 2 +- .../impl/AdaPotsFetchingServiceImpl.java | 33 ++-- .../impl/EpochFetchingServiceImpl.java | 40 +++-- .../service/impl/EpochServiceImpl.java | 8 +- .../impl/EpochStakeFetchingServiceImpl.java | 136 +++++++------- .../impl/PoolHistoryFetchingServiceImpl.java | 105 +++++------ .../impl/PoolInfoFetchingServiceImpl.java | 66 ++++--- .../impl/RewardFetchingServiceImpl.java | 122 +++++++------ .../explorer/rewards/util/CommonUtils.java | 7 +- .../ExplorerRewardsApplicationTests.java | 3 +- .../AdaPostsConcurrentFetchingTest.java | 30 ++-- .../EpochConcurrentFetchingTest.java | 33 ++-- .../EpochStakeConcurrentFetchingTest.java | 73 ++++---- .../PoolHistoryConcurrentFetchingTest.java | 67 ++++--- .../PoolInfoConcurrentFetchingTest.java | 51 +++--- .../RewardConcurrentFetchingTest.java | 71 ++++---- .../controller/AdaPotsControllerTest.java | 41 +++-- .../controller/EpochControllerTest.java | 50 +++--- .../controller/EpochStakeControllerTest.java | 52 +++--- .../controller/PoolHistoryControllerTest.java | 52 +++--- .../controller/PoolInfoControllerTest.java | 52 +++--- .../controller/RewardControllerTest.java | 51 +++--- ...OOQEpochStakeCheckPointRepositoryTest.java | 29 ++- .../jooq/JOOQEpochStakeRepositoryTest.java | 16 +- ...OQPoolHistoryCheckPointRepositoryTest.java | 22 +-- .../jooq/JOOQPoolHistoryRepositoryTest.java | 14 +- .../JOOQPoolInfoCheckPointRepositoryTest.java | 20 +-- .../jooq/JOOQPoolInfoRepositoryTest.java | 11 +- .../JOOQRewardCheckpointRepositoryTest.java | 6 +- .../jooq/JOOQRewardRepositoryTest.java | 5 +- .../schedule/PoolInfoDataScheduleTest.java | 64 +++---- .../service/PoolInfoDataServiceTest.java | 82 ++++----- .../impl/AdaPotsFetchingServiceImplTest.java | 57 +++--- .../impl/EpochFetchingServiceImplTest.java | 82 ++++----- .../service/impl/EpochServiceImplTest.java | 19 +- .../EpochStakeFetchingServiceImplTest.java | 167 +++++++++--------- .../PoolHistoryFetchingServiceImplTest.java | 99 +++++------ .../impl/PoolInfoFetchingServiceImplTest.java | 85 +++++---- .../impl/RewardFetchingServiceImplTest.java | 165 ++++++++--------- 76 files changed, 1339 insertions(+), 1264 deletions(-) diff --git a/pom.xml b/pom.xml index a0ecd91a..1b0da61a 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,8 @@ 4.0.0-M2 3.3.0 1.17.3 + 2.36.0 + 1.15.0 @@ -230,6 +232,39 @@ + + com.diffplug.spotless + spotless-maven-plugin + ${version.spotless-maven-plugin} + + + + build/**/*.java + + + + Remove wildcard imports + import\\s+[^\\*\\s]+\\*;(\\r\\n|\\r|\\n) + $1 + + + ${version.google-java-format} + + + + + java,jakarta,javax,lombok,org.springframework,,\\#,org.junit,\\#org.junit,org.cardanofoundation,\\#org.cardanofoundation + + + + true + 2 + + + + + + diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/AdaPostsConcurrentFetching.java b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/AdaPostsConcurrentFetching.java index 0522a6f1..997fdbce 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/AdaPostsConcurrentFetching.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/AdaPostsConcurrentFetching.java @@ -1,16 +1,18 @@ package org.cardanofoundation.explorer.rewards.concurrent; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import lombok.experimental.FieldDefaults; import lombok.extern.slf4j.Slf4j; -import org.cardanofoundation.explorer.rewards.service.AdaPotsFetchingService; + import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; +import org.cardanofoundation.explorer.rewards.service.AdaPotsFetchingService; @Component @FieldDefaults(level = AccessLevel.PRIVATE) @@ -22,7 +24,7 @@ public class AdaPostsConcurrentFetching { final AdaPotsFetchingService adaPotsFetchingService; public Boolean fetchDataConcurrently(List epochs) { - //TODO: validate stake address list + // TODO: validate stake address list var curTime = System.currentTimeMillis(); List epochsNeedFetchData = adaPotsFetchingService.getEpochsNeedFetchData(epochs); @@ -36,13 +38,14 @@ public Boolean fetchDataConcurrently(List epochs) { List> futures = new ArrayList<>(); for (var epoch : epochsNeedFetchData) { - CompletableFuture future = adaPotsFetchingService.fetchData(epoch) - .exceptionally( - ex -> { - log.error("Exception occurred in fetch ada-posts data}: {}", ex.getMessage()); - return Boolean.FALSE; - } - ); + CompletableFuture future = + adaPotsFetchingService + .fetchData(epoch) + .exceptionally( + ex -> { + log.error("Exception occurred in fetch ada-posts data}: {}", ex.getMessage()); + return Boolean.FALSE; + }); futures.add(future); } @@ -50,8 +53,9 @@ public Boolean fetchDataConcurrently(List epochs) { boolean result = futures.stream().allMatch(CompletableFuture::join); - log.info("Fetch and save ada-posts record concurrently by koios api: {} ms", - System.currentTimeMillis() - curTime); + log.info( + "Fetch and save ada-posts record concurrently by koios api: {} ms", + System.currentTimeMillis() - curTime); return result; } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetching.java b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetching.java index e3024100..eab3aa76 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetching.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetching.java @@ -1,18 +1,20 @@ package org.cardanofoundation.explorer.rewards.concurrent; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; + import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import lombok.experimental.FieldDefaults; import lombok.extern.slf4j.Slf4j; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; -import org.cardanofoundation.explorer.rewards.service.EpochFetchingService; + import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.CompletableFuture; +import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.rewards.service.EpochFetchingService; @Component @FieldDefaults(level = AccessLevel.PRIVATE) @@ -37,23 +39,27 @@ public List fetchDataConcurrently(List epochNoList) { List> futures = new ArrayList<>(); for (var epoch : epochsNeedFetchData) { - CompletableFuture future = epochFetchingService.fetchData(epoch) - .exceptionally( - ex -> { - log.error("Exception occurred in fetch epoch data}: {}", ex.getMessage()); - return null; - } - ); + CompletableFuture future = + epochFetchingService + .fetchData(epoch) + .exceptionally( + ex -> { + log.error("Exception occurred in fetch epoch data}: {}", ex.getMessage()); + return null; + }); if (Objects.nonNull(future)) { futures.add(future); } } - List result = futures.stream() - .filter(epoch -> Objects.nonNull(epoch.join())) - .map(CompletableFuture::join).toList(); + List result = + futures.stream() + .filter(epoch -> Objects.nonNull(epoch.join())) + .map(CompletableFuture::join) + .toList(); - log.info("Fetch and save epoch record concurrently by koios api: {} ms", + log.info( + "Fetch and save epoch record concurrently by koios api: {} ms", System.currentTimeMillis() - curTime); return result; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochStakeConcurrentFetching.java b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochStakeConcurrentFetching.java index 730ea472..87bb91ae 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochStakeConcurrentFetching.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochStakeConcurrentFetching.java @@ -14,9 +14,10 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; -import org.cardanofoundation.explorer.rewards.service.EpochStakeFetchingService; import rest.koios.client.backend.api.base.exception.ApiException; +import org.cardanofoundation.explorer.rewards.service.EpochStakeFetchingService; + @Component @FieldDefaults(level = AccessLevel.PRIVATE) @RequiredArgsConstructor @@ -31,7 +32,7 @@ public class EpochStakeConcurrentFetching { int subListSize; public Boolean fetchDataConcurrently(List stakeAddressList) { - //TODO: validate stake address list + // TODO: validate stake address list var curTime = System.currentTimeMillis(); if (stakeAddressList.isEmpty()) { @@ -42,10 +43,11 @@ public Boolean fetchDataConcurrently(List stakeAddressList) { try { // we only fetch data with addresses that are not in the checkpoint table // or in the checkpoint table but have an epoch checkpoint value < (current epoch) - stakeAddressListNeedFetchData = epochStakeFetchingService.getStakeAddressListNeedFetchData( - stakeAddressList); + stakeAddressListNeedFetchData = + epochStakeFetchingService.getStakeAddressListNeedFetchData(stakeAddressList); } catch (ApiException e) { - log.error("Exception occurs when calling getStakeAddressListNeedFetchData: {}", e.getMessage()); + log.error( + "Exception occurs when calling getStakeAddressListNeedFetchData: {}", e.getMessage()); return Boolean.FALSE; } @@ -62,13 +64,14 @@ public Boolean fetchDataConcurrently(List stakeAddressList) { int endIndex = Math.min(i + subListSize, stakeAddressListNeedFetchData.size()); var sublist = stakeAddressListNeedFetchData.subList(i, endIndex); - CompletableFuture future = epochStakeFetchingService.fetchData(sublist) - .exceptionally( - ex -> { - log.error("Exception occurred in fetch epoch stake data}: {}", ex.getMessage()); - return Boolean.FALSE; - } - ); + CompletableFuture future = + epochStakeFetchingService + .fetchData(sublist) + .exceptionally( + ex -> { + log.error("Exception occurred in fetch epoch stake data}: {}", ex.getMessage()); + return Boolean.FALSE; + }); futures.add(future); } @@ -76,7 +79,8 @@ public Boolean fetchDataConcurrently(List stakeAddressList) { boolean result = futures.stream().allMatch(CompletableFuture::join); - log.info("Fetch and save epoch stake record concurrently by koios api: {} ms", + log.info( + "Fetch and save epoch stake record concurrently by koios api: {} ms", System.currentTimeMillis() - curTime); return result; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/PoolHistoryConcurrentFetching.java b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/PoolHistoryConcurrentFetching.java index cfa83dae..85913d60 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/PoolHistoryConcurrentFetching.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/PoolHistoryConcurrentFetching.java @@ -12,9 +12,10 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; -import org.cardanofoundation.explorer.rewards.service.PoolHistoryFetchingService; import rest.koios.client.backend.api.base.exception.ApiException; +import org.cardanofoundation.explorer.rewards.service.PoolHistoryFetchingService; + @Component @FieldDefaults(level = AccessLevel.PRIVATE) @RequiredArgsConstructor @@ -25,7 +26,7 @@ public class PoolHistoryConcurrentFetching { final PoolHistoryFetchingService poolHistoryFetchingService; public Boolean fetchDataConcurrently(List poolIds) { - //TODO: validate poolIds + // TODO: validate poolIds var curTime = System.currentTimeMillis(); if (poolIds.isEmpty()) { @@ -36,8 +37,7 @@ public Boolean fetchDataConcurrently(List poolIds) { try { // we only fetch data with addresses that are not in the checkpoint table // or in the checkpoint table but have an epoch checkpoint value < (current epoch - 1) - poolIdListNeedFetchData = poolHistoryFetchingService.getPoolIdListNeedFetchData( - poolIds); + poolIdListNeedFetchData = poolHistoryFetchingService.getPoolIdListNeedFetchData(poolIds); } catch (ApiException e) { log.error("Exception occurs when calling getPoolIdListNeedFetchData: {}", e.getMessage()); return Boolean.FALSE; @@ -53,14 +53,17 @@ public Boolean fetchDataConcurrently(List poolIds) { List> futures = new ArrayList<>(); for (var poolId : poolIdListNeedFetchData) { - CompletableFuture future = poolHistoryFetchingService.fetchData(poolId) - .exceptionally( - ex -> { - log.error("Exception occurred in fetchData for poolId {}: {}", poolId, - ex.getMessage()); - return Boolean.FALSE; - } - ); + CompletableFuture future = + poolHistoryFetchingService + .fetchData(poolId) + .exceptionally( + ex -> { + log.error( + "Exception occurred in fetchData for poolId {}: {}", + poolId, + ex.getMessage()); + return Boolean.FALSE; + }); futures.add(future); } @@ -68,7 +71,8 @@ public Boolean fetchDataConcurrently(List poolIds) { boolean result = futures.stream().allMatch(CompletableFuture::join); - log.info("Fetch and save pool history record concurrently by koios api: {} ms", + log.info( + "Fetch and save pool history record concurrently by koios api: {} ms", System.currentTimeMillis() - curTime); return result; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/PoolInfoConcurrentFetching.java b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/PoolInfoConcurrentFetching.java index 0ad517ff..e9451aa5 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/PoolInfoConcurrentFetching.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/PoolInfoConcurrentFetching.java @@ -15,7 +15,6 @@ import org.springframework.stereotype.Component; import org.cardanofoundation.explorer.rewards.service.PoolInfoFetchingService; -import rest.koios.client.backend.api.base.exception.ApiException; @Component @FieldDefaults(level = AccessLevel.PRIVATE) @@ -31,7 +30,7 @@ public class PoolInfoConcurrentFetching { int subListSize; public Boolean fetchDataConcurrently(List poolIds) { - //TODO: validate poolIds list + // TODO: validate poolIds list var curTime = System.currentTimeMillis(); if (poolIds.isEmpty()) { @@ -44,13 +43,14 @@ public Boolean fetchDataConcurrently(List poolIds) { int endIndex = Math.min(i + subListSize, poolIds.size()); var sublist = poolIds.subList(i, endIndex); - CompletableFuture future = poolInfoFetchingService.fetchData(sublist) - .exceptionally( - ex -> { - log.error("Exception occurred in fetch epoch stake data}: {}", ex.getMessage()); - return Boolean.FALSE; - } - ); + CompletableFuture future = + poolInfoFetchingService + .fetchData(sublist) + .exceptionally( + ex -> { + log.error("Exception occurred in fetch epoch stake data}: {}", ex.getMessage()); + return Boolean.FALSE; + }); futures.add(future); } @@ -58,7 +58,8 @@ public Boolean fetchDataConcurrently(List poolIds) { boolean result = futures.stream().allMatch(CompletableFuture::join); - log.info("Fetch and save pool info record concurrently by koios api: {} ms", + log.info( + "Fetch and save pool info record concurrently by koios api: {} ms", System.currentTimeMillis() - curTime); return result; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/RewardConcurrentFetching.java b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/RewardConcurrentFetching.java index 4bfb631b..e83b4bb9 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/RewardConcurrentFetching.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/RewardConcurrentFetching.java @@ -14,9 +14,10 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; -import org.cardanofoundation.explorer.rewards.service.RewardFetchingService; import rest.koios.client.backend.api.base.exception.ApiException; +import org.cardanofoundation.explorer.rewards.service.RewardFetchingService; + @Component @FieldDefaults(level = AccessLevel.PRIVATE) @RequiredArgsConstructor @@ -31,7 +32,7 @@ public class RewardConcurrentFetching { int subListSize; public Boolean fetchDataConcurrently(List stakeAddressList) { - //TODO: validate stake address list + // TODO: validate stake address list var curTime = System.currentTimeMillis(); if (stakeAddressList.isEmpty()) { @@ -42,10 +43,11 @@ public Boolean fetchDataConcurrently(List stakeAddressList) { try { // we only fetch data with addresses that are not in the checkpoint table // or in the checkpoint table but have an epoch checkpoint value < (current epoch - 1) - stakeAddressListNeedFetchData = rewardFetchingService.getStakeAddressListNeedFetchData( - stakeAddressList); + stakeAddressListNeedFetchData = + rewardFetchingService.getStakeAddressListNeedFetchData(stakeAddressList); } catch (ApiException e) { - log.error("Exception occurs when calling getStakeAddressListNeedFetchData: {}", e.getMessage()); + log.error( + "Exception occurs when calling getStakeAddressListNeedFetchData: {}", e.getMessage()); return Boolean.FALSE; } @@ -61,12 +63,14 @@ public Boolean fetchDataConcurrently(List stakeAddressList) { int endIndex = Math.min(i + subListSize, stakeAddressList.size()); var sublist = stakeAddressList.subList(i, endIndex); - CompletableFuture future = rewardFetchingService.fetchData(sublist).exceptionally( - ex -> { - log.error("Exception occurred in fetch reward data: {}", ex.getMessage()); - return Boolean.FALSE; - } - ); + CompletableFuture future = + rewardFetchingService + .fetchData(sublist) + .exceptionally( + ex -> { + log.error("Exception occurred in fetch reward data: {}", ex.getMessage()); + return Boolean.FALSE; + }); futures.add(future); } @@ -74,7 +78,8 @@ public Boolean fetchDataConcurrently(List stakeAddressList) { boolean result = futures.stream().allMatch(CompletableFuture::join); - log.info("Fetch and save reward record concurrently by koios api: {} ms", + log.info( + "Fetch and save reward record concurrently by koios api: {} ms", System.currentTimeMillis() - curTime); return result; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/config/KoiosClient.java b/src/main/java/org/cardanofoundation/explorer/rewards/config/KoiosClient.java index 250adab7..97814d8a 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/config/KoiosClient.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/config/KoiosClient.java @@ -4,7 +4,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; -import org.cardanofoundation.explorer.rewards.constant.NetworkConstants; import rest.koios.client.backend.api.account.AccountService; import rest.koios.client.backend.api.epoch.EpochService; import rest.koios.client.backend.api.network.NetworkService; @@ -12,6 +11,8 @@ import rest.koios.client.backend.factory.BackendFactory; import rest.koios.client.backend.factory.BackendService; +import org.cardanofoundation.explorer.rewards.constant.NetworkConstants; + @Component @Profile("koios") public class KoiosClient { @@ -42,9 +43,9 @@ public EpochService epochService() { } private BackendService getBackendService() { - if(Boolean.TRUE.equals(baseUrlEnabled)) { + if (Boolean.TRUE.equals(baseUrlEnabled)) { return BackendFactory.getCustomRPCService(baseUrl); - } else{ + } else { return switch (value) { case NetworkConstants.MAINNET -> BackendFactory.getKoiosMainnetService(); case NetworkConstants.PREPROD -> BackendFactory.getKoiosPreprodService(); diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/config/RetryConfig.java b/src/main/java/org/cardanofoundation/explorer/rewards/config/RetryConfig.java index e23b8ddf..7718ca29 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/config/RetryConfig.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/config/RetryConfig.java @@ -5,5 +5,4 @@ @EnableRetry @Configuration -public class RetryConfig { -} +public class RetryConfig {} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/constant/NetworkConstants.java b/src/main/java/org/cardanofoundation/explorer/rewards/constant/NetworkConstants.java index ae7d72be..44cae116 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/constant/NetworkConstants.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/constant/NetworkConstants.java @@ -2,12 +2,10 @@ public class NetworkConstants { - private NetworkConstants() { - } + private NetworkConstants() {} public static final String MAINNET = "mainnet"; public static final String PREPROD = "preprod"; public static final String PREVIEW = "preview"; public static final String GUILDNET = "guildnet"; - } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/controller/AdaPotsController.java b/src/main/java/org/cardanofoundation/explorer/rewards/controller/AdaPotsController.java index a695fb3b..94df0668 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/controller/AdaPotsController.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/controller/AdaPotsController.java @@ -1,15 +1,17 @@ package org.cardanofoundation.explorer.rewards.controller; +import java.util.ArrayList; +import java.util.Set; + import lombok.RequiredArgsConstructor; -import org.cardanofoundation.explorer.rewards.concurrent.AdaPostsConcurrentFetching; + import org.springframework.context.annotation.Profile; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.ArrayList; -import java.util.Set; +import org.cardanofoundation.explorer.rewards.concurrent.AdaPostsConcurrentFetching; @RestController @RequestMapping("/api/v1/ada-pots") @@ -23,5 +25,4 @@ public class AdaPotsController { public Boolean fetchAdaPots(@RequestBody Set epochs) { return adaPostsConcurrentFetching.fetchDataConcurrently(new ArrayList<>(epochs)); } - } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/controller/EpochController.java b/src/main/java/org/cardanofoundation/explorer/rewards/controller/EpochController.java index bb75c239..cd3d5171 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/controller/EpochController.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/controller/EpochController.java @@ -1,17 +1,19 @@ package org.cardanofoundation.explorer.rewards.controller; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + import lombok.RequiredArgsConstructor; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; -import org.cardanofoundation.explorer.rewards.concurrent.EpochConcurrentFetching; + import org.springframework.context.annotation.Profile; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; +import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.rewards.concurrent.EpochConcurrentFetching; @RestController @RequestMapping("/api/v1/epochs") @@ -25,5 +27,4 @@ public class EpochController { public List fetchEpochs(@RequestBody Set epochs) { return epochConcurrentFetching.fetchDataConcurrently(new ArrayList<>(epochs)); } - } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/AdaPotsRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/AdaPotsRepository.java index 65df0853..1c2f9e07 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/AdaPotsRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/AdaPotsRepository.java @@ -7,7 +7,7 @@ import org.cardanofoundation.explorer.consumercommon.entity.AdaPots; -public interface AdaPotsRepository extends JpaRepository{ +public interface AdaPotsRepository extends JpaRepository { List findByEpochNoIn(@Param("epochs") List epochs); } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/BlockRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/BlockRepository.java index 9113fd1e..8be8b006 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/BlockRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/BlockRepository.java @@ -1,6 +1,5 @@ package org.cardanofoundation.explorer.rewards.repository; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochRepository.java index 95cf3dba..2596f34b 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochRepository.java @@ -1,5 +1,9 @@ package org.cardanofoundation.explorer.rewards.repository; +import java.math.BigInteger; +import java.util.List; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -8,10 +12,6 @@ import org.cardanofoundation.explorer.consumercommon.entity.Epoch; -import java.math.BigInteger; -import java.util.List; -import java.util.Optional; - @Repository public interface EpochRepository extends JpaRepository { @Query("SELECT MAX(e.no) FROM Epoch e") @@ -21,8 +21,9 @@ public interface EpochRepository extends JpaRepository { List findByRewardsDistributedIsNotNull(); - @Query("UPDATE Epoch epoch SET epoch.rewardsDistributed = :rewardsDistributed WHERE epoch.no = :no") + @Query( + "UPDATE Epoch epoch SET epoch.rewardsDistributed = :rewardsDistributed WHERE epoch.no = :no") @Modifying - void updateRewardDistributedByNo(@Param("rewardsDistributed") BigInteger rewardsDistributed, @Param("no") Integer no); - + void updateRewardDistributedByNo( + @Param("rewardsDistributed") BigInteger rewardsDistributed, @Param("no") Integer no); } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeCheckpointRepository.java index d79e1f2e..4815ae33 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeCheckpointRepository.java @@ -1,10 +1,10 @@ package org.cardanofoundation.explorer.rewards.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.List; - import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; @Repository diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeRepository.java index 5264230f..d17545de 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeRepository.java @@ -6,6 +6,4 @@ import org.cardanofoundation.explorer.consumercommon.entity.EpochStake; @Repository -public interface EpochStakeRepository extends JpaRepository { - -} +public interface EpochStakeRepository extends JpaRepository {} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHashRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHashRepository.java index 22f18e3e..857e6cf3 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHashRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHashRepository.java @@ -12,5 +12,6 @@ @Repository public interface PoolHashRepository extends JpaRepository { List findByViewIn(Collection views); + Optional findByView(String view); } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryCheckpointRepository.java index 7e6c0f7c..e8892029 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryCheckpointRepository.java @@ -9,8 +9,8 @@ import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint; @Repository -public interface PoolHistoryCheckpointRepository extends - JpaRepository { +public interface PoolHistoryCheckpointRepository + extends JpaRepository { List findByViewIn(List poolId); diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryRepository.java index 124fd62f..a0a26442 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryRepository.java @@ -6,6 +6,4 @@ import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory; @Repository -public interface PoolHistoryRepository extends JpaRepository { - -} +public interface PoolHistoryRepository extends JpaRepository {} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoRepository.java index 9a07473b..7212cd43 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoRepository.java @@ -6,6 +6,4 @@ import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; @Repository -public interface PoolInfoRepository extends JpaRepository { - -} +public interface PoolInfoRepository extends JpaRepository {} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardCheckpointRepository.java index 14ef2dc3..dad0d0a6 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardCheckpointRepository.java @@ -1,15 +1,14 @@ package org.cardanofoundation.explorer.rewards.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.List; - import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint; @Repository public interface RewardCheckpointRepository extends JpaRepository { List findByStakeAddressIn(List stakeAddress); - } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardRepository.java index e170b574..c84701cc 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardRepository.java @@ -1,12 +1,9 @@ package org.cardanofoundation.explorer.rewards.repository; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import org.cardanofoundation.explorer.consumercommon.entity.Reward; - @Repository -public interface RewardRepository extends JpaRepository { -} +public interface RewardRepository extends JpaRepository {} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/StakeAddressRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/StakeAddressRepository.java index e49e4b86..4202b5ad 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/StakeAddressRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/StakeAddressRepository.java @@ -8,7 +8,6 @@ import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress; - @Repository public interface StakeAddressRepository extends JpaRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckpointRepository.java index b8f5298d..4235bbf5 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckpointRepository.java @@ -1,5 +1,8 @@ package org.cardanofoundation.explorer.rewards.repository.jooq; +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; + import java.util.ArrayList; import java.util.List; @@ -7,14 +10,12 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.jooq.Query; -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.table; +import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; +import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @Component public class JOOQEpochStakeCheckpointRepository { @@ -23,13 +24,12 @@ public class JOOQEpochStakeCheckpointRepository { private final EntityUtil entityUtil; - public JOOQEpochStakeCheckpointRepository(DSLContext dsl, - @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { + public JOOQEpochStakeCheckpointRepository( + DSLContext dsl, @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { this.dsl = dsl; this.entityUtil = new EntityUtil(schema, EpochStakeCheckpoint.class); } - @Transactional public void saveAll(List checkpoints) { if (checkpoints.isEmpty()) { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepository.java index ee3be220..98b53fea 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepository.java @@ -1,5 +1,8 @@ package org.cardanofoundation.explorer.rewards.repository.jooq; +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; + import java.math.BigInteger; import java.util.ArrayList; import java.util.List; @@ -8,14 +11,12 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStake; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStake_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.jooq.Query; -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.table; +import org.cardanofoundation.explorer.consumercommon.entity.EpochStake; +import org.cardanofoundation.explorer.consumercommon.entity.EpochStake_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @Component public class JOOQEpochStakeRepository { @@ -24,8 +25,8 @@ public class JOOQEpochStakeRepository { private final EntityUtil entityUtil; - public JOOQEpochStakeRepository(DSLContext dsl, - @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { + public JOOQEpochStakeRepository( + DSLContext dsl, @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { this.dsl = dsl; this.entityUtil = new EntityUtil(schema, EpochStake.class); } @@ -60,4 +61,4 @@ public void saveAll(List epochStakes) { dsl.batch(queries).execute(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckpointRepository.java index f1895738..c0465b3a 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckpointRepository.java @@ -1,5 +1,8 @@ package org.cardanofoundation.explorer.rewards.repository.jooq; +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; + import java.util.ArrayList; import java.util.List; @@ -7,14 +10,12 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.jooq.Query; -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.table; +import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint; +import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @Component public class JOOQPoolHistoryCheckpointRepository { @@ -23,8 +24,8 @@ public class JOOQPoolHistoryCheckpointRepository { private final EntityUtil entityUtil; - public JOOQPoolHistoryCheckpointRepository(DSLContext dsl, - @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { + public JOOQPoolHistoryCheckpointRepository( + DSLContext dsl, @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { this.dsl = dsl; this.entityUtil = new EntityUtil(schema, PoolHistoryCheckpoint.class); } @@ -37,8 +38,8 @@ public void saveAll(List checkpoints) { var queries = new ArrayList(); var epochCheckpointField = entityUtil.getColumnField(PoolHistoryCheckpoint_.EPOCH_CHECKPOINT); var viewField = entityUtil.getColumnField(PoolHistoryCheckpoint_.VIEW); - var isSpendableRewardField = entityUtil.getColumnField( - PoolHistoryCheckpoint_.IS_SPENDABLE_REWARD); + var isSpendableRewardField = + entityUtil.getColumnField(PoolHistoryCheckpoint_.IS_SPENDABLE_REWARD); for (var checkpoint : checkpoints) { var query = diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepository.java index 97ec42c9..33170b1d 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepository.java @@ -1,19 +1,20 @@ package org.cardanofoundation.explorer.rewards.repository.jooq; +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; + import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.jooq.Query; -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.table; +import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory; +import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @Component public class JOOQPoolHistoryRepository { @@ -22,8 +23,8 @@ public class JOOQPoolHistoryRepository { private final EntityUtil entityUtil; - public JOOQPoolHistoryRepository(DSLContext dsl, - @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { + public JOOQPoolHistoryRepository( + DSLContext dsl, @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { this.dsl = dsl; this.entityUtil = new EntityUtil(schema, PoolHistory.class); } @@ -72,4 +73,3 @@ public void saveAll(List poolHistories) { dsl.batch(queries).execute(); } } - diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckpointRepository.java index 61590961..e3a900b3 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckpointRepository.java @@ -9,11 +9,12 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.jooq.Query; + import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint; +import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @Component public class JOOQPoolInfoCheckpointRepository { @@ -22,8 +23,8 @@ public class JOOQPoolInfoCheckpointRepository { private final EntityUtil entityUtil; - public JOOQPoolInfoCheckpointRepository(DSLContext dsl, - @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { + public JOOQPoolInfoCheckpointRepository( + DSLContext dsl, @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { this.dsl = dsl; this.entityUtil = new EntityUtil(schema, PoolInfoCheckpoint.class); } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepository.java index 0a888c17..286d5ad8 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepository.java @@ -6,16 +6,15 @@ import java.util.ArrayList; import java.util.List; - import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.jooq.Query; import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; +import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @Component public class JOOQPoolInfoRepository { @@ -24,8 +23,8 @@ public class JOOQPoolInfoRepository { private final EntityUtil entityUtil; - public JOOQPoolInfoRepository(DSLContext dsl, - @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { + public JOOQPoolInfoRepository( + DSLContext dsl, @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { this.dsl = dsl; this.entityUtil = new EntityUtil(schema, PoolInfo.class); } @@ -60,4 +59,4 @@ public void saveAll(List poolInfos) { dsl.batch(queries).execute(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepository.java index a443e8b1..45c514df 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepository.java @@ -1,21 +1,20 @@ package org.cardanofoundation.explorer.rewards.repository.jooq; +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; + import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import org.cardanofoundation.explorer.consumercommon.entity.Reward; -import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.jooq.Query; import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint; - -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.table; +import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @Component public class JOOQRewardCheckpointRepository { @@ -24,13 +23,12 @@ public class JOOQRewardCheckpointRepository { private final EntityUtil entityUtil; - public JOOQRewardCheckpointRepository(DSLContext dsl, - @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { + public JOOQRewardCheckpointRepository( + DSLContext dsl, @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { this.dsl = dsl; this.entityUtil = new EntityUtil(schema, RewardCheckpoint.class); } - public void saveAll(List checkpoints) { if (checkpoints.isEmpty()) { return; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepository.java index d0c88b20..47964663 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepository.java @@ -1,25 +1,22 @@ package org.cardanofoundation.explorer.rewards.repository.jooq; +import static org.jooq.impl.DSL.coalesce; +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; import java.math.BigInteger; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.Reward_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; -import org.jooq.Field; import org.jooq.Query; import org.cardanofoundation.explorer.consumercommon.entity.Reward; - -import static org.jooq.impl.DSL.coalesce; -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.table; +import org.cardanofoundation.explorer.consumercommon.entity.Reward_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @Repository public class JOOQRewardRepository { @@ -28,8 +25,8 @@ public class JOOQRewardRepository { private final EntityUtil entityUtil; - public JOOQRewardRepository(DSLContext dsl, - @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { + public JOOQRewardRepository( + DSLContext dsl, @Value("${spring.jpa.properties.hibernate.default_schema}") String schema) { this.dsl = dsl; this.entityUtil = new EntityUtil(schema, Reward.class); } @@ -65,8 +62,7 @@ public void saveAll(List rewards) { field(addressIdField), field(typeField), field(earnedEpochField), - coalesce(field(poolIdField), -1) - ) + coalesce(field(poolIdField), -1)) .doNothing(); queries.add(query); @@ -75,4 +71,3 @@ public void saveAll(List rewards) { dsl.batch(queries).execute(); } } - diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataSchedule.java b/src/main/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataSchedule.java index 928171ca..7d1f9a99 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataSchedule.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataSchedule.java @@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Profile; -import org.springframework.data.domain.PageRequest; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -41,8 +40,7 @@ public class PoolInfoDataSchedule { @Value("${application.pool-info.list-size-each-thread}") int subListSize; - @Scheduled( - fixedDelayString = "${application.pool-info.job.fixed-delay}") + @Scheduled(fixedDelayString = "${application.pool-info.job.fixed-delay}") @SneakyThrows public void fetchAllPoolInfoData() { log.info("Pool Info Job:-------------Start job---------------"); @@ -57,14 +55,17 @@ public void fetchAllPoolInfoData() { int endIndex = Math.min(i + subListSize, poolIds.size()); var sublist = poolIds.subList(i, endIndex); - CompletableFuture future = poolInfoDataService.fetchData(sublist) - .exceptionally( - ex -> { - log.error("Exception occurred in fetchData for poolId {}: {}", sublist, - ex.getMessage()); - return Boolean.FALSE; - } - ); + CompletableFuture future = + poolInfoDataService + .fetchData(sublist) + .exceptionally( + ex -> { + log.error( + "Exception occurred in fetchData for poolId {}: {}", + sublist, + ex.getMessage()); + return Boolean.FALSE; + }); futures.add(future); } @@ -72,7 +73,8 @@ public void fetchAllPoolInfoData() { boolean result = futures.stream().allMatch(CompletableFuture::join); if (result) { - log.info("Pool Info Job: It's success, fetch and save pool info record concurrently by koios api: {} ms", + log.info( + "Pool Info Job: It's success, fetch and save pool info record concurrently by koios api: {} ms", System.currentTimeMillis() - curTime); } else { log.info("Pool Info Job: It's not success"); diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java b/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java index c74602c7..7c9c1d14 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java @@ -18,13 +18,14 @@ import org.springframework.transaction.annotation.Transactional; import io.micrometer.common.util.StringUtils; +import rest.koios.client.backend.api.base.exception.ApiException; + import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolInfoRepository; import org.cardanofoundation.explorer.rewards.service.EpochService; -import rest.koios.client.backend.api.base.exception.ApiException; @Service @RequiredArgsConstructor @@ -38,7 +39,9 @@ public class PoolInfoDataService { final EpochService epochService; @Transactional - @Retryable(retryFor = {Exception.class}, maxAttempts = 3) + @Retryable( + retryFor = {Exception.class}, + maxAttempts = 3) @SneakyThrows @Async public CompletableFuture fetchData(List poolIds) { @@ -46,21 +49,34 @@ public CompletableFuture fetchData(List poolIds) { int currentEpoch = epochService.getCurrentEpoch(); var dataFromKoios = getPoolInfoList(poolIds); - var poolHashMap = poolHashRepository.findByViewIn(poolIds).stream().collect(Collectors.toMap( - PoolHash::getView, Function.identity())); + var poolHashMap = + poolHashRepository.findByViewIn(poolIds).stream() + .collect(Collectors.toMap(PoolHash::getView, Function.identity())); - List poolInfoList = dataFromKoios.stream().map(poolInfo -> - PoolInfo.builder().poolId(poolHashMap.get(poolInfo.getPoolIdBech32()).getId()) - .fetchedAtEpoch(currentEpoch) - .activeStake(StringUtils.isNotBlank(poolInfo.getActiveStake()) ? new BigInteger( - poolInfo.getActiveStake()) : null) - .liveStake(StringUtils.isNotBlank(poolInfo.getLiveStake()) ? new BigInteger( - poolInfo.getLiveStake()) : null) - .liveSaturation(poolInfo.getLiveSaturation()).build()) - .collect(Collectors.toList()); + List poolInfoList = + dataFromKoios.stream() + .map( + poolInfo -> + PoolInfo.builder() + .poolId(poolHashMap.get(poolInfo.getPoolIdBech32()).getId()) + .fetchedAtEpoch(currentEpoch) + .activeStake( + StringUtils.isNotBlank(poolInfo.getActiveStake()) + ? new BigInteger(poolInfo.getActiveStake()) + : null) + .liveStake( + StringUtils.isNotBlank(poolInfo.getLiveStake()) + ? new BigInteger(poolInfo.getLiveStake()) + : null) + .liveSaturation(poolInfo.getLiveSaturation()) + .build()) + .collect(Collectors.toList()); - log.info("fetch {} pool_info by koios api: {} ms, with poolIds input size {}", - poolInfoList.size(), System.currentTimeMillis() - curTime, poolIds.size()); + log.info( + "fetch {} pool_info by koios api: {} ms, with poolIds input size {}", + poolInfoList.size(), + System.currentTimeMillis() - curTime, + poolIds.size()); jooqPoolInfoRepository.saveAll(poolInfoList); return CompletableFuture.completedFuture(Boolean.TRUE); @@ -74,11 +90,7 @@ public CompletableFuture fetchData(List poolIds) { * @throws ApiException */ private List getPoolInfoList( - List poolIdList) - throws ApiException { - return koiosClient.poolService() - .getPoolInformation(poolIdList, null) - .getValue(); + List poolIdList) throws ApiException { + return koiosClient.poolService().getPoolInformation(poolIdList, null).getValue(); } - } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochFetchingService.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochFetchingService.java index 07a5a104..10765212 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochFetchingService.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochFetchingService.java @@ -1,10 +1,10 @@ package org.cardanofoundation.explorer.rewards.service; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; - import java.util.List; import java.util.concurrent.CompletableFuture; +import org.cardanofoundation.explorer.consumercommon.entity.Epoch; + public interface EpochFetchingService { CompletableFuture fetchData(Integer epochNo); diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochService.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochService.java index 3188d87e..e89e7842 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochService.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochService.java @@ -1,6 +1,5 @@ package org.cardanofoundation.explorer.rewards.service; - import rest.koios.client.backend.api.base.exception.ApiException; public interface EpochService { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/PoolInfoFetchingService.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/PoolInfoFetchingService.java index c31e3667..2307ffa3 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/PoolInfoFetchingService.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/PoolInfoFetchingService.java @@ -3,8 +3,6 @@ import java.util.List; import java.util.concurrent.CompletableFuture; -import rest.koios.client.backend.api.base.exception.ApiException; - public interface PoolInfoFetchingService { CompletableFuture fetchData(List poolIds); } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/RewardFetchingService.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/RewardFetchingService.java index 150a81de..81811450 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/RewardFetchingService.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/RewardFetchingService.java @@ -7,6 +7,6 @@ public interface RewardFetchingService { CompletableFuture fetchData(List stakeAddresses); - List getStakeAddressListNeedFetchData(List StakeAddressList) throws ApiException; + List getStakeAddressListNeedFetchData(List StakeAddressList) throws ApiException; } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImpl.java index b6a6c008..128477c6 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImpl.java @@ -1,10 +1,22 @@ package org.cardanofoundation.explorer.rewards.service.impl; +import java.math.BigInteger; +import java.util.List; +import java.util.concurrent.CompletableFuture; + import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.experimental.FieldDefaults; import lombok.extern.slf4j.Slf4j; + +import org.springframework.context.annotation.Profile; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import rest.koios.client.backend.api.network.model.Totals; + import org.cardanofoundation.explorer.consumercommon.entity.AdaPots; import org.cardanofoundation.explorer.consumercommon.entity.Block; import org.cardanofoundation.explorer.rewards.config.KoiosClient; @@ -12,15 +24,6 @@ import org.cardanofoundation.explorer.rewards.repository.BlockRepository; import org.cardanofoundation.explorer.rewards.repository.EpochRepository; import org.cardanofoundation.explorer.rewards.service.AdaPotsFetchingService; -import org.springframework.context.annotation.Profile; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import rest.koios.client.backend.api.network.model.Totals; - -import java.math.BigInteger; -import java.util.List; -import java.util.concurrent.CompletableFuture; @Service @FieldDefaults(level = AccessLevel.PRIVATE) @@ -39,9 +42,8 @@ public class AdaPotsFetchingServiceImpl implements AdaPotsFetchingService { @Async @SneakyThrows public CompletableFuture fetchData(Integer epoch) { - var adaPotsKoios = koiosClient.networkService() - .getHistoricalTokenomicStatsByEpoch(epoch) - .getValue(); + var adaPotsKoios = + koiosClient.networkService().getHistoricalTokenomicStatsByEpoch(epoch).getValue(); adaPotsRepository.save(mapToAdaPots(adaPotsKoios)); return CompletableFuture.completedFuture(Boolean.TRUE); @@ -51,11 +53,12 @@ public CompletableFuture fetchData(Integer epoch) { public List getEpochsNeedFetchData(List epochs) { Integer currentEpoch = epochRepository.findMaxEpoch(); - List existedAdaPosts = adaPotsRepository.findByEpochNoIn(epochs).stream() - .map(AdaPots::getEpochNo).toList(); + List existedAdaPosts = + adaPotsRepository.findByEpochNoIn(epochs).stream().map(AdaPots::getEpochNo).toList(); return epochs.stream() - .filter(epoch -> !existedAdaPosts.contains(epoch) && epoch <= currentEpoch).toList(); + .filter(epoch -> !existedAdaPosts.contains(epoch) && epoch <= currentEpoch) + .toList(); } private AdaPots mapToAdaPots(Totals totals) { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImpl.java index 1e268182..e1a78013 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImpl.java @@ -1,25 +1,28 @@ package org.cardanofoundation.explorer.rewards.service.impl; -import io.micrometer.common.util.StringUtils; +import java.math.BigInteger; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; + import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.experimental.FieldDefaults; import lombok.extern.slf4j.Slf4j; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; -import org.cardanofoundation.explorer.consumercommon.enumeration.EraType; -import org.cardanofoundation.explorer.rewards.config.KoiosClient; -import org.cardanofoundation.explorer.rewards.repository.EpochRepository; -import org.cardanofoundation.explorer.rewards.service.EpochFetchingService; + import org.springframework.context.annotation.Profile; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.math.BigInteger; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.CompletableFuture; +import io.micrometer.common.util.StringUtils; + +import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.consumercommon.enumeration.EraType; +import org.cardanofoundation.explorer.rewards.config.KoiosClient; +import org.cardanofoundation.explorer.rewards.repository.EpochRepository; +import org.cardanofoundation.explorer.rewards.service.EpochFetchingService; @Service @FieldDefaults(level = AccessLevel.PRIVATE) @@ -33,20 +36,20 @@ public class EpochFetchingServiceImpl implements EpochFetchingService { static final Integer NUMBER_EPOCH_CALC_AND_DELIVER_REWARD = 2; - @Override @Async @Transactional(rollbackFor = {Exception.class}) @SneakyThrows public CompletableFuture fetchData(Integer epochNo) { Epoch epoch = epochRepository.findByNo(epochNo).orElse(null); - if(Objects.isNull(epoch) + if (Objects.isNull(epoch) || Objects.nonNull(epoch.getRewardsDistributed()) || epoch.getEra().equals(EraType.BYRON) || epoch.getEra().equals(EraType.BYRON_EBB)) { return null; } - String totalRewards = koiosClient.epochService().getEpochInformationByEpoch(epochNo).getValue().getTotalRewards(); + String totalRewards = + koiosClient.epochService().getEpochInformationByEpoch(epochNo).getValue().getTotalRewards(); if (StringUtils.isEmpty(totalRewards)) { Integer currentEpoch = epochRepository.findMaxEpoch(); if (epoch.getNo() <= currentEpoch - NUMBER_EPOCH_CALC_AND_DELIVER_REWARD) { @@ -66,10 +69,13 @@ public List getEpochsNeedFetchData(List epochNoList) { Integer currentEpoch = epochRepository.findMaxEpoch(); - List epochContainsRewardDistributed = epochRepository.findByRewardsDistributedIsNotNull() - .stream().map(Epoch::getNo).toList(); + List epochContainsRewardDistributed = + epochRepository.findByRewardsDistributedIsNotNull().stream().map(Epoch::getNo).toList(); return epochNoList.stream() - .filter(epoch -> !epochContainsRewardDistributed.contains(epoch) - && epoch <= currentEpoch - NUMBER_EPOCH_CALC_AND_DELIVER_REWARD).toList(); + .filter( + epoch -> + !epochContainsRewardDistributed.contains(epoch) + && epoch <= currentEpoch - NUMBER_EPOCH_CALC_AND_DELIVER_REWARD) + .toList(); } } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochServiceImpl.java index e2147326..0ecd9c02 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochServiceImpl.java @@ -5,15 +5,15 @@ import lombok.experimental.FieldDefaults; import lombok.extern.slf4j.Slf4j; -import org.cardanofoundation.explorer.rewards.config.KoiosClient; -import org.cardanofoundation.explorer.rewards.repository.EpochRepository; -import org.cardanofoundation.explorer.rewards.service.EpochService; - import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; import rest.koios.client.backend.api.base.exception.ApiException; +import org.cardanofoundation.explorer.rewards.config.KoiosClient; +import org.cardanofoundation.explorer.rewards.repository.EpochRepository; +import org.cardanofoundation.explorer.rewards.service.EpochService; + @Service @FieldDefaults(level = AccessLevel.PRIVATE) @RequiredArgsConstructor diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImpl.java index f72586dc..14e0a01e 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImpl.java @@ -19,6 +19,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import rest.koios.client.backend.api.account.model.AccountHistory; +import rest.koios.client.backend.api.account.model.AccountHistoryInner; +import rest.koios.client.backend.api.base.exception.ApiException; + import org.cardanofoundation.explorer.consumercommon.entity.EpochStake; import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; @@ -31,9 +35,6 @@ import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQEpochStakeRepository; import org.cardanofoundation.explorer.rewards.service.EpochService; import org.cardanofoundation.explorer.rewards.service.EpochStakeFetchingService; -import rest.koios.client.backend.api.account.model.AccountHistory; -import rest.koios.client.backend.api.account.model.AccountHistoryInner; -import rest.koios.client.backend.api.base.exception.ApiException; @Service @FieldDefaults(level = AccessLevel.PRIVATE) @@ -59,13 +60,16 @@ public CompletableFuture fetchData(List stakeAddressList) { int currentEpoch = epochService.getCurrentEpoch(); List accountHistoryList = getAccountHistoryList(stakeAddressList); - int epochStakeSize = accountHistoryList - .parallelStream() - .mapToInt(accountHistory -> accountHistory.getHistory().size()) - .sum(); + int epochStakeSize = + accountHistoryList.parallelStream() + .mapToInt(accountHistory -> accountHistory.getHistory().size()) + .sum(); - log.info("fetch {} epoch_stake by koios api: {} ms, with stake_address input size {}", - epochStakeSize, System.currentTimeMillis() - curTime, stakeAddressList.size()); + log.info( + "fetch {} epoch_stake by koios api: {} ms, with stake_address input size {}", + epochStakeSize, + System.currentTimeMillis() - curTime, + stakeAddressList.size()); Map poolHashMap = getPoolHashMap(accountHistoryList); @@ -74,33 +78,38 @@ public CompletableFuture fetchData(List stakeAddressList) { Map epochStakeCheckpointMap = getEpochStakeCheckpointMap(stakeAddressList); - List saveData = accountHistoryList.parallelStream() - .flatMap(accountHistory -> { - var epochStakeCheckpoint = epochStakeCheckpointMap.get(accountHistory.getStakeAddress()); - if (epochStakeCheckpoint == null) { - return Stream.empty(); - } - - return accountHistory.getHistory().stream() - .filter(accountHistoryInner -> - accountHistoryInner.getEpochNo() > epochStakeCheckpoint.getEpochCheckpoint() - && accountHistoryInner.getEpochNo() < currentEpoch + 2) - .map(accountHistoryInner -> - EpochStake.builder() - .epochNo(accountHistoryInner.getEpochNo()) - .addr(stakeAddressMap.get(accountHistory.getStakeAddress())) - .pool(poolHashMap.get(accountHistoryInner.getPoolId())) - .amount(new BigInteger(accountHistoryInner.getActiveStake())).build() - ); - }) - .collect(Collectors.toList()); + List saveData = + accountHistoryList.parallelStream() + .flatMap( + accountHistory -> { + var epochStakeCheckpoint = + epochStakeCheckpointMap.get(accountHistory.getStakeAddress()); + if (epochStakeCheckpoint == null) { + return Stream.empty(); + } + + return accountHistory.getHistory().stream() + .filter( + accountHistoryInner -> + accountHistoryInner.getEpochNo() + > epochStakeCheckpoint.getEpochCheckpoint() + && accountHistoryInner.getEpochNo() < currentEpoch + 2) + .map( + accountHistoryInner -> + EpochStake.builder() + .epochNo(accountHistoryInner.getEpochNo()) + .addr(stakeAddressMap.get(accountHistory.getStakeAddress())) + .pool(poolHashMap.get(accountHistoryInner.getPoolId())) + .amount(new BigInteger(accountHistoryInner.getActiveStake())) + .build()); + }) + .collect(Collectors.toList()); epochStakeCheckpointMap .values() .forEach(epochCheckpoint -> epochCheckpoint.setEpochCheckpoint(currentEpoch)); jooqEpochStakeRepository.saveAll(saveData); - jooqEpochStakeCheckpointRepository.saveAll( - epochStakeCheckpointMap.values().stream().toList()); + jooqEpochStakeCheckpointRepository.saveAll(epochStakeCheckpointMap.values().stream().toList()); return CompletableFuture.completedFuture(Boolean.TRUE); } @@ -108,42 +117,42 @@ public CompletableFuture fetchData(List stakeAddressList) { private Map getEpochStakeCheckpointMap( List stakeAddressList) { // get epochStakeCheckpointMap with stakeAddressList - Map epochStakeCheckpointMap = epochStakeCheckpointRepository - .findByStakeAddressIn(stakeAddressList) - .stream() - .collect(Collectors.toMap(EpochStakeCheckpoint::getStakeAddress, Function.identity())); + Map epochStakeCheckpointMap = + epochStakeCheckpointRepository.findByStakeAddressIn(stakeAddressList).stream() + .collect(Collectors.toMap(EpochStakeCheckpoint::getStakeAddress, Function.identity())); // if an stake address not in checkpoint table, // create a epochStakeCheckpoint with stake address equal to that and epoch_checkpoint = 0 - List epochStakeCheckpoints = stakeAddressList - .stream() - .filter( - stakeAddress -> !epochStakeCheckpointMap.containsKey(stakeAddress)) - .map(stakeAddress -> EpochStakeCheckpoint.builder() - .stakeAddress(stakeAddress) - .epochCheckpoint(0) - .build()) - .collect(Collectors.toList()); + List epochStakeCheckpoints = + stakeAddressList.stream() + .filter(stakeAddress -> !epochStakeCheckpointMap.containsKey(stakeAddress)) + .map( + stakeAddress -> + EpochStakeCheckpoint.builder() + .stakeAddress(stakeAddress) + .epochCheckpoint(0) + .build()) + .collect(Collectors.toList()); // put all into result - epochStakeCheckpointMap.putAll(epochStakeCheckpoints.stream().collect( - Collectors.toMap(EpochStakeCheckpoint::getStakeAddress, Function.identity()))); + epochStakeCheckpointMap.putAll( + epochStakeCheckpoints.stream() + .collect(Collectors.toMap(EpochStakeCheckpoint::getStakeAddress, Function.identity()))); return epochStakeCheckpointMap; } private Map getStakeAddressMap(List stakeAddressList) { - return stakeAddressRepository - .findByViewIn(stakeAddressList) - .stream() + return stakeAddressRepository.findByViewIn(stakeAddressList).stream() .collect(Collectors.toMap(StakeAddress::getView, Function.identity())); } private Map getPoolHashMap(List accountHistoryList) { - List poolIds = accountHistoryList.stream() - .flatMap(accountHistory -> accountHistory.getHistory().stream()) - .map(AccountHistoryInner::getPoolId) - .toList(); + List poolIds = + accountHistoryList.stream() + .flatMap(accountHistory -> accountHistory.getHistory().stream()) + .map(AccountHistoryInner::getPoolId) + .toList(); return poolHashRepository.findByViewIn(poolIds).stream() .collect(Collectors.toMap(PoolHash::getView, Function.identity())); @@ -158,9 +167,7 @@ private Map getPoolHashMap(List accountHistory */ private List getAccountHistoryList(List stakeAddressList) throws ApiException { - return koiosClient.accountService() - .getAccountHistory(stakeAddressList, null, null) - .getValue(); + return koiosClient.accountService().getAccountHistory(stakeAddressList, null, null).getValue(); } /** @@ -175,17 +182,16 @@ public List getStakeAddressListNeedFetchData(List stakeAddressLi throws ApiException { Integer currentEpoch = epochService.getCurrentEpoch(); - Map epochStakeCheckpointMap = epochStakeCheckpointRepository - .findByStakeAddressIn(stakeAddressList) - .stream() - .collect(Collectors.toMap(EpochStakeCheckpoint::getStakeAddress, Function.identity())); + Map epochStakeCheckpointMap = + epochStakeCheckpointRepository.findByStakeAddressIn(stakeAddressList).stream() + .collect(Collectors.toMap(EpochStakeCheckpoint::getStakeAddress, Function.identity())); return stakeAddressList.stream() - .filter(stakeAddress -> - ((!epochStakeCheckpointMap.containsKey(stakeAddress)) - || epochStakeCheckpointMap.get(stakeAddress).getEpochCheckpoint() < currentEpoch - )) + .filter( + stakeAddress -> + ((!epochStakeCheckpointMap.containsKey(stakeAddress)) + || epochStakeCheckpointMap.get(stakeAddress).getEpochCheckpoint() + < currentEpoch)) .collect(Collectors.toList()); } - } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java index 47945410..78b04eb8 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java @@ -19,6 +19,8 @@ import org.springframework.transaction.annotation.Transactional; import io.micrometer.common.util.StringUtils; +import rest.koios.client.backend.api.base.exception.ApiException; + import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory; import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint; import org.cardanofoundation.explorer.rewards.config.KoiosClient; @@ -28,7 +30,6 @@ import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolHistoryRepository; import org.cardanofoundation.explorer.rewards.service.EpochService; import org.cardanofoundation.explorer.rewards.service.PoolHistoryFetchingService; -import rest.koios.client.backend.api.base.exception.ApiException; @Service @FieldDefaults(level = AccessLevel.PRIVATE) @@ -60,30 +61,37 @@ public CompletableFuture fetchData(String poolId) { var poolHistoryCheckpoint = poolHistoryCheckpointRepository.findByView(poolId); Map poolHistoryList = - dataFromKoios.stream().filter(poolHistory -> poolHistory.getEpochNo() < currentEpoch) - .map(poolHistory -> - PoolHistory.builder() - .epochNo(poolHistory.getEpochNo()) - .activeStake( - StringUtils.isNotBlank(poolHistory.getActiveStake()) ? new BigInteger( - poolHistory.getActiveStake()) : null) - .activeStakePct(poolHistory.getActiveStakePct()) - .blockCnt(poolHistory.getBlockCnt()) - .poolFees(StringUtils.isNotBlank(poolHistory.getPoolFees()) ? new BigInteger( - poolHistory.getPoolFees()) : null) - .delegatorCnt(poolHistory.getDelegatorCnt()) - .delegatorRewards( - StringUtils.isNotBlank(poolHistory.getDelegRewards()) ? new BigInteger( - poolHistory.getDelegRewards()) : null) - .epochRos(poolHistory.getEpochRos()) - .fixedCost(StringUtils.isNotBlank(poolHistory.getFixedCost()) ? new BigInteger( - poolHistory.getFixedCost()) : null) - .margin(poolHistory.getMargin()) - .saturationPct(poolHistory.getSaturationPct()) - .poolId(poolHash.get().getId()) - .build() - ).collect( - Collectors.toMap(PoolHistory::getEpochNo, Function.identity())); + dataFromKoios.stream() + .filter(poolHistory -> poolHistory.getEpochNo() < currentEpoch) + .map( + poolHistory -> + PoolHistory.builder() + .epochNo(poolHistory.getEpochNo()) + .activeStake( + StringUtils.isNotBlank(poolHistory.getActiveStake()) + ? new BigInteger(poolHistory.getActiveStake()) + : null) + .activeStakePct(poolHistory.getActiveStakePct()) + .blockCnt(poolHistory.getBlockCnt()) + .poolFees( + StringUtils.isNotBlank(poolHistory.getPoolFees()) + ? new BigInteger(poolHistory.getPoolFees()) + : null) + .delegatorCnt(poolHistory.getDelegatorCnt()) + .delegatorRewards( + StringUtils.isNotBlank(poolHistory.getDelegRewards()) + ? new BigInteger(poolHistory.getDelegRewards()) + : null) + .epochRos(poolHistory.getEpochRos()) + .fixedCost( + StringUtils.isNotBlank(poolHistory.getFixedCost()) + ? new BigInteger(poolHistory.getFixedCost()) + : null) + .margin(poolHistory.getMargin()) + .saturationPct(poolHistory.getSaturationPct()) + .poolId(poolHash.get().getId()) + .build()) + .collect(Collectors.toMap(PoolHistory::getEpochNo, Function.identity())); var poolHistoryCheck = poolHistoryList.get(currentEpoch - 2); boolean isSpendableReward = @@ -93,26 +101,27 @@ public CompletableFuture fetchData(String poolId) { || poolHistoryCheck.getEpochRos() != 0.0; if (poolHistoryCheckpoint.isPresent()) { - jooqPoolHistoryRepository.saveAll(poolHistoryList.values().stream().filter( - poolHistory -> poolHistory.getEpochNo() > poolHistoryCheckpoint.get() - .getEpochCheckpoint() - 2).collect(Collectors.toList())); + jooqPoolHistoryRepository.saveAll( + poolHistoryList.values().stream() + .filter( + poolHistory -> + poolHistory.getEpochNo() + > poolHistoryCheckpoint.get().getEpochCheckpoint() - 2) + .collect(Collectors.toList())); var checkpoint = poolHistoryCheckpoint.get(); checkpoint.setEpochCheckpoint(currentEpoch - 1); checkpoint.setIsSpendableReward( - isSpendableReward || poolHistoryCheck.getBlockCnt() == 0 ? Boolean.TRUE - : Boolean.FALSE); + isSpendableReward || poolHistoryCheck.getBlockCnt() == 0 ? Boolean.TRUE : Boolean.FALSE); jooqPoolHistoryCheckpointRepository.saveAll(List.of(checkpoint)); } else { jooqPoolHistoryRepository.saveAll(poolHistoryList.values().stream().toList()); - var checkpoint = PoolHistoryCheckpoint.builder().view(poolId) - .epochCheckpoint(currentEpoch - 1) - .build(); + var checkpoint = + PoolHistoryCheckpoint.builder().view(poolId).epochCheckpoint(currentEpoch - 1).build(); checkpoint.setIsSpendableReward(isSpendableReward ? Boolean.TRUE : Boolean.FALSE); - jooqPoolHistoryCheckpointRepository.saveAll( - List.of(checkpoint)); + jooqPoolHistoryCheckpointRepository.saveAll(List.of(checkpoint)); } return CompletableFuture.completedFuture(Boolean.TRUE); @@ -126,11 +135,8 @@ public CompletableFuture fetchData(String poolId) { * @throws ApiException */ private List getPoolHistoryList( - String poolId) - throws ApiException { - return koiosClient.poolService() - .getPoolHistory(poolId, null) - .getValue(); + String poolId) throws ApiException { + return koiosClient.poolService().getPoolHistory(poolId, null).getValue(); } /** @@ -144,19 +150,16 @@ private List getPoolHistor public List getPoolIdListNeedFetchData(List poolIds) throws ApiException { int currentEpoch = epochService.getCurrentEpoch(); - Map poolHistoryCheckpointMap = poolHistoryCheckpointRepository - .findByViewIn(poolIds) - .stream() - .collect(Collectors.toMap(PoolHistoryCheckpoint::getView, Function.identity())); + Map poolHistoryCheckpointMap = + poolHistoryCheckpointRepository.findByViewIn(poolIds).stream() + .collect(Collectors.toMap(PoolHistoryCheckpoint::getView, Function.identity())); return poolIds.stream() - .filter(poolId -> ( - (!poolHistoryCheckpointMap.containsKey(poolId)) - || poolHistoryCheckpointMap.get(poolId).getEpochCheckpoint() - < currentEpoch - 1 - || !poolHistoryCheckpointMap.get(poolId).getIsSpendableReward() - )) + .filter( + poolId -> + ((!poolHistoryCheckpointMap.containsKey(poolId)) + || poolHistoryCheckpointMap.get(poolId).getEpochCheckpoint() < currentEpoch - 1 + || !poolHistoryCheckpointMap.get(poolId).getIsSpendableReward())) .collect(Collectors.toList()); } - } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImpl.java index d4a6092f..ddd4b20f 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImpl.java @@ -18,16 +18,17 @@ import org.springframework.transaction.annotation.Transactional; import io.micrometer.common.util.StringUtils; +import rest.koios.client.backend.api.base.exception.ApiException; + import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint; import org.cardanofoundation.explorer.rewards.config.KoiosClient; +import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolInfoCheckpointRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolInfoRepository; -import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.service.EpochService; import org.cardanofoundation.explorer.rewards.service.PoolInfoFetchingService; -import rest.koios.client.backend.api.base.exception.ApiException; @Service @FieldDefaults(level = AccessLevel.PRIVATE) @@ -53,30 +54,45 @@ public CompletableFuture fetchData(List poolIds) { int currentEpoch = epochService.getCurrentEpoch(); - var poolHashMap = poolHashRepository.findByViewIn(poolIds).stream().collect(Collectors.toMap( - PoolHash::getView, Function.identity())); + var poolHashMap = + poolHashRepository.findByViewIn(poolIds).stream() + .collect(Collectors.toMap(PoolHash::getView, Function.identity())); if (poolHashMap.size() != poolIds.size()) { return CompletableFuture.completedFuture(Boolean.FALSE); } - List poolInfoList = dataFromKoios.stream().map(poolInfo -> - PoolInfo.builder().poolId(poolHashMap.get(poolInfo.getPoolIdBech32()).getId()) - .activeStake(StringUtils.isNotBlank(poolInfo.getActiveStake()) ? new BigInteger( - poolInfo.getActiveStake()) : null) - .fetchedAtEpoch(currentEpoch) - .liveStake(StringUtils.isNotBlank(poolInfo.getLiveStake()) ? new BigInteger( - poolInfo.getLiveStake()) : null) - .liveSaturation(poolInfo.getLiveSaturation()).build()) - .collect(Collectors.toList()); - - log.info("fetch {} pool_info by koios api: {} ms, with poolIds input size {}", - poolInfoList.size(), System.currentTimeMillis() - curTime, poolIds.size()); - - List poolInfoCheckpointList = poolIds.stream() - .map(poolId -> PoolInfoCheckpoint.builder() - .view(poolId).epochCheckpoint(currentEpoch).build()) - .collect(Collectors.toList()); + List poolInfoList = + dataFromKoios.stream() + .map( + poolInfo -> + PoolInfo.builder() + .poolId(poolHashMap.get(poolInfo.getPoolIdBech32()).getId()) + .activeStake( + StringUtils.isNotBlank(poolInfo.getActiveStake()) + ? new BigInteger(poolInfo.getActiveStake()) + : null) + .fetchedAtEpoch(currentEpoch) + .liveStake( + StringUtils.isNotBlank(poolInfo.getLiveStake()) + ? new BigInteger(poolInfo.getLiveStake()) + : null) + .liveSaturation(poolInfo.getLiveSaturation()) + .build()) + .collect(Collectors.toList()); + + log.info( + "fetch {} pool_info by koios api: {} ms, with poolIds input size {}", + poolInfoList.size(), + System.currentTimeMillis() - curTime, + poolIds.size()); + + List poolInfoCheckpointList = + poolIds.stream() + .map( + poolId -> + PoolInfoCheckpoint.builder().view(poolId).epochCheckpoint(currentEpoch).build()) + .collect(Collectors.toList()); jooqPoolInfoCheckpointRepository.saveAll(poolInfoCheckpointList); jooqPoolInfoRepository.saveAll(poolInfoList); @@ -92,11 +108,7 @@ public CompletableFuture fetchData(List poolIds) { * @throws ApiException */ private List getPoolInfoList( - List poolIdList) - throws ApiException { - return koiosClient.poolService() - .getPoolInformation(poolIdList, null) - .getValue(); + List poolIdList) throws ApiException { + return koiosClient.poolService().getPoolInformation(poolIdList, null).getValue(); } - } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImpl.java index a33d9d25..5791f8cf 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImpl.java @@ -19,6 +19,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import rest.koios.client.backend.api.account.model.AccountReward; +import rest.koios.client.backend.api.account.model.AccountRewards; +import rest.koios.client.backend.api.base.exception.ApiException; + import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; import org.cardanofoundation.explorer.consumercommon.entity.Reward; import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint; @@ -32,9 +36,6 @@ import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQRewardRepository; import org.cardanofoundation.explorer.rewards.service.EpochService; import org.cardanofoundation.explorer.rewards.service.RewardFetchingService; -import rest.koios.client.backend.api.account.model.AccountReward; -import rest.koios.client.backend.api.account.model.AccountRewards; -import rest.koios.client.backend.api.base.exception.ApiException; @Service @FieldDefaults(level = AccessLevel.PRIVATE) @@ -62,16 +63,18 @@ public CompletableFuture fetchData(List stakeAddressList) { List accountRewardsList = getAccountRewards(stakeAddressList); - int rewardSize = accountRewardsList - .parallelStream() - .mapToInt(accountHistory -> accountHistory.getRewards().size()) - .sum(); + int rewardSize = + accountRewardsList.parallelStream() + .mapToInt(accountHistory -> accountHistory.getRewards().size()) + .sum(); - log.info("fetch {} reward by koios api: {} ms, with stake_address input size {}", - rewardSize, System.currentTimeMillis() - curTime, stakeAddressList.size()); + log.info( + "fetch {} reward by koios api: {} ms, with stake_address input size {}", + rewardSize, + System.currentTimeMillis() - curTime, + stakeAddressList.size()); - Map rewardCheckpointMap = getRewardCheckpointMap( - stakeAddressList); + Map rewardCheckpointMap = getRewardCheckpointMap(stakeAddressList); Map stakeAddressMap = getStakeAddressMap(stakeAddressList); @@ -87,21 +90,23 @@ public CompletableFuture fetchData(List stakeAddressList) { for (var accountReward : accountRewards.getRewards()) { // if earned epoch < epoch checkpoint, data was saved - // if earned epoch > current epoch (current epoch value in local < curren epoch value in koios), - // data should not be saved + // if earned epoch > current epoch (current epoch value in local < curren epoch value in + // koios), + // data should not be saved if (accountReward.getEarnedEpoch() < rewardCheckpoint.getEpochCheckpoint() || accountReward.getEarnedEpoch() > currentEpoch) { continue; } - Reward reward = Reward.builder() - .pool(poolHashMap.get(accountReward.getPoolId())) - .addr(stakeAddressMap.get(accountRewards.getStakeAddress())) - .amount(new BigInteger(accountReward.getAmount())) - .earnedEpoch(accountReward.getEarnedEpoch()) - .spendableEpoch(accountReward.getSpendableEpoch()) - .type(RewardType.fromValue(accountReward.getType())) - .build(); + Reward reward = + Reward.builder() + .pool(poolHashMap.get(accountReward.getPoolId())) + .addr(stakeAddressMap.get(accountRewards.getStakeAddress())) + .amount(new BigInteger(accountReward.getAmount())) + .earnedEpoch(accountReward.getEarnedEpoch()) + .spendableEpoch(accountReward.getSpendableEpoch()) + .type(RewardType.fromValue(accountReward.getType())) + .build(); result.add(reward); } @@ -114,24 +119,26 @@ public CompletableFuture fetchData(List stakeAddressList) { jooqRewardRepository.saveAll(result); jooqRewardCheckpointRepository.saveAll(rewardCheckpointMap.values().stream().toList()); - log.info("Save {} reward record from koios api: {} ms, with stake_address input size {}", - result.size(), System.currentTimeMillis() - curTime, stakeAddressList.size()); + log.info( + "Save {} reward record from koios api: {} ms, with stake_address input size {}", + result.size(), + System.currentTimeMillis() - curTime, + stakeAddressList.size()); return CompletableFuture.completedFuture(Boolean.TRUE); } private Map getStakeAddressMap(List stakeAddressList) { - return stakeAddressRepository - .findByViewIn(stakeAddressList) - .stream() + return stakeAddressRepository.findByViewIn(stakeAddressList).stream() .collect(Collectors.toMap(StakeAddress::getView, Function.identity())); } private Map getPoolHashMap(List accountRewardsList) { - List poolIds = accountRewardsList.stream() - .flatMap(accountRewards -> accountRewards.getRewards().stream()) - .map(AccountReward::getPoolId) - .toList(); + List poolIds = + accountRewardsList.stream() + .flatMap(accountRewards -> accountRewards.getRewards().stream()) + .map(AccountReward::getPoolId) + .toList(); return poolHashRepository.findByViewIn(poolIds).stream() .collect(Collectors.toMap(PoolHash::getView, Function.identity())); @@ -146,34 +153,32 @@ private Map getPoolHashMap(List accountRewards */ private List getAccountRewards(List stakeAddressList) throws ApiException { - return koiosClient - .accountService() - .getAccountRewards(stakeAddressList, null, null) - .getValue(); + return koiosClient.accountService().getAccountRewards(stakeAddressList, null, null).getValue(); } private Map getRewardCheckpointMap(List stakeAddressList) { // get rewardCheckpointMap with stakeAddressList - Map rewardCheckpointMap = rewardCheckpointRepository - .findByStakeAddressIn(stakeAddressList) - .stream() - .collect(Collectors.toMap(RewardCheckpoint::getStakeAddress, Function.identity())); + Map rewardCheckpointMap = + rewardCheckpointRepository.findByStakeAddressIn(stakeAddressList).stream() + .collect(Collectors.toMap(RewardCheckpoint::getStakeAddress, Function.identity())); // if an stake address not in checkpoint table, // create a rewardCheckpoint with stake address equal to that and epoch_checkpoint = 0 - List rewardCheckpoints = stakeAddressList - .stream() - .filter( - stakeAddress -> !rewardCheckpointMap.containsKey(stakeAddress)) - .map(stakeAddress -> RewardCheckpoint.builder() - .stakeAddress(stakeAddress) - .epochCheckpoint(0) - .build()) - .collect(Collectors.toList()); + List rewardCheckpoints = + stakeAddressList.stream() + .filter(stakeAddress -> !rewardCheckpointMap.containsKey(stakeAddress)) + .map( + stakeAddress -> + RewardCheckpoint.builder() + .stakeAddress(stakeAddress) + .epochCheckpoint(0) + .build()) + .collect(Collectors.toList()); // put all into result - rewardCheckpointMap.putAll(rewardCheckpoints.stream().collect( - Collectors.toMap(RewardCheckpoint::getStakeAddress, Function.identity()))); + rewardCheckpointMap.putAll( + rewardCheckpoints.stream() + .collect(Collectors.toMap(RewardCheckpoint::getStakeAddress, Function.identity()))); return rewardCheckpointMap; } @@ -186,19 +191,20 @@ private Map getRewardCheckpointMap(List stakeA * @return */ @Override - public List getStakeAddressListNeedFetchData(List stakeAddressList) throws ApiException{ + public List getStakeAddressListNeedFetchData(List stakeAddressList) + throws ApiException { int currentEpoch = epochService.getCurrentEpoch(); - Map rewardCheckpointMap = rewardCheckpointRepository - .findByStakeAddressIn(stakeAddressList) - .stream() - .collect(Collectors.toMap(RewardCheckpoint::getStakeAddress, Function.identity())); + Map rewardCheckpointMap = + rewardCheckpointRepository.findByStakeAddressIn(stakeAddressList).stream() + .collect(Collectors.toMap(RewardCheckpoint::getStakeAddress, Function.identity())); return stakeAddressList.stream() - .filter(stakeAddress -> ( - (!rewardCheckpointMap.containsKey(stakeAddress)) - || rewardCheckpointMap.get(stakeAddress).getEpochCheckpoint() < currentEpoch - 1 - )) + .filter( + stakeAddress -> + ((!rewardCheckpointMap.containsKey(stakeAddress)) + || rewardCheckpointMap.get(stakeAddress).getEpochCheckpoint() + < currentEpoch - 1)) .collect(Collectors.toList()); } } diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/util/CommonUtils.java b/src/main/java/org/cardanofoundation/explorer/rewards/util/CommonUtils.java index 7be4f0fe..837fe027 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/util/CommonUtils.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/util/CommonUtils.java @@ -5,11 +5,10 @@ public class CommonUtils { - private CommonUtils() { - } + private CommonUtils() {} - public static void setNullableValue(PreparedStatement ps, int parameterIndex, Object value, int sqlType) - throws SQLException { + public static void setNullableValue( + PreparedStatement ps, int parameterIndex, Object value, int sqlType) throws SQLException { if (value != null) { ps.setObject(parameterIndex, value, sqlType); } else { diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/ExplorerRewardsApplicationTests.java b/src/test/java/org/cardanofoundation/explorer/rewards/ExplorerRewardsApplicationTests.java index bcadc770..8206ed53 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/ExplorerRewardsApplicationTests.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/ExplorerRewardsApplicationTests.java @@ -7,6 +7,5 @@ @SpringBootTest class ExplorerRewardsApplicationTests { @Test - void contextLoads() { - } + void contextLoads() {} } diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/AdaPostsConcurrentFetchingTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/AdaPostsConcurrentFetchingTest.java index 5b9dcd5d..2b734b3f 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/AdaPostsConcurrentFetchingTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/AdaPostsConcurrentFetchingTest.java @@ -1,28 +1,28 @@ package org.cardanofoundation.explorer.rewards.concurrent; -import org.cardanofoundation.explorer.rewards.service.AdaPotsFetchingService; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CompletableFuture; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.when; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.cardanofoundation.explorer.rewards.service.AdaPotsFetchingService; + @ExtendWith(MockitoExtension.class) class AdaPostsConcurrentFetchingTest { - @Mock - private AdaPotsFetchingService adaPotsFetchingService; - @InjectMocks - private AdaPostsConcurrentFetching adaPostsConcurrentFetching; + @Mock private AdaPotsFetchingService adaPotsFetchingService; + @InjectMocks private AdaPostsConcurrentFetching adaPostsConcurrentFetching; @Test void fetchDataConcurrently_NoEpochs_ReturnsTrue() { diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetchingTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetchingTest.java index 9804a8a6..80d6dd33 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetchingTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetchingTest.java @@ -1,28 +1,28 @@ package org.cardanofoundation.explorer.rewards.concurrent; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; -import org.cardanofoundation.explorer.rewards.service.EpochFetchingService; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.when; import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.when; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.rewards.service.EpochFetchingService; @ExtendWith(MockitoExtension.class) class EpochConcurrentFetchingTest { - @Mock - private EpochFetchingService epochFetchingService; - @InjectMocks - private EpochConcurrentFetching epochConcurrentFetching; + @Mock private EpochFetchingService epochFetchingService; + @InjectMocks private EpochConcurrentFetching epochConcurrentFetching; @Test void fetchDataConcurrently_NoEpochs_ReturnsTrue() { @@ -44,7 +44,7 @@ void fetchDataConcurrently_FetchDataSuccessFully_ReturnsTrue() { when(epochFetchingService.fetchData(314)) .thenReturn(CompletableFuture.completedFuture(Epoch.builder().no(314).build())); when(epochFetchingService.fetchData(315)) - .thenReturn(CompletableFuture.completedFuture(Epoch.builder().no(315).build())); + .thenReturn(CompletableFuture.completedFuture(Epoch.builder().no(315).build())); // Run the test final List result = epochConcurrentFetching.fetchDataConcurrently(epochs); @@ -65,5 +65,4 @@ void fetchDataConcurrently_EpochsNeedFetchDataIsEmpty_ReturnsTrue() { // Verify the results assertEquals(0, result.size()); } - } diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochStakeConcurrentFetchingTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochStakeConcurrentFetchingTest.java index bf7174d1..9794a510 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochStakeConcurrentFetchingTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochStakeConcurrentFetchingTest.java @@ -1,31 +1,31 @@ package org.cardanofoundation.explorer.rewards.concurrent; -import org.cardanofoundation.explorer.rewards.service.EpochStakeFetchingService; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; + import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import rest.koios.client.backend.api.base.exception.ApiException; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CompletableFuture; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.when; +import org.cardanofoundation.explorer.rewards.service.EpochStakeFetchingService; @ExtendWith(MockitoExtension.class) class EpochStakeConcurrentFetchingTest { - @Mock - private EpochStakeFetchingService epochStakeFetchingService; + @Mock private EpochStakeFetchingService epochStakeFetchingService; - @InjectMocks - private EpochStakeConcurrentFetching epochStakeConcurrentFetching; + @InjectMocks private EpochStakeConcurrentFetching epochStakeConcurrentFetching; @Test void fetchDataConcurrently_NoStakeAddresses_ReturnsTrue() { @@ -35,11 +35,11 @@ void fetchDataConcurrently_NoStakeAddresses_ReturnsTrue() { } @Test - void fetchDataConcurrently_ApiExceptionOccurs_ReturnsFalse() - throws Exception { - List stakeAddressList = List.of( - "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); + void fetchDataConcurrently_ApiExceptionOccurs_ReturnsFalse() throws Exception { + List stakeAddressList = + List.of( + "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", + "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); when(epochStakeFetchingService.getStakeAddressListNeedFetchData(stakeAddressList)) .thenThrow(ApiException.class); @@ -52,9 +52,10 @@ void fetchDataConcurrently_ApiExceptionOccurs_ReturnsFalse() @Test void fetchDataConcurrently_FetchDataSuccessfully_ReturnsTrue() throws Exception { // Setup - List stakeAddressList = List.of( - "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); + List stakeAddressList = + List.of( + "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", + "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); epochStakeConcurrentFetching.setSubListSize(5); @@ -65,19 +66,18 @@ void fetchDataConcurrently_FetchDataSuccessfully_ReturnsTrue() throws Exception .thenReturn(CompletableFuture.completedFuture(Boolean.TRUE)); // Run the test - final Boolean result = epochStakeConcurrentFetching.fetchDataConcurrently( - stakeAddressList); + final Boolean result = epochStakeConcurrentFetching.fetchDataConcurrently(stakeAddressList); // Verify the results assertThat(result).isTrue(); } @Test - void fetchDataConcurrently_StakeAddressListNeedFetchDataIsEmpty_ReturnsTrue() - throws Exception { - List stakeAddressList = List.of( - "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); + void fetchDataConcurrently_StakeAddressListNeedFetchDataIsEmpty_ReturnsTrue() throws Exception { + List stakeAddressList = + List.of( + "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", + "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); when(epochStakeFetchingService.getStakeAddressListNeedFetchData(stakeAddressList)) .thenReturn(Collections.emptyList()); @@ -90,17 +90,18 @@ void fetchDataConcurrently_StakeAddressListNeedFetchDataIsEmpty_ReturnsTrue() @Test void fetchDataConcurrently_FetchDataFailed_ReturnsFalse() throws Exception { // Setup - List stakeAddressList = List.of( - "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); + List stakeAddressList = + List.of( + "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", + "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); epochStakeConcurrentFetching.setSubListSize(5); when(epochStakeFetchingService.getStakeAddressListNeedFetchData(anyList())) .thenReturn(stakeAddressList); - when(epochStakeFetchingService.fetchData(anyList())).thenReturn(CompletableFuture.completedFuture(Boolean.FALSE)); + when(epochStakeFetchingService.fetchData(anyList())) + .thenReturn(CompletableFuture.completedFuture(Boolean.FALSE)); // Run the test - final Boolean result = epochStakeConcurrentFetching.fetchDataConcurrently( - stakeAddressList); + final Boolean result = epochStakeConcurrentFetching.fetchDataConcurrently(stakeAddressList); // Verify the results assertFalse(result); } diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/PoolHistoryConcurrentFetchingTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/PoolHistoryConcurrentFetchingTest.java index 181c7e0c..58e54299 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/PoolHistoryConcurrentFetchingTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/PoolHistoryConcurrentFetchingTest.java @@ -1,31 +1,30 @@ package org.cardanofoundation.explorer.rewards.concurrent; -import org.cardanofoundation.explorer.rewards.service.PoolHistoryFetchingService; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CompletableFuture; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.cardanofoundation.explorer.rewards.service.PoolHistoryFetchingService; + @ExtendWith(MockitoExtension.class) class PoolHistoryConcurrentFetchingTest { - @Mock - private PoolHistoryFetchingService poolHistoryFetchingService; + @Mock private PoolHistoryFetchingService poolHistoryFetchingService; - @InjectMocks - private PoolHistoryConcurrentFetching poolHistoryConcurrentFetching; + @InjectMocks private PoolHistoryConcurrentFetching poolHistoryConcurrentFetching; @Test void fetchDataConcurrently_NoPoolIds_ReturnsTrue() { @@ -37,27 +36,26 @@ void fetchDataConcurrently_NoPoolIds_ReturnsTrue() { @Test void fetchDataConcurrently_FetchDataSuccessfully_ReturnsTrue() throws Exception { // Setup - List poolIds = List.of( - "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", - "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); - when(poolHistoryFetchingService.getPoolIdListNeedFetchData(poolIds)) - .thenReturn(poolIds); + List poolIds = + List.of( + "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", + "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); + when(poolHistoryFetchingService.getPoolIdListNeedFetchData(poolIds)).thenReturn(poolIds); when(poolHistoryFetchingService.fetchData(anyString())) .thenReturn(CompletableFuture.completedFuture(true)); // Run the test - final Boolean result = poolHistoryConcurrentFetching.fetchDataConcurrently( - poolIds); + final Boolean result = poolHistoryConcurrentFetching.fetchDataConcurrently(poolIds); // Verify the results assertThat(result).isTrue(); } @Test - void fetchDataConcurrently_PoolIdListNeedFetchDataIsEmpty_ReturnsTrue() - throws Exception { + void fetchDataConcurrently_PoolIdListNeedFetchDataIsEmpty_ReturnsTrue() throws Exception { // Setup - List poolIds = List.of( + List poolIds = + List.of( "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); when(poolHistoryFetchingService.getPoolIdListNeedFetchData(poolIds)) @@ -73,17 +71,16 @@ void fetchDataConcurrently_PoolIdListNeedFetchDataIsEmpty_ReturnsTrue() @Test void fetchDataConcurrently_FetchDataFailed_ReturnsFalse() throws Exception { // Setup - List poolIds = List.of( - "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", - "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); - when(poolHistoryFetchingService.getPoolIdListNeedFetchData(poolIds)) - .thenReturn(poolIds); + List poolIds = + List.of( + "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", + "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); + when(poolHistoryFetchingService.getPoolIdListNeedFetchData(poolIds)).thenReturn(poolIds); - when(poolHistoryFetchingService.fetchData(anyString())).thenReturn( - CompletableFuture.completedFuture(Boolean.FALSE)); + when(poolHistoryFetchingService.fetchData(anyString())) + .thenReturn(CompletableFuture.completedFuture(Boolean.FALSE)); // Run the test - final Boolean result = poolHistoryConcurrentFetching.fetchDataConcurrently( - poolIds); + final Boolean result = poolHistoryConcurrentFetching.fetchDataConcurrently(poolIds); // Verify the results assertFalse(result); } diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/PoolInfoConcurrentFetchingTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/PoolInfoConcurrentFetchingTest.java index 510f8e5c..92876018 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/PoolInfoConcurrentFetchingTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/PoolInfoConcurrentFetchingTest.java @@ -1,29 +1,29 @@ package org.cardanofoundation.explorer.rewards.concurrent; -import org.cardanofoundation.explorer.rewards.service.PoolInfoFetchingService; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.when; import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.when; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.cardanofoundation.explorer.rewards.service.PoolInfoFetchingService; @ExtendWith(MockitoExtension.class) class PoolInfoConcurrentFetchingTest { - @Mock - private PoolInfoFetchingService poolInfoFetchingService; + @Mock private PoolInfoFetchingService poolInfoFetchingService; - @InjectMocks - private PoolInfoConcurrentFetching poolInfoConcurrentFetching; + @InjectMocks private PoolInfoConcurrentFetching poolInfoConcurrentFetching; @Test void fetchDataConcurrently_NoStakeAddresses_ReturnsTrue() { @@ -35,9 +35,10 @@ void fetchDataConcurrently_NoStakeAddresses_ReturnsTrue() { @Test void fetchDataConcurrently_FetchDataSuccessfully_ReturnsTrue() throws Exception { // Setup - List poolIds = List.of( - "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", - "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); + List poolIds = + List.of( + "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", + "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); poolInfoConcurrentFetching.setSubListSize(5); @@ -45,8 +46,7 @@ void fetchDataConcurrently_FetchDataSuccessfully_ReturnsTrue() throws Exception .thenReturn(CompletableFuture.completedFuture(true)); // Run the test - final Boolean result = poolInfoConcurrentFetching.fetchDataConcurrently( - poolIds); + final Boolean result = poolInfoConcurrentFetching.fetchDataConcurrently(poolIds); // Verify the results assertTrue(result); @@ -55,16 +55,17 @@ void fetchDataConcurrently_FetchDataSuccessfully_ReturnsTrue() throws Exception @Test void fetchDataConcurrently_FetchDataFailed_ReturnsFalse() throws Exception { // Setup - List poolIds = List.of( - "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", - "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); + List poolIds = + List.of( + "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", + "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); poolInfoConcurrentFetching.setSubListSize(5); - when(poolInfoFetchingService.fetchData(anyList())).thenReturn(CompletableFuture.completedFuture(Boolean.FALSE)); + when(poolInfoFetchingService.fetchData(anyList())) + .thenReturn(CompletableFuture.completedFuture(Boolean.FALSE)); // Run the test - final Boolean result = poolInfoConcurrentFetching.fetchDataConcurrently( - poolIds); + final Boolean result = poolInfoConcurrentFetching.fetchDataConcurrently(poolIds); // Verify the results assertFalse(result); } diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/RewardConcurrentFetchingTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/RewardConcurrentFetchingTest.java index 72d904b4..cfd530a6 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/RewardConcurrentFetchingTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/RewardConcurrentFetchingTest.java @@ -1,30 +1,30 @@ package org.cardanofoundation.explorer.rewards.concurrent; -import org.cardanofoundation.explorer.rewards.service.RewardFetchingService; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; + import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import rest.koios.client.backend.api.base.exception.ApiException; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CompletableFuture; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.when; +import org.cardanofoundation.explorer.rewards.service.RewardFetchingService; @ExtendWith(MockitoExtension.class) class RewardConcurrentFetchingTest { - @Mock - private RewardFetchingService rewardFetchingService; + @Mock private RewardFetchingService rewardFetchingService; - @InjectMocks - private RewardConcurrentFetching rewardConcurrentFetching; + @InjectMocks private RewardConcurrentFetching rewardConcurrentFetching; @Test void fetchDataConcurrently_NoStakeAddresses_ReturnsTrue() { @@ -33,13 +33,13 @@ void fetchDataConcurrently_NoStakeAddresses_ReturnsTrue() { assertTrue(result); } - @Test void fetchDataConcurrently_FetchDataSuccessfully_ReturnsTrue() throws Exception { // Setup - List stakeAddressList = List.of( - "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); + List stakeAddressList = + List.of( + "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", + "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); rewardConcurrentFetching.setSubListSize(5); @@ -49,19 +49,18 @@ void fetchDataConcurrently_FetchDataSuccessfully_ReturnsTrue() throws Exception .thenReturn(CompletableFuture.completedFuture(true)); // Run the test - final Boolean result = rewardConcurrentFetching.fetchDataConcurrently( - stakeAddressList); + final Boolean result = rewardConcurrentFetching.fetchDataConcurrently(stakeAddressList); // Verify the results assertTrue(result); } @Test - void fetchDataConcurrently_ApiExceptionOccurs_ReturnsFalse() - throws Exception { - List stakeAddressList = List.of( - "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); + void fetchDataConcurrently_ApiExceptionOccurs_ReturnsFalse() throws Exception { + List stakeAddressList = + List.of( + "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", + "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); when(rewardFetchingService.getStakeAddressListNeedFetchData(stakeAddressList)) .thenThrow(ApiException.class); @@ -72,10 +71,11 @@ void fetchDataConcurrently_ApiExceptionOccurs_ReturnsFalse() } @Test - void fetchDataConcurrently_StakeAddressListNeedFetchDataIsEmpty_ReturnsTrue() throws Exception{ - List stakeAddressList = List.of( - "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); + void fetchDataConcurrently_StakeAddressListNeedFetchDataIsEmpty_ReturnsTrue() throws Exception { + List stakeAddressList = + List.of( + "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", + "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); when(rewardFetchingService.getStakeAddressListNeedFetchData(stakeAddressList)) .thenReturn(Collections.emptyList()); @@ -88,17 +88,18 @@ void fetchDataConcurrently_StakeAddressListNeedFetchDataIsEmpty_ReturnsTrue() th @Test void fetchDataConcurrently_FetchDataFailed_ReturnsFalse() throws Exception { // Setup - List stakeAddressList = List.of( - "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); + List stakeAddressList = + List.of( + "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", + "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); rewardConcurrentFetching.setSubListSize(5); when(rewardFetchingService.getStakeAddressListNeedFetchData(anyList())) .thenReturn(stakeAddressList); - when(rewardFetchingService.fetchData(anyList())).thenReturn(CompletableFuture.completedFuture(Boolean.FALSE)); + when(rewardFetchingService.fetchData(anyList())) + .thenReturn(CompletableFuture.completedFuture(Boolean.FALSE)); // Run the test - final Boolean result = rewardConcurrentFetching.fetchDataConcurrently( - stakeAddressList); + final Boolean result = rewardConcurrentFetching.fetchDataConcurrently(stakeAddressList); // Verify the results assertFalse(result); } diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/controller/AdaPotsControllerTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/controller/AdaPotsControllerTest.java index 7482e860..6e6136ac 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/controller/AdaPotsControllerTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/controller/AdaPotsControllerTest.java @@ -1,9 +1,13 @@ package org.cardanofoundation.explorer.rewards.controller; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.cardanofoundation.explorer.rewards.concurrent.AdaPostsConcurrentFetching; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import static org.hamcrest.core.StringContains.containsString; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -11,35 +15,34 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import java.util.List; +import com.fasterxml.jackson.databind.ObjectMapper; -import static org.hamcrest.core.StringContains.containsString; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.cardanofoundation.explorer.rewards.concurrent.AdaPostsConcurrentFetching; @ExtendWith(SpringExtension.class) @WebMvcTest(AdaPotsController.class) class AdaPotsControllerTest { - @Autowired - private MockMvc mockMvc; + @Autowired private MockMvc mockMvc; - @MockBean - private AdaPostsConcurrentFetching adaPostsConcurrentFetching; + @MockBean private AdaPostsConcurrentFetching adaPostsConcurrentFetching; @Test void fetchAdaPots_Success_ReturnsTrue() throws Exception { List epochs = List.of(314, 315); when(adaPostsConcurrentFetching.fetchDataConcurrently(epochs)).thenReturn(true); - mockMvc.perform(post("/api/v1/ada-pots/fetch") - .content(asJsonString(epochs)).contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + mockMvc + .perform( + post("/api/v1/ada-pots/fetch") + .content(asJsonString(epochs)) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(content().string( - containsString("true"))); + .andExpect(content().string(containsString("true"))); } public static String asJsonString(final Object obj) { diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochControllerTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochControllerTest.java index 80adfb95..856864d0 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochControllerTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochControllerTest.java @@ -1,11 +1,12 @@ - package org.cardanofoundation.explorer.rewards.controller; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; -import org.cardanofoundation.explorer.rewards.concurrent.EpochConcurrentFetching; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -13,34 +14,41 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import java.util.List; +import com.fasterxml.jackson.databind.ObjectMapper; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.rewards.concurrent.EpochConcurrentFetching; @ExtendWith(SpringExtension.class) @WebMvcTest(EpochController.class) class EpochControllerTest { - @Autowired - private MockMvc mockMvc; + @Autowired private MockMvc mockMvc; - @MockBean - private EpochConcurrentFetching epochConcurrentFetching; + @MockBean private EpochConcurrentFetching epochConcurrentFetching; @Test void fetchEpochsSuccess_ReturnsTrue() throws Exception { List epochs = List.of(314, 315); when(epochConcurrentFetching.fetchDataConcurrently(epochs)) - .thenReturn(List.of(Epoch.builder().no(314).build(), Epoch.builder().no(315).build())); - - mockMvc.perform(post("/api/v1/epochs/fetch") - .content(asJsonString(epochs)).contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .thenReturn(List.of(Epoch.builder().no(314).build(), Epoch.builder().no(315).build())); + + mockMvc + .perform( + post("/api/v1/epochs/fetch") + .content(asJsonString(epochs)) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(content().json(asJsonString(List.of(Epoch.builder().no(314).build(), Epoch.builder().no(315).build())))); + .andExpect( + content() + .json( + asJsonString( + List.of( + Epoch.builder().no(314).build(), Epoch.builder().no(315).build())))); } public static String asJsonString(final Object obj) { diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochStakeControllerTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochStakeControllerTest.java index 5915ea5f..664bba6f 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochStakeControllerTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochStakeControllerTest.java @@ -1,9 +1,13 @@ package org.cardanofoundation.explorer.rewards.controller; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.cardanofoundation.explorer.rewards.concurrent.EpochStakeConcurrentFetching; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import static org.hamcrest.core.StringContains.containsString; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -11,38 +15,36 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import java.util.List; +import com.fasterxml.jackson.databind.ObjectMapper; -import static org.hamcrest.core.StringContains.containsString; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.cardanofoundation.explorer.rewards.concurrent.EpochStakeConcurrentFetching; @ExtendWith(SpringExtension.class) @WebMvcTest(EpochStakeController.class) class EpochStakeControllerTest { - @Autowired - private MockMvc mockMvc; + @Autowired private MockMvc mockMvc; - @MockBean - private EpochStakeConcurrentFetching mockEpochStakeConcurrentFetching; + @MockBean private EpochStakeConcurrentFetching mockEpochStakeConcurrentFetching; @Test void fetchEpochStakes_Success_ReturnsTrue() throws Exception { - List stakeAddressList = List.of( - "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); - when(mockEpochStakeConcurrentFetching.fetchDataConcurrently(stakeAddressList)) - .thenReturn(true); - mockMvc.perform(post("/api/v1/epoch-stake/fetch") - .content(asJsonString(stakeAddressList)) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + List stakeAddressList = + List.of( + "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", + "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); + when(mockEpochStakeConcurrentFetching.fetchDataConcurrently(stakeAddressList)).thenReturn(true); + mockMvc + .perform( + post("/api/v1/epoch-stake/fetch") + .content(asJsonString(stakeAddressList)) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(content().string( - containsString("true"))); + .andExpect(content().string(containsString("true"))); } public static String asJsonString(final Object obj) { diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/controller/PoolHistoryControllerTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/controller/PoolHistoryControllerTest.java index 0deee72e..13ddc6e0 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/controller/PoolHistoryControllerTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/controller/PoolHistoryControllerTest.java @@ -1,9 +1,13 @@ package org.cardanofoundation.explorer.rewards.controller; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.cardanofoundation.explorer.rewards.concurrent.PoolHistoryConcurrentFetching; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import static org.hamcrest.core.StringContains.containsString; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -11,38 +15,36 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import java.util.List; +import com.fasterxml.jackson.databind.ObjectMapper; -import static org.hamcrest.core.StringContains.containsString; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.cardanofoundation.explorer.rewards.concurrent.PoolHistoryConcurrentFetching; @ExtendWith(SpringExtension.class) @WebMvcTest(PoolHistoryController.class) class PoolHistoryControllerTest { - @Autowired - private MockMvc mockMvc; + @Autowired private MockMvc mockMvc; - @MockBean - private PoolHistoryConcurrentFetching mockPoolHistoryConcurrentFetching; + @MockBean private PoolHistoryConcurrentFetching mockPoolHistoryConcurrentFetching; @Test void fetchPoolHistoryList_Success_ReturnsTrue() throws Exception { - List poolIdList = List.of( - "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", - "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); - when(mockPoolHistoryConcurrentFetching.fetchDataConcurrently(poolIdList)) - .thenReturn(true); - mockMvc.perform(post("/api/v1/pool-history/fetch") - .content(asJsonString(poolIdList)) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + List poolIdList = + List.of( + "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", + "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); + when(mockPoolHistoryConcurrentFetching.fetchDataConcurrently(poolIdList)).thenReturn(true); + mockMvc + .perform( + post("/api/v1/pool-history/fetch") + .content(asJsonString(poolIdList)) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(content().string( - containsString("true"))); + .andExpect(content().string(containsString("true"))); } public static String asJsonString(final Object obj) { diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/controller/PoolInfoControllerTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/controller/PoolInfoControllerTest.java index aca8798f..b593553c 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/controller/PoolInfoControllerTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/controller/PoolInfoControllerTest.java @@ -1,9 +1,13 @@ package org.cardanofoundation.explorer.rewards.controller; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.cardanofoundation.explorer.rewards.concurrent.PoolInfoConcurrentFetching; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import static org.hamcrest.core.StringContains.containsString; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -11,38 +15,36 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import java.util.List; +import com.fasterxml.jackson.databind.ObjectMapper; -import static org.hamcrest.core.StringContains.containsString; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.cardanofoundation.explorer.rewards.concurrent.PoolInfoConcurrentFetching; @ExtendWith(SpringExtension.class) @WebMvcTest(PoolInfoController.class) class PoolInfoControllerTest { - @Autowired - private MockMvc mockMvc; + @Autowired private MockMvc mockMvc; - @MockBean - private PoolInfoConcurrentFetching mockPoolInfoConcurrentFetching; + @MockBean private PoolInfoConcurrentFetching mockPoolInfoConcurrentFetching; @Test void fetchPoolInfoList_Success_ReturnsTrue() throws Exception { - List poolIdList = List.of( - "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", - "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); - when(mockPoolInfoConcurrentFetching.fetchDataConcurrently(poolIdList)) - .thenReturn(true); - mockMvc.perform(post("/api/v1/pool-info/fetch") - .content(asJsonString(poolIdList)) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + List poolIdList = + List.of( + "pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt", + "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); + when(mockPoolInfoConcurrentFetching.fetchDataConcurrently(poolIdList)).thenReturn(true); + mockMvc + .perform( + post("/api/v1/pool-info/fetch") + .content(asJsonString(poolIdList)) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(content().string( - containsString("true"))); + .andExpect(content().string(containsString("true"))); } public static String asJsonString(final Object obj) { diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/controller/RewardControllerTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/controller/RewardControllerTest.java index e0de9777..5973657b 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/controller/RewardControllerTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/controller/RewardControllerTest.java @@ -1,9 +1,13 @@ package org.cardanofoundation.explorer.rewards.controller; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.cardanofoundation.explorer.rewards.concurrent.RewardConcurrentFetching; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import static org.hamcrest.core.StringContains.containsString; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -11,37 +15,36 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import java.util.List; +import com.fasterxml.jackson.databind.ObjectMapper; -import static org.hamcrest.core.StringContains.containsString; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.cardanofoundation.explorer.rewards.concurrent.RewardConcurrentFetching; @ExtendWith(SpringExtension.class) @WebMvcTest(RewardController.class) class RewardControllerTest { - @Autowired - private MockMvc mockMvc; + @Autowired private MockMvc mockMvc; - @MockBean - private RewardConcurrentFetching mockRewardConcurrentFetching; + @MockBean private RewardConcurrentFetching mockRewardConcurrentFetching; @Test void fetchRewards_Success_ReturnsTrue() throws Exception { - List stakeAddressList = List.of( - "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); - when(mockRewardConcurrentFetching.fetchDataConcurrently(stakeAddressList)) - .thenReturn(true); - mockMvc.perform(post("/api/v1/rewards/fetch") - .content(asJsonString(stakeAddressList)).contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + List stakeAddressList = + List.of( + "stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", + "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"); + when(mockRewardConcurrentFetching.fetchDataConcurrently(stakeAddressList)).thenReturn(true); + mockMvc + .perform( + post("/api/v1/rewards/fetch") + .content(asJsonString(stakeAddressList)) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(content().string( - containsString("true"))); + .andExpect(content().string(containsString("true"))); } public static String asJsonString(final Object obj) { diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckPointRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckPointRepositoryTest.java index f7901c50..cf95eaa0 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckPointRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckPointRepositoryTest.java @@ -1,5 +1,9 @@ package org.cardanofoundation.explorer.rewards.repository.jooq; +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.List; import java.util.concurrent.CompletableFuture; @@ -9,20 +13,15 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ActiveProfiles; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.table; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - +import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; +import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @JooqTest @ActiveProfiles("integration-test") @@ -35,6 +34,7 @@ class JOOQEpochStakeCheckPointRepositoryTest extends TestDataBaseContainer { @Value("${spring.jpa.properties.hibernate.default_schema}") private String schema; + private String tableName; private String viewField; @@ -45,6 +45,7 @@ void setUp() { tableName = entityUtil.getTableName(); dsl.deleteFrom(table(tableName)).execute(); } + @Test @DisplayName("SaveAll should save success when on conflict view") void saveAll_shouldSaveSuccessWhenOnConflictView() { @@ -65,8 +66,7 @@ void saveAll_shouldSaveSuccessWhenOnConflictView() { completableFutures.forEach(CompletableFuture::join); dsl.fetch(table(tableName), field(viewField).eq(stakeAddress)); - assertEquals( - 1, dsl.fetchCount(table(tableName), field(viewField).eq(stakeAddress))); + assertEquals(1, dsl.fetchCount(table(tableName), field(viewField).eq(stakeAddress))); } @Test @@ -81,11 +81,8 @@ void saveAll_shouldSaveSuccessWhenDoesNotOnConflictView() { jooqEpochStakeCheckpointRepository.saveAll(List.of(checkpoint1, checkpoint2, checkpoint3)); assertEquals(3, dsl.fetchCount(table(tableName))); - assertEquals( - 1, dsl.fetchCount(table(tableName), field(viewField).eq("stakeKey1"))); - assertEquals( - 1, dsl.fetchCount(table(tableName), field(viewField).eq("stakeKey2"))); - assertEquals( - 1, dsl.fetchCount(table(tableName), field(viewField).eq("stakeKey3"))); + assertEquals(1, dsl.fetchCount(table(tableName), field(viewField).eq("stakeKey1"))); + assertEquals(1, dsl.fetchCount(table(tableName), field(viewField).eq("stakeKey2"))); + assertEquals(1, dsl.fetchCount(table(tableName), field(viewField).eq("stakeKey3"))); } } diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepositoryTest.java index b282156b..3ccd3be2 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepositoryTest.java @@ -1,6 +1,8 @@ package org.cardanofoundation.explorer.rewards.repository.jooq; - +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.name; +import static org.jooq.impl.DSL.table; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -14,8 +16,6 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ActiveProfiles; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStake_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.junit.jupiter.api.BeforeEach; @@ -23,13 +23,10 @@ import org.junit.jupiter.api.Test; import org.cardanofoundation.explorer.consumercommon.entity.EpochStake; +import org.cardanofoundation.explorer.consumercommon.entity.EpochStake_; import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress; -import org.jooq.Name; - -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.name; -import static org.jooq.impl.DSL.table; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @JooqTest @ActiveProfiles("integration-test") @@ -42,6 +39,7 @@ class JOOQEpochStakeRepositoryTest extends TestDataBaseContainer { @Value("${spring.jpa.properties.hibernate.default_schema}") private String schema; + private String tableName; private String epochNoField; @@ -168,4 +166,4 @@ void saveAll_shouldSaveSuccessWhenDoesNotOnConflictUniqueField() { assertEquals(403, response.get(3).get(field(epochNoField))); assertEquals(404, response.get(4).get(field(epochNoField))); } -} \ No newline at end of file +} diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckPointRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckPointRepositoryTest.java index 9d5299a2..451e2f16 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckPointRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckPointRepositoryTest.java @@ -1,5 +1,7 @@ package org.cardanofoundation.explorer.rewards.repository.jooq; +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; @@ -11,8 +13,6 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ActiveProfiles; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.junit.jupiter.api.BeforeEach; @@ -20,9 +20,8 @@ import org.junit.jupiter.api.Test; import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint; - -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.table; +import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @JooqTest @ActiveProfiles("integration-test") @@ -35,6 +34,7 @@ class JOOQPoolHistoryCheckPointRepositoryTest extends TestDataBaseContainer { @Value("${spring.jpa.properties.hibernate.default_schema}") private String schema; + private String tableName; private String viewField; @@ -73,8 +73,7 @@ void saveAll_shouldSaveSuccessWhenOnConflictView() { completableFutures.forEach(CompletableFuture::join); - assertEquals( - 1, dsl.fetchCount(table(tableName), field(viewField).eq(poolView))); + assertEquals(1, dsl.fetchCount(table(tableName), field(viewField).eq(poolView))); } @Test @@ -103,11 +102,8 @@ void saveAll_shouldSaveSuccessWhenDoesNotOnConflictView() { jooqPoolHistoryCheckpointRepository.saveAll(List.of(checkpoint1, checkpoint2, checkpoint3)); assertEquals(3, dsl.fetchCount(table(tableName))); - assertEquals( - 1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView1"))); - assertEquals( - 1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView2"))); - assertEquals( - 1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView3"))); + assertEquals(1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView1"))); + assertEquals(1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView2"))); + assertEquals(1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView3"))); } } diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepositoryTest.java index 6e4bb5ec..7089743a 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepositoryTest.java @@ -1,5 +1,8 @@ package org.cardanofoundation.explorer.rewards.repository.jooq; +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.name; +import static org.jooq.impl.DSL.table; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -13,10 +16,6 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ActiveProfiles; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory_; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.junit.jupiter.api.BeforeEach; @@ -24,10 +23,8 @@ import org.junit.jupiter.api.Test; import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory; - -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.name; -import static org.jooq.impl.DSL.table; +import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @JooqTest @ActiveProfiles("integration-test") @@ -40,6 +37,7 @@ class JOOQPoolHistoryRepositoryTest extends TestDataBaseContainer { @Value("${spring.jpa.properties.hibernate.default_schema}") private String schema; + private String tableName; private String epochNoField; diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckPointRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckPointRepositoryTest.java index b80c33a1..065688f3 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckPointRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckPointRepositoryTest.java @@ -2,7 +2,6 @@ import static org.jooq.impl.DSL.field; import static org.jooq.impl.DSL.table; - import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; @@ -14,8 +13,6 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ActiveProfiles; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.junit.jupiter.api.BeforeEach; @@ -23,16 +20,16 @@ import org.junit.jupiter.api.Test; import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint; +import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @JooqTest @ActiveProfiles("integration-test") @ComponentScan class JOOQPoolInfoCheckPointRepositoryTest extends TestDataBaseContainer { - @Autowired - private DSLContext dsl; - @Autowired - private JOOQPoolInfoCheckpointRepository jooqPoolInfoCheckpointRepository; + @Autowired private DSLContext dsl; + @Autowired private JOOQPoolInfoCheckpointRepository jooqPoolInfoCheckpointRepository; @Value("${spring.jpa.properties.hibernate.default_schema}") private String schema; @@ -79,11 +76,8 @@ void saveAll_shouldSaveSuccessWhenDoesNotOnConflictView() { jooqPoolInfoCheckpointRepository.saveAll(List.of(checkpoint1, checkpoint2, checkpoint3)); assertEquals(3, dsl.fetchCount(table(tableName))); - assertEquals( - 1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView1"))); - assertEquals( - 1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView2"))); - assertEquals( - 1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView3"))); + assertEquals(1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView1"))); + assertEquals(1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView2"))); + assertEquals(1, dsl.fetchCount(table(tableName), field(viewField).eq("poolView3"))); } } diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepositoryTest.java index 9663d6fd..778dc9a8 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepositoryTest.java @@ -3,7 +3,6 @@ import static org.jooq.impl.DSL.field; import static org.jooq.impl.DSL.name; import static org.jooq.impl.DSL.table; - import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -17,8 +16,6 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ActiveProfiles; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.junit.jupiter.api.BeforeEach; @@ -26,17 +23,17 @@ import org.junit.jupiter.api.Test; import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; +import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @JooqTest @ActiveProfiles("integration-test") @ComponentScan class JOOQPoolInfoRepositoryTest extends TestDataBaseContainer { - @Autowired - private DSLContext dsl; + @Autowired private DSLContext dsl; - @Autowired - private JOOQPoolInfoRepository jooqPoolInfoRepository; + @Autowired private JOOQPoolInfoRepository jooqPoolInfoRepository; @Value("${spring.jpa.properties.hibernate.default_schema}") private String schema; diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepositoryTest.java index ddbbcac1..1b0878f5 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepositoryTest.java @@ -2,7 +2,6 @@ import static org.jooq.impl.DSL.field; import static org.jooq.impl.DSL.table; - import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; @@ -14,8 +13,6 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ActiveProfiles; -import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.junit.jupiter.api.BeforeEach; @@ -23,7 +20,8 @@ import org.junit.jupiter.api.Test; import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint; - +import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint_; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @JooqTest @ActiveProfiles("integration-test") diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepositoryTest.java index aca15021..a58cb2a3 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepositoryTest.java @@ -3,7 +3,6 @@ import static org.jooq.impl.DSL.field; import static org.jooq.impl.DSL.name; import static org.jooq.impl.DSL.table; - import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -17,8 +16,6 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ActiveProfiles; -import org.cardanofoundation.explorer.consumercommon.entity.Reward_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; import org.jooq.DSLContext; import org.junit.jupiter.api.BeforeEach; @@ -27,8 +24,10 @@ import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; import org.cardanofoundation.explorer.consumercommon.entity.Reward; +import org.cardanofoundation.explorer.consumercommon.entity.Reward_; import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress; import org.cardanofoundation.explorer.consumercommon.enumeration.RewardType; +import org.cardanofoundation.explorer.rewards.util.EntityUtil; @JooqTest @ActiveProfiles("integration-test") diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataScheduleTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataScheduleTest.java index 84a4ab08..65a0714b 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataScheduleTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataScheduleTest.java @@ -1,45 +1,45 @@ package org.cardanofoundation.explorer.rewards.schedule; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.util.List; import java.util.concurrent.CompletableFuture; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; -import org.cardanofoundation.explorer.rewards.schedule.service.PoolInfoDataService; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; +import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; +import org.cardanofoundation.explorer.rewards.schedule.service.PoolInfoDataService; + @ExtendWith(MockitoExtension.class) class PoolInfoDataScheduleTest { - @Mock - private PoolHashRepository poolHashRepository; - @Mock - private PoolInfoDataService poolInfoDataService; - @InjectMocks - private PoolInfoDataSchedule poolInfoDataSchedule; + @Mock private PoolHashRepository poolHashRepository; + @Mock private PoolInfoDataService poolInfoDataService; + @InjectMocks private PoolInfoDataSchedule poolInfoDataSchedule; @Test void fetchAllPoolInfoData_WhenFetchDataSuccessfully() { // Setup - final List poolHashes = List.of(PoolHash.builder() - .id(1L) - .view("pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr") - .build(), - PoolHash.builder() - .id(2L) - .view("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - .build()); + final List poolHashes = + List.of( + PoolHash.builder() + .id(1L) + .view("pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr") + .build(), + PoolHash.builder() + .id(2L) + .view("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") + .build()); poolInfoDataSchedule.setSubListSize(1); when(poolHashRepository.findAll()).thenReturn(poolHashes); when(poolInfoDataService.fetchData(anyList())) @@ -65,14 +65,16 @@ void fetchAllPoolInfoData_whenPoolHashRepositoryReturnsNoItem() { @Test void fetchAllPoolInfoData_whenPoolInfoDataServiceReturnsFailure() { // Setup - final List poolHashes = List.of(PoolHash.builder() - .id(1L) - .view("pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr") - .build(), - PoolHash.builder() - .id(2L) - .view("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - .build()); + final List poolHashes = + List.of( + PoolHash.builder() + .id(1L) + .view("pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr") + .build(), + PoolHash.builder() + .id(2L) + .view("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") + .build()); when(poolHashRepository.findAll()).thenReturn(poolHashes); poolInfoDataSchedule.setSubListSize(1); diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataServiceTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataServiceTest.java index 68791590..a9019846 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataServiceTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataServiceTest.java @@ -1,14 +1,14 @@ package org.cardanofoundation.explorer.rewards.schedule.service; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.util.List; import java.util.concurrent.CompletableFuture; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; -import org.cardanofoundation.explorer.rewards.config.KoiosClient; -import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; -import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolInfoRepository; -import org.cardanofoundation.explorer.rewards.service.EpochService; import org.mockito.Answers; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -17,37 +17,35 @@ import org.mockito.junit.jupiter.MockitoExtension; import rest.koios.client.backend.api.base.exception.ApiException; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; +import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; +import org.cardanofoundation.explorer.rewards.config.KoiosClient; +import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; +import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolInfoRepository; +import org.cardanofoundation.explorer.rewards.service.EpochService; @ExtendWith(MockitoExtension.class) class PoolInfoDataServiceTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private KoiosClient koiosClient; - @Mock - private JOOQPoolInfoRepository jooqPoolInfoRepository; - @Mock - private PoolHashRepository poolHashRepository; - @Mock - private EpochService epochService; - @InjectMocks - private PoolInfoDataService poolInfoDataService; - @Captor - ArgumentCaptor> poolInfoCaptor; + + @Mock private JOOQPoolInfoRepository jooqPoolInfoRepository; + @Mock private PoolHashRepository poolHashRepository; + @Mock private EpochService epochService; + @InjectMocks private PoolInfoDataService poolInfoDataService; + @Captor ArgumentCaptor> poolInfoCaptor; @Test void fetchData_whenFetchSuccessfully() throws Exception { // Setup - List poolIds = List.of("pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr", - "pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc"); + List poolIds = + List.of( + "pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr", + "pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc"); var poolInfo1 = new rest.koios.client.backend.api.pool.model.PoolInfo(); poolInfo1.setPoolIdBech32(poolIds.get(0)); @@ -63,23 +61,23 @@ void fetchData_whenFetchSuccessfully() throws Exception { when(epochService.getCurrentEpoch()).thenReturn(416); - when(koiosClient.poolService().getPoolInformation(poolIds, null).getValue()).thenReturn( - List.of(poolInfo1, poolInfo2)); - - when(poolHashRepository.findByViewIn(poolIds)).thenReturn(List.of( - PoolHash.builder() - .id(1L) - .view("pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr") - .build(), - PoolHash.builder() - .id(2L) - .view("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - .build() - )); + when(koiosClient.poolService().getPoolInformation(poolIds, null).getValue()) + .thenReturn(List.of(poolInfo1, poolInfo2)); + + when(poolHashRepository.findByViewIn(poolIds)) + .thenReturn( + List.of( + PoolHash.builder() + .id(1L) + .view("pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr") + .build(), + PoolHash.builder() + .id(2L) + .view("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") + .build())); // Run the test - final CompletableFuture result = poolInfoDataService.fetchData( - poolIds); + final CompletableFuture result = poolInfoDataService.fetchData(poolIds); // Verify verify(jooqPoolInfoRepository).saveAll(poolInfoCaptor.capture()); @@ -90,8 +88,10 @@ void fetchData_whenFetchSuccessfully() throws Exception { @Test void fetchData_whenEpochServiceThrowsApiException() throws Exception { // Setup - List poolIds = List.of("pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr", - "pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc"); + List poolIds = + List.of( + "pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr", + "pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc"); when(epochService.getCurrentEpoch()).thenThrow(ApiException.class); diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImplTest.java index 3cbb5a98..eb838a6f 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImplTest.java @@ -1,25 +1,27 @@ package org.cardanofoundation.explorer.rewards.service.impl; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.math.BigInteger; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import org.mockito.*; +import org.mockito.junit.jupiter.MockitoExtension; +import rest.koios.client.backend.api.network.model.Totals; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import org.cardanofoundation.explorer.consumercommon.entity.AdaPots; import org.cardanofoundation.explorer.consumercommon.entity.Block; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.AdaPotsRepository; import org.cardanofoundation.explorer.rewards.repository.BlockRepository; import org.cardanofoundation.explorer.rewards.repository.EpochRepository; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.*; -import org.mockito.junit.jupiter.MockitoExtension; -import rest.koios.client.backend.api.network.model.Totals; - -import java.math.BigInteger; -import java.util.List; -import java.util.concurrent.CompletableFuture; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class AdaPotsFetchingServiceImplTest { @@ -27,20 +29,15 @@ class AdaPotsFetchingServiceImplTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private KoiosClient koiosClient; - @Mock - private AdaPotsRepository adaPotsRepository; + @Mock private AdaPotsRepository adaPotsRepository; - @Mock - private BlockRepository blockRepository; + @Mock private BlockRepository blockRepository; - @Mock - private EpochRepository epochRepository; + @Mock private EpochRepository epochRepository; - @InjectMocks - private AdaPotsFetchingServiceImpl adaPotsFetchingServiceImpl; + @InjectMocks private AdaPotsFetchingServiceImpl adaPotsFetchingServiceImpl; - @Captor - ArgumentCaptor adaPotsCaptor; + @Captor ArgumentCaptor adaPotsCaptor; @Test void testFetchData() throws Exception { @@ -55,12 +52,9 @@ void testFetchData() throws Exception { totals.setCirculation("32696853337370414"); totals.setSupply("34085668605164388"); - when(koiosClient.networkService().getHistoricalTokenomicStatsByEpoch(epoch) - .getValue()).thenReturn(totals); - Block block = Block.builder() - .id(1L) - .slotNo(1375L) - .build(); + when(koiosClient.networkService().getHistoricalTokenomicStatsByEpoch(epoch).getValue()) + .thenReturn(totals); + Block block = Block.builder().id(1L).slotNo(1375L).build(); when(blockRepository.getFirstBlockByEpochNo(epoch)).thenReturn(block); // Run the test @@ -90,8 +84,7 @@ void testGetEpochsNeedFetchData() { when(adaPotsRepository.findByEpochNoIn(epochs)).thenReturn(List.of(adaPots)); // Run the test - final List result = adaPotsFetchingServiceImpl.getEpochsNeedFetchData( - epochs); + final List result = adaPotsFetchingServiceImpl.getEpochsNeedFetchData(epochs); // Verify the results assertEquals(List.of(314), result); diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImplTest.java index a0149951..7a61e1de 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImplTest.java @@ -1,16 +1,10 @@ package org.cardanofoundation.explorer.rewards.service.impl; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; -import org.cardanofoundation.explorer.consumercommon.enumeration.EraType; -import org.cardanofoundation.explorer.rewards.config.KoiosClient; -import org.cardanofoundation.explorer.rewards.repository.EpochRepository; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Answers; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import rest.koios.client.backend.api.epoch.model.EpochInfo; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; import java.math.BigInteger; import java.util.ArrayList; @@ -18,11 +12,19 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; +import org.mockito.Answers; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import rest.koios.client.backend.api.epoch.model.EpochInfo; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.consumercommon.enumeration.EraType; +import org.cardanofoundation.explorer.rewards.config.KoiosClient; +import org.cardanofoundation.explorer.rewards.repository.EpochRepository; @ExtendWith(MockitoExtension.class) class EpochFetchingServiceImplTest { @@ -30,11 +32,9 @@ class EpochFetchingServiceImplTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private KoiosClient koiosClient; - @Mock - private EpochRepository epochRepository; + @Mock private EpochRepository epochRepository; - @InjectMocks - private EpochFetchingServiceImpl epochFetchingService; + @InjectMocks private EpochFetchingServiceImpl epochFetchingService; @Test void testFetchDataWithByronBlock() { @@ -46,12 +46,7 @@ void testFetchDataWithByronBlock() { epochInfo.setTotalRewards("577641621267691"); when(epochRepository.findByNo(any())) - .thenReturn(Optional - .ofNullable(Epoch - .builder() - .no(epoch) - .era(EraType.BYRON) - .build())); + .thenReturn(Optional.ofNullable(Epoch.builder().no(epoch).era(EraType.BYRON).build())); // Run the test final CompletableFuture result = epochFetchingService.fetchData(epoch); @@ -68,15 +63,12 @@ void testFetchData() throws Exception { epochInfo.setTotalRewards("577641621267691"); when(epochRepository.findByNo(any())) - .thenReturn(Optional - .ofNullable(Epoch - .builder() - .no(epoch) - .era(EraType.SHELLEY) - .build())); - when(koiosClient.epochService().getEpochInformationByEpoch(epoch) - .getValue()).thenReturn(epochInfo); - doNothing().when(epochRepository).updateRewardDistributedByNo(new BigInteger("577641621267691"), epoch); + .thenReturn(Optional.ofNullable(Epoch.builder().no(epoch).era(EraType.SHELLEY).build())); + when(koiosClient.epochService().getEpochInformationByEpoch(epoch).getValue()) + .thenReturn(epochInfo); + doNothing() + .when(epochRepository) + .updateRewardDistributedByNo(new BigInteger("577641621267691"), epoch); // Run the test final CompletableFuture result = epochFetchingService.fetchData(epoch); @@ -95,12 +87,12 @@ void testFetchDataWithEpochNotNull() { epochInfo.setTotalRewards("577641621267691"); when(epochRepository.findByNo(any())) - .thenReturn(Optional - .ofNullable(Epoch - .builder() - .no(epoch) - .rewardsDistributed(new BigInteger("577641621267691")) - .build())); + .thenReturn( + Optional.ofNullable( + Epoch.builder() + .no(epoch) + .rewardsDistributed(new BigInteger("577641621267691")) + .build())); // Run the test final CompletableFuture result = epochFetchingService.fetchData(epoch); assertNull(result); @@ -111,8 +103,7 @@ void testFetchDataWithEpochNotFound() { // Setup Integer epoch = 5000; - when(epochRepository.findByNo(any())) - .thenReturn(Optional.empty()); + when(epochRepository.findByNo(any())).thenReturn(Optional.empty()); // Run the test final CompletableFuture result = epochFetchingService.fetchData(epoch); @@ -130,9 +121,8 @@ void testGetEpochsNeedFetchData() { when(epochRepository.findByRewardsDistributedIsNotNull()).thenReturn(epochs); // Run the test - final List result = epochFetchingService.getEpochsNeedFetchData( - List.of(312, 313, 314, 315, 316) - ); + final List result = + epochFetchingService.getEpochsNeedFetchData(List.of(312, 313, 314, 315, 316)); // Verify the results assertEquals(List.of(314), result); diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochServiceImplTest.java index e046a2d5..7d1417cd 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochServiceImplTest.java @@ -1,29 +1,28 @@ package org.cardanofoundation.explorer.rewards.service.impl; -import org.cardanofoundation.explorer.rewards.config.KoiosClient; -import org.cardanofoundation.explorer.rewards.repository.EpochRepository; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.when; + import org.mockito.Answers; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.cardanofoundation.explorer.rewards.config.KoiosClient; +import org.cardanofoundation.explorer.rewards.repository.EpochRepository; @ExtendWith(MockitoExtension.class) class EpochServiceImplTest { - @Mock - private EpochRepository epochRepository; + @Mock private EpochRepository epochRepository; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) private KoiosClient koiosClient; - @InjectMocks - private EpochServiceImpl epochServiceImpl; + + @InjectMocks private EpochServiceImpl epochServiceImpl; @Test void testGetCurrentEpoch() throws Exception { diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImplTest.java index 04a16464..de0a8f1a 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImplTest.java @@ -1,5 +1,23 @@ package org.cardanofoundation.explorer.rewards.service.impl; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import org.mockito.*; +import org.mockito.junit.jupiter.MockitoExtension; +import rest.koios.client.backend.api.account.model.AccountHistory; +import rest.koios.client.backend.api.account.model.AccountHistoryInner; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import org.cardanofoundation.explorer.consumercommon.entity.EpochStake; import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; @@ -10,78 +28,56 @@ import org.cardanofoundation.explorer.rewards.repository.StakeAddressRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQEpochStakeCheckpointRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQEpochStakeRepository; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - import org.cardanofoundation.explorer.rewards.service.EpochService; -import org.mockito.*; -import org.mockito.junit.jupiter.MockitoExtension; -import rest.koios.client.backend.api.account.model.AccountHistory; -import rest.koios.client.backend.api.account.model.AccountHistoryInner; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class EpochStakeFetchingServiceImplTest { - @Mock - private StakeAddressRepository stakeAddressRepository; + @Mock private StakeAddressRepository stakeAddressRepository; @Mock(answer = Answers.RETURNS_DEEP_STUBS) private KoiosClient koiosClient; - @Mock - private PoolHashRepository poolHashRepository; + @Mock private PoolHashRepository poolHashRepository; - @Mock - private EpochStakeCheckpointRepository epochStakeCheckpointRepository; + @Mock private EpochStakeCheckpointRepository epochStakeCheckpointRepository; - @Mock - private EpochService epochService; + @Mock private EpochService epochService; - @Mock - private JOOQEpochStakeRepository jooqEpochStakeRepository; + @Mock private JOOQEpochStakeRepository jooqEpochStakeRepository; - @Mock - private JOOQEpochStakeCheckpointRepository jooqEpochStakeCheckpointRepository; + @Mock private JOOQEpochStakeCheckpointRepository jooqEpochStakeCheckpointRepository; - @InjectMocks - private EpochStakeFetchingServiceImpl epochStakeFetchingServiceImpl; + @InjectMocks private EpochStakeFetchingServiceImpl epochStakeFetchingServiceImpl; - @Captor - ArgumentCaptor> epochStakeCaptor; + @Captor ArgumentCaptor> epochStakeCaptor; - @Captor - ArgumentCaptor> checkpointCaptor; + @Captor ArgumentCaptor> checkpointCaptor; - private static List stakeAddressList = new ArrayList<>();// verify(jdbcEpochStakeRepository).saveAll(anyList()); + private static List stakeAddressList = + new ArrayList<>(); // verify(jdbcEpochStakeRepository).saveAll(anyList()); @BeforeAll static void beforeAll() { - stakeAddressList = List.of("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8", - "stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg"); + stakeAddressList = + List.of( + "stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8", + "stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg"); } @Test void fetchData_shouldFetchAndSaveEpochStakeData() throws Exception { // Setup - List stakeAddresses = List.of( - StakeAddress.builder() - .id(1L) - .view("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") - .build(), - StakeAddress.builder() - .view("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") - .id(2L) - .build()); + List stakeAddresses = + List.of( + StakeAddress.builder() + .id(1L) + .view("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") + .build(), + StakeAddress.builder() + .view("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") + .id(2L) + .build()); when(stakeAddressRepository.findByViewIn(any())).thenReturn(stakeAddresses); @@ -95,9 +91,7 @@ void fetchData_shouldFetchAndSaveEpochStakeData() throws Exception { innerOfAccountHistory1.setActiveStake("123456789"); innerOfAccountHistory1.setPoolId("pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"); - accountHistory1.setHistory(List.of( - innerOfAccountHistory1 - )); + accountHistory1.setHistory(List.of(innerOfAccountHistory1)); AccountHistory accountHistory2 = new AccountHistory(); accountHistory2.setStakeAddress("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg"); @@ -107,31 +101,39 @@ void fetchData_shouldFetchAndSaveEpochStakeData() throws Exception { innerOfAccountHistory2.setActiveStake("123456789"); innerOfAccountHistory2.setPoolId("pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt"); - accountHistory2.setHistory(List.of( - innerOfAccountHistory2 - )); + accountHistory2.setHistory(List.of(innerOfAccountHistory2)); accountHistoryList.add(accountHistory1); accountHistoryList.add(accountHistory2); - when(koiosClient.accountService() - .getAccountHistory( - anyList(), any(), any()) - .getValue()).thenReturn(accountHistoryList); - - when(poolHashRepository.findByViewIn(any())).thenReturn(List.of( - PoolHash.builder().view("pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy").id(1L) - .build(), - PoolHash.builder().view("pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt").id(2L) - .build())); - - when(epochStakeCheckpointRepository.findByStakeAddressIn(any())).thenReturn( - List.of(EpochStakeCheckpoint.builder().id(1L) - .stakeAddress("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") - .epochCheckpoint(413).build(), - EpochStakeCheckpoint.builder().id(2L) - .stakeAddress("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") - .epochCheckpoint(413).build())); + when(koiosClient.accountService().getAccountHistory(anyList(), any(), any()).getValue()) + .thenReturn(accountHistoryList); + + when(poolHashRepository.findByViewIn(any())) + .thenReturn( + List.of( + PoolHash.builder() + .view("pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy") + .id(1L) + .build(), + PoolHash.builder() + .view("pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt") + .id(2L) + .build())); + + when(epochStakeCheckpointRepository.findByStakeAddressIn(any())) + .thenReturn( + List.of( + EpochStakeCheckpoint.builder() + .id(1L) + .stakeAddress("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") + .epochCheckpoint(413) + .build(), + EpochStakeCheckpoint.builder() + .id(2L) + .stakeAddress("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") + .epochCheckpoint(413) + .build())); when(epochService.getCurrentEpoch()).thenReturn(414); // Run the test @@ -145,22 +147,27 @@ void fetchData_shouldFetchAndSaveEpochStakeData() throws Exception { assertTrue(result.get()); } - @Test void getStakeAddressListNeedFetchData_shouldReturnStakeAddressList() throws Exception { // Setup - var checkpoints = List.of(EpochStakeCheckpoint.builder().id(1L) - .stakeAddress("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") - .epochCheckpoint(414).build(), - EpochStakeCheckpoint.builder().id(2L) - .stakeAddress("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") - .epochCheckpoint(415).build()); + var checkpoints = + List.of( + EpochStakeCheckpoint.builder() + .id(1L) + .stakeAddress("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") + .epochCheckpoint(414) + .build(), + EpochStakeCheckpoint.builder() + .id(2L) + .stakeAddress("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") + .epochCheckpoint(415) + .build()); when(epochStakeCheckpointRepository.findByStakeAddressIn(any())).thenReturn(checkpoints); when(epochService.getCurrentEpoch()).thenReturn(415); // Run the test - List result = epochStakeFetchingServiceImpl.getStakeAddressListNeedFetchData( - stakeAddressList); + List result = + epochStakeFetchingServiceImpl.getStakeAddressListNeedFetchData(stakeAddressList); // Verify assertEquals(List.of("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8"), result); diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImplTest.java index 30438ce1..2099b8a4 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImplTest.java @@ -1,5 +1,21 @@ package org.cardanofoundation.explorer.rewards.service.impl; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +import org.mockito.*; +import org.mockito.junit.jupiter.MockitoExtension; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory; import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint; @@ -8,22 +24,7 @@ import org.cardanofoundation.explorer.rewards.repository.PoolHistoryCheckpointRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolHistoryCheckpointRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolHistoryRepository; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - import org.cardanofoundation.explorer.rewards.service.EpochService; -import org.mockito.*; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class PoolHistoryFetchingServiceImplTest { @@ -31,36 +32,28 @@ class PoolHistoryFetchingServiceImplTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private KoiosClient koiosClient; - @Mock - private EpochService epochService; + @Mock private EpochService epochService; - @Mock - private PoolHistoryCheckpointRepository poolHistoryCheckpointRepository; + @Mock private PoolHistoryCheckpointRepository poolHistoryCheckpointRepository; - @Mock - private PoolHashRepository poolHashRepository; + @Mock private PoolHashRepository poolHashRepository; - @Mock - private JOOQPoolHistoryRepository jooqPoolHistoryRepository; + @Mock private JOOQPoolHistoryRepository jooqPoolHistoryRepository; - @Mock - private JOOQPoolHistoryCheckpointRepository jooqPoolHistoryCheckpointRepository; + @Mock private JOOQPoolHistoryCheckpointRepository jooqPoolHistoryCheckpointRepository; - @InjectMocks - private PoolHistoryFetchingServiceImpl poolHistoryFetchingServiceImpl; + @InjectMocks private PoolHistoryFetchingServiceImpl poolHistoryFetchingServiceImpl; - @Captor - ArgumentCaptor> poolHistoryCaptor; + @Captor ArgumentCaptor> poolHistoryCaptor; - @Captor - ArgumentCaptor> checkpointCaptor; + @Captor ArgumentCaptor> checkpointCaptor; @Test void fetchData_shouldFetchAndSavePoolHistoryData() throws Exception { // Setup String poolId = "pool10quq4wlghwrvmhdzc7geq22pyhzegccwj56ax2g8hx0cjfahufs"; - when(poolHashRepository.findByView(poolId)).thenReturn( - Optional.of(PoolHash.builder().id(1L).view(poolId).build())); + when(poolHashRepository.findByView(poolId)) + .thenReturn(Optional.of(PoolHash.builder().id(1L).view(poolId).build())); when(epochService.getCurrentEpoch()).thenReturn(416); var poolHistory1 = new rest.koios.client.backend.api.pool.model.PoolHistory(); @@ -89,18 +82,17 @@ void fetchData_shouldFetchAndSavePoolHistoryData() throws Exception { poolHistory2.setBlockCnt(64); poolHistory2.setDelegatorCnt(2); - when(koiosClient.poolService().getPoolHistory(poolId, null).getValue()).thenReturn( - List.of(poolHistory1, poolHistory2)); + when(koiosClient.poolService().getPoolHistory(poolId, null).getValue()) + .thenReturn(List.of(poolHistory1, poolHistory2)); - final Optional poolHistoryCheckpoint = Optional.of( - PoolHistoryCheckpoint.builder().epochCheckpoint(416).view(poolId).id(1L).build()); + final Optional poolHistoryCheckpoint = + Optional.of( + PoolHistoryCheckpoint.builder().epochCheckpoint(416).view(poolId).id(1L).build()); - when(poolHistoryCheckpointRepository.findByView(poolId)) - .thenReturn(poolHistoryCheckpoint); + when(poolHistoryCheckpointRepository.findByView(poolId)).thenReturn(poolHistoryCheckpoint); // Run the test - final CompletableFuture result = poolHistoryFetchingServiceImpl.fetchData( - poolId); + final CompletableFuture result = poolHistoryFetchingServiceImpl.fetchData(poolId); // verify verify(jooqPoolHistoryRepository).saveAll(poolHistoryCaptor.capture()); @@ -115,8 +107,8 @@ void fetchData_shouldFetchAndSavePoolHistoryData() throws Exception { void fetchData_WhenPoolHistoryCheckpointRepositoryReturnsAbsent() throws Exception { // Setup String poolId = "pool10quq4wlghwrvmhdzc7geq22pyhzegccwj56ax2g8hx0cjfahufs"; - when(poolHashRepository.findByView(poolId)).thenReturn( - Optional.of(PoolHash.builder().id(1L).view(poolId).build())); + when(poolHashRepository.findByView(poolId)) + .thenReturn(Optional.of(PoolHash.builder().id(1L).view(poolId).build())); when(epochService.getCurrentEpoch()).thenReturn(416); var poolHistory1 = new rest.koios.client.backend.api.pool.model.PoolHistory(); @@ -145,11 +137,10 @@ void fetchData_WhenPoolHistoryCheckpointRepositoryReturnsAbsent() throws Excepti poolHistory2.setBlockCnt(64); poolHistory2.setDelegatorCnt(2); - when(koiosClient.poolService().getPoolHistory(poolId, null).getValue()).thenReturn( - List.of(poolHistory1, poolHistory2)); + when(koiosClient.poolService().getPoolHistory(poolId, null).getValue()) + .thenReturn(List.of(poolHistory1, poolHistory2)); - when(poolHistoryCheckpointRepository.findByView(poolId)) - .thenReturn(Optional.empty()); + when(poolHistoryCheckpointRepository.findByView(poolId)).thenReturn(Optional.empty()); // Run the test final CompletableFuture result = poolHistoryFetchingServiceImpl.fetchData(poolId); @@ -169,15 +160,19 @@ void getPoolIdListNeedFetchData_ShouldReturnPoolIds() throws Exception { String poolId = "pool10quq4wlghwrvmhdzc7geq22pyhzegccwj56ax2g8hx0cjfahufs"; when(epochService.getCurrentEpoch()).thenReturn(416); - final List poolHistoryCheckpoints = List.of( - PoolHistoryCheckpoint.builder().view(poolId).epochCheckpoint(415).isSpendableReward(true) - .build()); + final List poolHistoryCheckpoints = + List.of( + PoolHistoryCheckpoint.builder() + .view(poolId) + .epochCheckpoint(415) + .isSpendableReward(true) + .build()); when(poolHistoryCheckpointRepository.findByViewIn(List.of(poolId))) .thenReturn(poolHistoryCheckpoints); // Run the test - final List result = poolHistoryFetchingServiceImpl.getPoolIdListNeedFetchData( - List.of(poolId)); + final List result = + poolHistoryFetchingServiceImpl.getPoolIdListNeedFetchData(List.of(poolId)); // Verify the results assertThat(result).isEqualTo(List.of()); diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImplTest.java index 9db1c6e3..a3983165 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImplTest.java @@ -1,5 +1,19 @@ package org.cardanofoundation.explorer.rewards.service.impl; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import org.mockito.*; +import org.mockito.junit.jupiter.MockitoExtension; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint; @@ -7,48 +21,31 @@ import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolInfoCheckpointRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolInfoRepository; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - import org.cardanofoundation.explorer.rewards.service.EpochService; -import org.mockito.*; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.List; -import java.util.concurrent.CompletableFuture; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class PoolInfoFetchingServiceImplTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private KoiosClient koiosClient; - @Mock - private EpochService epochService; - @Mock - private PoolHashRepository poolHashRepository; - @Mock - private JOOQPoolInfoRepository jooqPoolInfoRepository; - @Mock - private JOOQPoolInfoCheckpointRepository jooqPoolInfoCheckpointRepository; - @InjectMocks - private PoolInfoFetchingServiceImpl poolInfoFetchingServiceImpl; - @Captor - ArgumentCaptor> poolInfoCaptor; + @Mock private EpochService epochService; + @Mock private PoolHashRepository poolHashRepository; + @Mock private JOOQPoolInfoRepository jooqPoolInfoRepository; + @Mock private JOOQPoolInfoCheckpointRepository jooqPoolInfoCheckpointRepository; + @InjectMocks private PoolInfoFetchingServiceImpl poolInfoFetchingServiceImpl; + + @Captor ArgumentCaptor> poolInfoCaptor; - @Captor - ArgumentCaptor> checkpointCaptor; + @Captor ArgumentCaptor> checkpointCaptor; @Test void fetchData_shouldFetchAndSavePoolInfoData() throws Exception { // Setup - List poolIds = List.of("pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr", - "pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc"); + List poolIds = + List.of( + "pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr", + "pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc"); var poolInfo1 = new rest.koios.client.backend.api.pool.model.PoolInfo(); poolInfo1.setPoolIdBech32(poolIds.get(0)); @@ -62,24 +59,24 @@ void fetchData_shouldFetchAndSavePoolInfoData() throws Exception { poolInfo2.setLiveStake("5722279429"); poolInfo2.setLiveSaturation(0.01); - when(koiosClient.poolService().getPoolInformation(poolIds, null).getValue()).thenReturn( - List.of(poolInfo1, poolInfo2)); + when(koiosClient.poolService().getPoolInformation(poolIds, null).getValue()) + .thenReturn(List.of(poolInfo1, poolInfo2)); when(epochService.getCurrentEpoch()).thenReturn(416); - when(poolHashRepository.findByViewIn(poolIds)).thenReturn(List.of( - PoolHash.builder() - .id(1L) - .view("pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr") - .build(), - PoolHash.builder() - .id(2L) - .view("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - .build() - )); + when(poolHashRepository.findByViewIn(poolIds)) + .thenReturn( + List.of( + PoolHash.builder() + .id(1L) + .view("pool1chdvqec5lwsxuedrdhcdcxg2295tqrce9lcz3luru5fruzjf3wr") + .build(), + PoolHash.builder() + .id(2L) + .view("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") + .build())); // Run the test - final CompletableFuture result = poolInfoFetchingServiceImpl.fetchData( - poolIds); + final CompletableFuture result = poolInfoFetchingServiceImpl.fetchData(poolIds); - //verify + // verify verify(jooqPoolInfoCheckpointRepository).saveAll(checkpointCaptor.capture()); verify(jooqPoolInfoRepository).saveAll(poolInfoCaptor.capture()); assertEquals(2, poolInfoCaptor.getValue().size()); diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImplTest.java index 24d04004..06ff2beb 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImplTest.java @@ -1,5 +1,24 @@ package org.cardanofoundation.explorer.rewards.service.impl; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import org.mockito.*; +import org.mockito.junit.jupiter.MockitoExtension; +import rest.koios.client.backend.api.account.model.AccountReward; +import rest.koios.client.backend.api.account.model.AccountRewards; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; import org.cardanofoundation.explorer.consumercommon.entity.Reward; import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint; @@ -10,25 +29,7 @@ import org.cardanofoundation.explorer.rewards.repository.StakeAddressRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQRewardCheckpointRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQRewardRepository; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - import org.cardanofoundation.explorer.rewards.service.EpochService; -import org.mockito.*; -import org.mockito.junit.jupiter.MockitoExtension; -import rest.koios.client.backend.api.account.model.AccountReward; -import rest.koios.client.backend.api.account.model.AccountRewards; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class RewardFetchingServiceImplTest { @@ -36,53 +37,47 @@ class RewardFetchingServiceImplTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private KoiosClient koiosClient; - @Mock - private StakeAddressRepository stakeAddressRepository; + @Mock private StakeAddressRepository stakeAddressRepository; - @Mock - private PoolHashRepository poolHashRepository; + @Mock private PoolHashRepository poolHashRepository; - @Mock - private RewardCheckpointRepository rewardCheckpointRepository; + @Mock private RewardCheckpointRepository rewardCheckpointRepository; - @Mock - private EpochService epochService; + @Mock private EpochService epochService; - @Mock - private JOOQRewardRepository jooqRewardRepository; + @Mock private JOOQRewardRepository jooqRewardRepository; - @Mock - private JOOQRewardCheckpointRepository jooqRewardCheckpointRepository; + @Mock private JOOQRewardCheckpointRepository jooqRewardCheckpointRepository; - @InjectMocks - private RewardFetchingServiceImpl rewardFetchingServiceImpl; + @InjectMocks private RewardFetchingServiceImpl rewardFetchingServiceImpl; - @Captor - ArgumentCaptor> rewardCaptor; + @Captor ArgumentCaptor> rewardCaptor; - @Captor - ArgumentCaptor> checkpointCaptor; + @Captor ArgumentCaptor> checkpointCaptor; private static List stakeAddressList = new ArrayList<>(); @BeforeAll static void beforeAll() { - stakeAddressList = List.of("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8", - "stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg"); + stakeAddressList = + List.of( + "stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8", + "stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg"); } @Test void fetchData_shouldFetchAndSaveRewardData() throws Exception { // Setup - List stakeAddresses = List.of( - StakeAddress.builder() - .id(1L) - .view("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") - .build(), - StakeAddress.builder() - .view("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") - .id(2L) - .build()); + List stakeAddresses = + List.of( + StakeAddress.builder() + .id(1L) + .view("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") + .build(), + StakeAddress.builder() + .view("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") + .id(2L) + .build()); when(stakeAddressRepository.findByViewIn(any())).thenReturn(stakeAddresses); @@ -98,9 +93,7 @@ void fetchData_shouldFetchAndSaveRewardData() throws Exception { inner1.setEarnedEpoch(414); inner1.setSpendableEpoch(415); - accountRewards1.setRewards(List.of( - inner1 - )); + accountRewards1.setRewards(List.of(inner1)); AccountRewards accountRewards2 = new AccountRewards(); accountRewards2.setStakeAddress("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg"); @@ -112,31 +105,39 @@ void fetchData_shouldFetchAndSaveRewardData() throws Exception { inner2.setEarnedEpoch(414); inner2.setSpendableEpoch(415); - accountRewards2.setRewards(List.of( - inner2 - )); + accountRewards2.setRewards(List.of(inner2)); accountRewards.add(accountRewards1); accountRewards.add(accountRewards2); - when(koiosClient.accountService() - .getAccountRewards( - anyList(), any(), any()) - .getValue()).thenReturn(accountRewards); - - when(poolHashRepository.findByViewIn(any())).thenReturn(List.of( - PoolHash.builder().view("pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy").id(1L) - .build(), - PoolHash.builder().view("pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt").id(2L) - .build())); - - when(rewardCheckpointRepository.findByStakeAddressIn(any())).thenReturn( - List.of(RewardCheckpoint.builder().id(1L) - .stakeAddress("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") - .epochCheckpoint(413).build(), - RewardCheckpoint.builder().id(2L) - .stakeAddress("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") - .epochCheckpoint(413).build())); + when(koiosClient.accountService().getAccountRewards(anyList(), any(), any()).getValue()) + .thenReturn(accountRewards); + + when(poolHashRepository.findByViewIn(any())) + .thenReturn( + List.of( + PoolHash.builder() + .view("pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy") + .id(1L) + .build(), + PoolHash.builder() + .view("pool1z5uqdk7dzdxaae5633fqfcu2eqzy3a3rgtuvy087fdld7yws0xt") + .id(2L) + .build())); + + when(rewardCheckpointRepository.findByStakeAddressIn(any())) + .thenReturn( + List.of( + RewardCheckpoint.builder() + .id(1L) + .stakeAddress("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") + .epochCheckpoint(413) + .build(), + RewardCheckpoint.builder() + .id(2L) + .stakeAddress("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") + .epochCheckpoint(413) + .build())); when(epochService.getCurrentEpoch()).thenReturn(416); @@ -154,18 +155,24 @@ void fetchData_shouldFetchAndSaveRewardData() throws Exception { @Test void getStakeAddressListNeedFetchData_shouldReturnStakeAddressList() throws Exception { // Setup - var checkpoints = List.of(RewardCheckpoint.builder().id(1L) - .stakeAddress("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") - .epochCheckpoint(413).build(), - RewardCheckpoint.builder().id(2L) - .stakeAddress("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") - .epochCheckpoint(414).build()); + var checkpoints = + List.of( + RewardCheckpoint.builder() + .id(1L) + .stakeAddress("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8") + .epochCheckpoint(413) + .build(), + RewardCheckpoint.builder() + .id(2L) + .stakeAddress("stake1u9nzg3s4wvstx0czh2asmeknfl80tn7z8nhm03smzunflas3m8ptg") + .epochCheckpoint(414) + .build()); when(rewardCheckpointRepository.findByStakeAddressIn(any())).thenReturn(checkpoints); when(epochService.getCurrentEpoch()).thenReturn(415); // Run the test - List result = rewardFetchingServiceImpl.getStakeAddressListNeedFetchData( - stakeAddressList); + List result = + rewardFetchingServiceImpl.getStakeAddressListNeedFetchData(stakeAddressList); // Verify assertEquals(List.of("stake1u9kdeq0fzxqdgtdk73mxxpa88e29vffkggctzgul7dyqwmsvfm6z8"), result); } From 7850b32e2d451648362feebd08b0159f837615ee Mon Sep 17 00:00:00 2001 From: Sotatek-ThinhVu Date: Tue, 30 Jan 2024 15:38:52 +0700 Subject: [PATCH 2/4] chore: update step check formatting when run tests --- .github/workflows/tests.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 25c64546..1e275368 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -34,6 +34,10 @@ jobs: run: | envsubst < ./.m2/settings.default.xml.tpl > ./.m2/settings.xml + - name: Check Formatting + run: | + mvn spotless:check + - name: Build run: | mvn --batch-mode --update-snapshots clean package -DskipTests From a13cf985c34fe4473c38f9848f19207eab1467ba Mon Sep 17 00:00:00 2001 From: Sotatek-DucPhung Date: Tue, 6 Feb 2024 15:48:07 +0700 Subject: [PATCH 3/4] feat: MET-1956 add bearerToken option for backendService --- README.md | 1 + docker-compose.yml | 1 + pom.xml | 2 +- .../explorer/rewards/config/KoiosClient.java | 35 ++++++++++++------- .../resources/config/application-dev.yaml | 2 ++ .../resources/config/application-local.yaml | 4 ++- .../resources/config/application-prod.yaml | 18 +++++++--- 7 files changed, 43 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 51d7fce0..7fa40b5f 100644 --- a/README.md +++ b/README.md @@ -43,3 +43,4 @@ To ensure the stability and reliability of this project, unit and mutation tests - FLYWAY_VALIDATE: whether to automatically call validate when performing a migration - KOIOS_BASE_URL_ENABLED: Set `true` to enable to use your Koios instance base URL, otherwise set `false` - KOIOS_BASE_URL: Koios instance base URL. +- KOIOS_AUTH_TOKEN: JWT Bearer Auth token generated via https://koios.rest Profile page diff --git a/docker-compose.yml b/docker-compose.yml index f303af00..0af8400e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,5 +27,6 @@ services: - FETCH_AND_SAVE_POOL_INFO_DATA_DELAY=${FETCH_AND_SAVE_POOL_INFO_DATA_DELAY} - KOIOS_BASE_URL_ENABLED=${KOIOS_BASE_URL_ENABLED} - KOIOS_BASE_URL=${KOIOS_BASE_URL} + - KOIOS_AUTH_TOKEN=${KOIOS_AUTH_TOKEN} ports: - ${SERVER_PORT}:${SERVER_PORT} diff --git a/pom.xml b/pom.xml index 1b0da61a..d4d29516 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ 17 1.18.26 1.18.24 - 1.17.2 + 1.18.1 0.1.0-SNAPSHOT 0.1.1-SNAPSHOT 0.1.12 diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/config/KoiosClient.java b/src/main/java/org/cardanofoundation/explorer/rewards/config/KoiosClient.java index 97814d8a..eb419463 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/config/KoiosClient.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/config/KoiosClient.java @@ -1,5 +1,7 @@ package org.cardanofoundation.explorer.rewards.config; +import jakarta.annotation.PostConstruct; + import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @@ -26,33 +28,40 @@ public class KoiosClient { @Value("${application.koios-base-url}") private String baseUrl; + @Value("${application.koios-auth-token}") + private String authToken; + + private BackendService backendService; + public AccountService accountService() { - return this.getBackendService().getAccountService(); + return this.backendService.getAccountService(); } public NetworkService networkService() { - return this.getBackendService().getNetworkService(); + return this.backendService.getNetworkService(); } public PoolService poolService() { - return this.getBackendService().getPoolService(); + return this.backendService.getPoolService(); } public EpochService epochService() { - return this.getBackendService().getEpochService(); + return this.backendService.getEpochService(); } - private BackendService getBackendService() { + @PostConstruct + void setBackendService() { if (Boolean.TRUE.equals(baseUrlEnabled)) { - return BackendFactory.getCustomRPCService(baseUrl); + backendService = BackendFactory.getCustomRPCService(baseUrl, authToken); } else { - return switch (value) { - case NetworkConstants.MAINNET -> BackendFactory.getKoiosMainnetService(); - case NetworkConstants.PREPROD -> BackendFactory.getKoiosPreprodService(); - case NetworkConstants.PREVIEW -> BackendFactory.getKoiosPreviewService(); - case NetworkConstants.GUILDNET -> BackendFactory.getKoiosGuildService(); - default -> throw new IllegalStateException("Unexpected value: " + value); - }; + backendService = + switch (value) { + case NetworkConstants.MAINNET -> BackendFactory.getKoiosMainnetService(authToken); + case NetworkConstants.PREPROD -> BackendFactory.getKoiosPreprodService(authToken); + case NetworkConstants.PREVIEW -> BackendFactory.getKoiosPreviewService(authToken); + case NetworkConstants.GUILDNET -> BackendFactory.getKoiosGuildService(authToken); + default -> throw new IllegalStateException("Unexpected value: " + value); + }; } } } diff --git a/src/main/resources/config/application-dev.yaml b/src/main/resources/config/application-dev.yaml index 4f417d70..119fec31 100644 --- a/src/main/resources/config/application-dev.yaml +++ b/src/main/resources/config/application-dev.yaml @@ -68,6 +68,8 @@ application: network: ${NETWORK:mainnet} koios-base-url-enabled: ${KOIOS_BASE_URL_ENABLED:false} koios-base-url: ${KOIOS_BASE_URL:https://api.koios.rest/api/v0/} + koios-auth-token: ${KOIOS_AUTH_TOKEN} + reward: list-size-each-thread: ${REWARD_LIST_SIZE_EACH_THREAD:5} epoch-stake: diff --git a/src/main/resources/config/application-local.yaml b/src/main/resources/config/application-local.yaml index e7a02f7f..746de083 100644 --- a/src/main/resources/config/application-local.yaml +++ b/src/main/resources/config/application-local.yaml @@ -68,7 +68,9 @@ spring: application: network: ${NETWORK:mainnet} koios-base-url-enabled: ${KOIOS_BASE_URL_ENABLED:false} - koios-base-url: ${KOIOS_BASE_URL:https://api.koios.rest/api/v0/} + koios-base-url: ${KOIOS_BASE_URL:https://koios-api.pro.dandelion-mainnet.eu-west-1.metadata.dev.cf-deployments.org/rpc/} + koios-auth-token: ${KOIOS_AUTH_TOKEN:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZGRyIjoic3Rha2UxdTg5eXZsNXB1OWhqenVkenF6amh3cHF2Y3Z3YTJ3dHNzNHljZG1seDM4Y2Foa2NwNWhzdmYiLCJleHAiOjE3Mzg2ODY5NjcsInRpZXIiOjEsInByb2pJRCI6ImNhcmRhbm9fZXhwbG9yZXJfcmV3YXJkIn0.vP9mbj4fDN3yz3c-kYloey9ssXbgqDcwVM3BSOJfk-g} + reward: list-size-each-thread: ${LIST_SIZE_EACH_THREAD:5} epoch-stake: diff --git a/src/main/resources/config/application-prod.yaml b/src/main/resources/config/application-prod.yaml index 99589d94..ece5d6a3 100644 --- a/src/main/resources/config/application-prod.yaml +++ b/src/main/resources/config/application-prod.yaml @@ -13,7 +13,7 @@ spring: hikari: pool-name: explorer-api-pool minimum-idle: 1 #minimum number of idle connections maintained by HikariCP in a connection pool - maximum-pool-size: 10 #maximum pool size + maximum-pool-size: 32 #maximum pool size idle-timeout: 300000 #maximum idle time for connection max-lifetime: 900000 #maximum lifetime in milliseconds of a connection in the pool after it is closed. connection-timeout: 50000 #maximum number of milliseconds that a client will wait for a connection @@ -63,15 +63,23 @@ spring: default-schema: ${spring.jpa.properties.hibernate.default_schema} schemas: ${spring.jpa.properties.hibernate.default_schema} validate-on-migrate: ${FLYWAY_VALIDATE:false} - + out-of-order: true application: network: ${NETWORK:mainnet} + koios-base-url-enabled: ${KOIOS_BASE_URL_ENABLED:false} + koios-base-url: ${KOIOS_BASE_URL:https://api.koios.rest/api/v0/} + koios-auth-token: ${KOIOS_AUTH_TOKEN} + reward: - list-size-each-thread: ${LIST_SIZE_EACH_THREAD:5} + list-size-each-thread: ${REWARD_LIST_SIZE_EACH_THREAD:5} epoch-stake: - list-size-each-thread: ${LIST_SIZE_EACH_THREAD:5} + list-size-each-thread: ${EPOCH_STAKE_LIST_SIZE_EACH_THREAD:5} pool-info: list-size-each-thread: ${POOL_INFO_LIST_SIZE_EACH_THREAD:500} job: enable: ${POOL_INFO_DATA_JOB_ENABLED:true} - fixed-delay: ${FETCH_AND_SAVE_POOL_INFO_DATA_DELAY:3600000} + fixed-delay: ${FETCH_AND_SAVE_POOL_INFO_DATA_DELAY:3600000} + +logging: + level: + rest.koios: ERROR \ No newline at end of file From 047617b60da26c76d53f685ee88c45e8dadf2f19 Mon Sep 17 00:00:00 2001 From: Sotatek-DucPhung Date: Thu, 15 Feb 2024 14:43:27 +0700 Subject: [PATCH 4/4] refactor: update rewards service after reduce common repository --- pom.xml | 14 ++--- .../concurrent/EpochConcurrentFetching.java | 2 +- .../rewards/controller/EpochController.java | 2 +- .../rewards/repository/AdaPotsRepository.java | 2 +- .../rewards/repository/BlockRepository.java | 2 +- .../rewards/repository/EpochRepository.java | 2 +- .../EpochStakeCheckpointRepository.java | 2 +- .../repository/EpochStakeRepository.java | 2 +- .../repository/PoolHashRepository.java | 2 +- .../PoolHistoryCheckpointRepository.java | 2 +- .../repository/PoolHistoryRepository.java | 2 +- .../PoolInfoCheckpointRepository.java | 2 +- .../repository/PoolInfoRepository.java | 2 +- .../RewardCheckpointRepository.java | 2 +- .../rewards/repository/RewardRepository.java | 2 +- .../repository/StakeAddressRepository.java | 2 +- .../JOOQEpochStakeCheckpointRepository.java | 6 +-- .../jooq/JOOQEpochStakeRepository.java | 6 +-- .../JOOQPoolHistoryCheckpointRepository.java | 6 +-- .../jooq/JOOQPoolHistoryRepository.java | 6 +-- .../JOOQPoolInfoCheckpointRepository.java | 6 +-- .../jooq/JOOQPoolInfoRepository.java | 6 +-- .../jooq/JOOQRewardCheckpointRepository.java | 6 +-- .../repository/jooq/JOOQRewardRepository.java | 6 +-- .../schedule/PoolInfoDataSchedule.java | 2 +- .../schedule/service/PoolInfoDataService.java | 4 +- .../rewards/service/EpochFetchingService.java | 2 +- .../impl/AdaPotsFetchingServiceImpl.java | 4 +- .../impl/EpochFetchingServiceImpl.java | 4 +- .../impl/EpochStakeFetchingServiceImpl.java | 8 +-- .../impl/PoolHistoryFetchingServiceImpl.java | 4 +- .../impl/PoolInfoFetchingServiceImpl.java | 6 +-- .../impl/RewardFetchingServiceImpl.java | 10 ++-- .../explorer/rewards/util/EntityUtil.java | 54 ------------------- .../EpochConcurrentFetchingTest.java | 2 +- .../controller/EpochControllerTest.java | 2 +- ...OOQEpochStakeCheckPointRepositoryTest.java | 6 +-- .../jooq/JOOQEpochStakeRepositoryTest.java | 10 ++-- ...OQPoolHistoryCheckPointRepositoryTest.java | 6 +-- .../jooq/JOOQPoolHistoryRepositoryTest.java | 6 +-- .../JOOQPoolInfoCheckPointRepositoryTest.java | 6 +-- .../jooq/JOOQPoolInfoRepositoryTest.java | 6 +-- .../JOOQRewardCheckpointRepositoryTest.java | 6 +-- .../jooq/JOOQRewardRepositoryTest.java | 12 ++--- .../schedule/PoolInfoDataScheduleTest.java | 2 +- .../service/PoolInfoDataServiceTest.java | 4 +- .../impl/AdaPotsFetchingServiceImplTest.java | 4 +- .../impl/EpochFetchingServiceImplTest.java | 4 +- .../EpochStakeFetchingServiceImplTest.java | 8 +-- .../PoolHistoryFetchingServiceImplTest.java | 6 +-- .../impl/PoolInfoFetchingServiceImplTest.java | 6 +-- .../impl/RewardFetchingServiceImplTest.java | 8 +-- 52 files changed, 116 insertions(+), 178 deletions(-) delete mode 100644 src/main/java/org/cardanofoundation/explorer/rewards/util/EntityUtil.java diff --git a/pom.xml b/pom.xml index 1b0da61a..2c083e39 100644 --- a/pom.xml +++ b/pom.xml @@ -13,9 +13,7 @@ 1.18.26 1.18.24 1.17.2 - 0.1.0-SNAPSHOT - 0.1.1-SNAPSHOT - 0.1.12 + 0.1.16-SNAPSHOT-PR173 3.0.5 9.16.0 3.10.0 @@ -61,16 +59,10 @@ test - - org.cardanofoundation.ledgersync - common - ${version.ledgersync-common} - - org.cardanofoundation.explorer - consumer-common - ${version.explorer-consumer-common} + common + ${version.explorer-common} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetching.java b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetching.java index eab3aa76..e959067f 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetching.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetching.java @@ -13,7 +13,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.common.entity.ledgersync.Epoch; import org.cardanofoundation.explorer.rewards.service.EpochFetchingService; @Component diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/controller/EpochController.java b/src/main/java/org/cardanofoundation/explorer/rewards/controller/EpochController.java index cd3d5171..33e62fe6 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/controller/EpochController.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/controller/EpochController.java @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.common.entity.ledgersync.Epoch; import org.cardanofoundation.explorer.rewards.concurrent.EpochConcurrentFetching; @RestController diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/AdaPotsRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/AdaPotsRepository.java index 1c2f9e07..69eaf072 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/AdaPotsRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/AdaPotsRepository.java @@ -5,7 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.query.Param; -import org.cardanofoundation.explorer.consumercommon.entity.AdaPots; +import org.cardanofoundation.explorer.common.entity.ledgersync.AdaPots; public interface AdaPotsRepository extends JpaRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/BlockRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/BlockRepository.java index 8be8b006..936f085e 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/BlockRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/BlockRepository.java @@ -4,7 +4,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import org.cardanofoundation.explorer.consumercommon.entity.Block; +import org.cardanofoundation.explorer.common.entity.ledgersync.Block; public interface BlockRepository extends JpaRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochRepository.java index 2596f34b..8584afc4 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochRepository.java @@ -10,7 +10,7 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.common.entity.ledgersync.Epoch; @Repository public interface EpochRepository extends JpaRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeCheckpointRepository.java index 4815ae33..2fe72abb 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeCheckpointRepository.java @@ -5,7 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStakeCheckpoint; @Repository public interface EpochStakeCheckpointRepository extends JpaRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeRepository.java index d17545de..9ca57c42 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/EpochStakeRepository.java @@ -3,7 +3,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStake; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStake; @Repository public interface EpochStakeRepository extends JpaRepository {} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHashRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHashRepository.java index 857e6cf3..a487b8a2 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHashRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHashRepository.java @@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; @Repository public interface PoolHashRepository extends JpaRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryCheckpointRepository.java index e8892029..9d53869c 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryCheckpointRepository.java @@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistoryCheckpoint; @Repository public interface PoolHistoryCheckpointRepository diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryRepository.java index a0a26442..74d9eec9 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolHistoryRepository.java @@ -3,7 +3,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistory; @Repository public interface PoolHistoryRepository extends JpaRepository {} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoCheckpointRepository.java index a4db41c3..d6be5f56 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoCheckpointRepository.java @@ -5,7 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfoCheckpoint; @Repository public interface PoolInfoCheckpointRepository extends JpaRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoRepository.java index 7212cd43..b0fd1805 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/PoolInfoRepository.java @@ -3,7 +3,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfo; @Repository public interface PoolInfoRepository extends JpaRepository {} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardCheckpointRepository.java index dad0d0a6..13c07485 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardCheckpointRepository.java @@ -5,7 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.RewardCheckpoint; @Repository public interface RewardCheckpointRepository extends JpaRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardRepository.java index c84701cc..6b37fc7f 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/RewardRepository.java @@ -3,7 +3,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.Reward; +import org.cardanofoundation.explorer.common.entity.ledgersync.Reward; @Repository public interface RewardRepository extends JpaRepository {} diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/StakeAddressRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/StakeAddressRepository.java index 4202b5ad..69303549 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/StakeAddressRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/StakeAddressRepository.java @@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress; +import org.cardanofoundation.explorer.common.entity.ledgersync.StakeAddress; @Repository public interface StakeAddressRepository extends JpaRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckpointRepository.java index 4235bbf5..8aba73bd 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckpointRepository.java @@ -13,9 +13,9 @@ import org.jooq.DSLContext; import org.jooq.Query; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStakeCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStakeCheckpoint_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @Component public class JOOQEpochStakeCheckpointRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepository.java index 98b53fea..f32be484 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepository.java @@ -14,9 +14,9 @@ import org.jooq.DSLContext; import org.jooq.Query; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStake; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStake_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStake; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStake_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @Component public class JOOQEpochStakeRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckpointRepository.java index c0465b3a..8c45d97c 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckpointRepository.java @@ -13,9 +13,9 @@ import org.jooq.DSLContext; import org.jooq.Query; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistoryCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistoryCheckpoint_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @Component public class JOOQPoolHistoryCheckpointRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepository.java index 33170b1d..1e188716 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepository.java @@ -12,9 +12,9 @@ import org.jooq.DSLContext; import org.jooq.Query; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistory; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistory_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @Component public class JOOQPoolHistoryRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckpointRepository.java index e3a900b3..4c6865d2 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckpointRepository.java @@ -12,9 +12,9 @@ import org.jooq.DSLContext; import org.jooq.Query; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfoCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfoCheckpoint_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @Component public class JOOQPoolInfoCheckpointRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepository.java index 286d5ad8..0b51323f 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepository.java @@ -12,9 +12,9 @@ import org.jooq.DSLContext; import org.jooq.Query; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfo; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfo_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @Component public class JOOQPoolInfoRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepository.java index 45c514df..bcd35e07 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepository.java @@ -12,9 +12,9 @@ import org.jooq.DSLContext; import org.jooq.Query; -import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.RewardCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.RewardCheckpoint_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @Component public class JOOQRewardCheckpointRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepository.java b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepository.java index 47964663..8bb0b1fb 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepository.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepository.java @@ -14,9 +14,9 @@ import org.jooq.DSLContext; import org.jooq.Query; -import org.cardanofoundation.explorer.consumercommon.entity.Reward; -import org.cardanofoundation.explorer.consumercommon.entity.Reward_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.Reward; +import org.cardanofoundation.explorer.common.entity.ledgersync.Reward_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @Repository public class JOOQRewardRepository { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataSchedule.java b/src/main/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataSchedule.java index 7d1f9a99..c1e9dbcc 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataSchedule.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataSchedule.java @@ -18,7 +18,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.schedule.service.PoolInfoDataService; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java b/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java index 7c9c1d14..58c98e38 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java @@ -20,8 +20,8 @@ import io.micrometer.common.util.StringUtils; import rest.koios.client.backend.api.base.exception.ApiException; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfo; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolInfoRepository; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochFetchingService.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochFetchingService.java index 10765212..8d65724e 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochFetchingService.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/EpochFetchingService.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.common.entity.ledgersync.Epoch; public interface EpochFetchingService { diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImpl.java index 128477c6..0a6e94fc 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImpl.java @@ -17,8 +17,8 @@ import rest.koios.client.backend.api.network.model.Totals; -import org.cardanofoundation.explorer.consumercommon.entity.AdaPots; -import org.cardanofoundation.explorer.consumercommon.entity.Block; +import org.cardanofoundation.explorer.common.entity.ledgersync.AdaPots; +import org.cardanofoundation.explorer.common.entity.ledgersync.Block; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.AdaPotsRepository; import org.cardanofoundation.explorer.rewards.repository.BlockRepository; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImpl.java index e1a78013..015c802e 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImpl.java @@ -18,8 +18,8 @@ import io.micrometer.common.util.StringUtils; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; -import org.cardanofoundation.explorer.consumercommon.enumeration.EraType; +import org.cardanofoundation.explorer.common.entity.enumeration.EraType; +import org.cardanofoundation.explorer.common.entity.ledgersync.Epoch; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.EpochRepository; import org.cardanofoundation.explorer.rewards.service.EpochFetchingService; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImpl.java index 14e0a01e..8c0de88c 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImpl.java @@ -23,10 +23,10 @@ import rest.koios.client.backend.api.account.model.AccountHistoryInner; import rest.koios.client.backend.api.base.exception.ApiException; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStake; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStake; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStakeCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.StakeAddress; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.EpochStakeCheckpointRepository; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java index 78b04eb8..1eb29cdd 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java @@ -21,8 +21,8 @@ import io.micrometer.common.util.StringUtils; import rest.koios.client.backend.api.base.exception.ApiException; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistory; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistoryCheckpoint; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.repository.PoolHistoryCheckpointRepository; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImpl.java index ddd4b20f..468ba922 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImpl.java @@ -20,9 +20,9 @@ import io.micrometer.common.util.StringUtils; import rest.koios.client.backend.api.base.exception.ApiException; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfo; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfoCheckpoint; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolInfoCheckpointRepository; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImpl.java index 5791f8cf..3b8c6cfa 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImpl.java @@ -23,11 +23,11 @@ import rest.koios.client.backend.api.account.model.AccountRewards; import rest.koios.client.backend.api.base.exception.ApiException; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.Reward; -import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress; -import org.cardanofoundation.explorer.consumercommon.enumeration.RewardType; +import org.cardanofoundation.explorer.common.entity.enumeration.RewardType; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.Reward; +import org.cardanofoundation.explorer.common.entity.ledgersync.RewardCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.StakeAddress; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.repository.RewardCheckpointRepository; diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/util/EntityUtil.java b/src/main/java/org/cardanofoundation/explorer/rewards/util/EntityUtil.java deleted file mode 100644 index 8503565c..00000000 --- a/src/main/java/org/cardanofoundation/explorer/rewards/util/EntityUtil.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.cardanofoundation.explorer.rewards.util; - -import java.lang.reflect.Field; -import java.util.List; - -import jakarta.persistence.Column; -import jakarta.persistence.Table; - -import org.cardanofoundation.explorer.consumercommon.entity.BaseEntity; - -public class EntityUtil { - - private final String schema; - - private final Class entityClass; - - public EntityUtil(String schema, Class entityClass) { - this.schema = schema; - this.entityClass = entityClass; - } - - /** - * @return the table name of the entity with the schema prefix. - */ - public String getTableName() { - return schema + "." + entityClass.getAnnotation(Table.class).name(); - } - - /** - * @param fieldName the entity field name - * @return the column database field name of the entity. - */ - public String getColumnField(String fieldName) { - Field field = getFieldByName(fieldName); - if (field != null) { - return field.getAnnotation(Column.class).name(); - } - return null; - } - - /** - * @param fieldName - * @return the field of the entity with the given name. - */ - private Field getFieldByName(String fieldName) { - List fields = List.of(entityClass.getDeclaredFields()); - for (Field field : fields) { - if (field.getName().equals(fieldName)) { - return field; - } - } - return null; - } -} diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetchingTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetchingTest.java index 80d6dd33..8da0b10d 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetchingTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/concurrent/EpochConcurrentFetchingTest.java @@ -16,7 +16,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.common.entity.ledgersync.Epoch; import org.cardanofoundation.explorer.rewards.service.EpochFetchingService; @ExtendWith(MockitoExtension.class) diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochControllerTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochControllerTest.java index 856864d0..30d5dc58 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochControllerTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/controller/EpochControllerTest.java @@ -19,7 +19,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; +import org.cardanofoundation.explorer.common.entity.ledgersync.Epoch; import org.cardanofoundation.explorer.rewards.concurrent.EpochConcurrentFetching; @ExtendWith(SpringExtension.class) diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckPointRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckPointRepositoryTest.java index cf95eaa0..3e805d0b 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckPointRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeCheckPointRepositoryTest.java @@ -19,9 +19,9 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStakeCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStakeCheckpoint_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @JooqTest @ActiveProfiles("integration-test") diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepositoryTest.java index 3ccd3be2..fb4eef8e 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQEpochStakeRepositoryTest.java @@ -22,11 +22,11 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStake; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStake_; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStake; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStake_; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.StakeAddress; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @JooqTest @ActiveProfiles("integration-test") diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckPointRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckPointRepositoryTest.java index 451e2f16..ed8bb67f 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckPointRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryCheckPointRepositoryTest.java @@ -19,9 +19,9 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistoryCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistoryCheckpoint_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @JooqTest @ActiveProfiles("integration-test") diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepositoryTest.java index 7089743a..5ebfd47a 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolHistoryRepositoryTest.java @@ -22,9 +22,9 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistory; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistory_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @JooqTest @ActiveProfiles("integration-test") diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckPointRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckPointRepositoryTest.java index 065688f3..d0b1d98e 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckPointRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoCheckPointRepositoryTest.java @@ -19,9 +19,9 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfoCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfoCheckpoint_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @JooqTest @ActiveProfiles("integration-test") diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepositoryTest.java index 778dc9a8..baee9b08 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQPoolInfoRepositoryTest.java @@ -22,9 +22,9 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfo; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfo_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @JooqTest @ActiveProfiles("integration-test") diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepositoryTest.java index 1b0878f5..1dc1ad97 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardCheckpointRepositoryTest.java @@ -19,9 +19,9 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint_; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.ledgersync.RewardCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.RewardCheckpoint_; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @JooqTest @ActiveProfiles("integration-test") diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepositoryTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepositoryTest.java index a58cb2a3..42fd6e5b 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepositoryTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/repository/jooq/JOOQRewardRepositoryTest.java @@ -22,12 +22,12 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.Reward; -import org.cardanofoundation.explorer.consumercommon.entity.Reward_; -import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress; -import org.cardanofoundation.explorer.consumercommon.enumeration.RewardType; -import org.cardanofoundation.explorer.rewards.util.EntityUtil; +import org.cardanofoundation.explorer.common.entity.enumeration.RewardType; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.Reward; +import org.cardanofoundation.explorer.common.entity.ledgersync.Reward_; +import org.cardanofoundation.explorer.common.entity.ledgersync.StakeAddress; +import org.cardanofoundation.explorer.common.utils.EntityUtil; @JooqTest @ActiveProfiles("integration-test") diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataScheduleTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataScheduleTest.java index 65a0714b..6d0b06d3 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataScheduleTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/schedule/PoolInfoDataScheduleTest.java @@ -16,7 +16,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.schedule.service.PoolInfoDataService; diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataServiceTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataServiceTest.java index a9019846..2c8bec67 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataServiceTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataServiceTest.java @@ -20,8 +20,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfo; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolInfoRepository; diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImplTest.java index eb838a6f..39f59206 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/AdaPotsFetchingServiceImplTest.java @@ -16,8 +16,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.cardanofoundation.explorer.consumercommon.entity.AdaPots; -import org.cardanofoundation.explorer.consumercommon.entity.Block; +import org.cardanofoundation.explorer.common.entity.ledgersync.AdaPots; +import org.cardanofoundation.explorer.common.entity.ledgersync.Block; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.AdaPotsRepository; import org.cardanofoundation.explorer.rewards.repository.BlockRepository; diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImplTest.java index 7a61e1de..18385c4e 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochFetchingServiceImplTest.java @@ -21,8 +21,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.cardanofoundation.explorer.consumercommon.entity.Epoch; -import org.cardanofoundation.explorer.consumercommon.enumeration.EraType; +import org.cardanofoundation.explorer.common.entity.enumeration.EraType; +import org.cardanofoundation.explorer.common.entity.ledgersync.Epoch; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.EpochRepository; diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImplTest.java index de0a8f1a..3f520c1d 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/EpochStakeFetchingServiceImplTest.java @@ -18,10 +18,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStake; -import org.cardanofoundation.explorer.consumercommon.entity.EpochStakeCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStake; +import org.cardanofoundation.explorer.common.entity.ledgersync.EpochStakeCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.StakeAddress; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.EpochStakeCheckpointRepository; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImplTest.java index 2099b8a4..b39da19d 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImplTest.java @@ -16,9 +16,9 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistory; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHistoryCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistory; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHistoryCheckpoint; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.repository.PoolHistoryCheckpointRepository; diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImplTest.java index a3983165..c11b019c 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/PoolInfoFetchingServiceImplTest.java @@ -14,9 +14,9 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfo; -import org.cardanofoundation.explorer.consumercommon.entity.PoolInfoCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfo; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolInfoCheckpoint; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.repository.jooq.JOOQPoolInfoCheckpointRepository; diff --git a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImplTest.java b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImplTest.java index 06ff2beb..d8d2efb6 100644 --- a/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImplTest.java +++ b/src/test/java/org/cardanofoundation/explorer/rewards/service/impl/RewardFetchingServiceImplTest.java @@ -19,10 +19,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.cardanofoundation.explorer.consumercommon.entity.PoolHash; -import org.cardanofoundation.explorer.consumercommon.entity.Reward; -import org.cardanofoundation.explorer.consumercommon.entity.RewardCheckpoint; -import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress; +import org.cardanofoundation.explorer.common.entity.ledgersync.PoolHash; +import org.cardanofoundation.explorer.common.entity.ledgersync.Reward; +import org.cardanofoundation.explorer.common.entity.ledgersync.RewardCheckpoint; +import org.cardanofoundation.explorer.common.entity.ledgersync.StakeAddress; import org.cardanofoundation.explorer.rewards.config.KoiosClient; import org.cardanofoundation.explorer.rewards.repository.PoolHashRepository; import org.cardanofoundation.explorer.rewards.repository.RewardCheckpointRepository;