diff --git a/backend/src/main/java/de/cotto/lndmanagej/service/OnlinePeersService.java b/backend/src/main/java/de/cotto/lndmanagej/service/OnlinePeersService.java index 5bc847a2..d7198829 100644 --- a/backend/src/main/java/de/cotto/lndmanagej/service/OnlinePeersService.java +++ b/backend/src/main/java/de/cotto/lndmanagej/service/OnlinePeersService.java @@ -17,7 +17,7 @@ import java.util.Objects; @Component public class OnlinePeersService { - private static final int DAYS_FOR_ONLINE_PERCENTAGE = 7; + private static final int DAYS_FOR_ONLINE_PERCENTAGE = 14; private static final int DAYS_FOR_CHANGES = 7; private static final Duration CACHE_REFRESH = Duration.ofMinutes(1); private static final Duration CACHE_EXPIRY = Duration.ofMinutes(2); diff --git a/backend/src/test/java/de/cotto/lndmanagej/service/OnlinePeersServiceTest.java b/backend/src/test/java/de/cotto/lndmanagej/service/OnlinePeersServiceTest.java index 85213272..37f55c2d 100644 --- a/backend/src/test/java/de/cotto/lndmanagej/service/OnlinePeersServiceTest.java +++ b/backend/src/test/java/de/cotto/lndmanagej/service/OnlinePeersServiceTest.java @@ -22,6 +22,7 @@ import static de.cotto.lndmanagej.model.OnlineStatusFixtures.ONLINE_STATUS_OFFLI import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; @SuppressWarnings("CPD-START") @@ -29,6 +30,7 @@ import static org.mockito.Mockito.when; class OnlinePeersServiceTest { private static final ZonedDateTime NOW = ZonedDateTime.now(ZoneOffset.UTC); private static final int SEVEN_DAYS = 7; + private static final int FOURTEEN_DAYS = 14; @InjectMocks private OnlinePeersService onlinePeersService; @@ -39,12 +41,12 @@ class OnlinePeersServiceTest { @Test void with_time_if_given_status_matches_last_known_status() { when(dao.getMostRecentOnlineStatus(PUBKEY)).thenReturn(Optional.of(ONLINE_STATUS)); - mockFor23PercentOffline(); + mockFor12PercentOffline(); assertThat(onlinePeersService.getOnlineReport(NODE_PEER)).isEqualTo(new OnlineReport( true, OnlineReportFixtures.TIMESTAMP, - 77, - 7, + 88, + 14, 1, 7 )); @@ -74,7 +76,7 @@ class OnlinePeersServiceTest { @Test void getDaysForOnlinePercentage() { - assertThat(onlinePeersService.getDaysForOnlinePercentage()).isEqualTo(7); + assertThat(onlinePeersService.getDaysForOnlinePercentage()).isEqualTo(FOURTEEN_DAYS); } @Test @@ -85,7 +87,7 @@ class OnlinePeersServiceTest { @Test void getOnlinePercentage_always_online() { ZonedDateTime early = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); - when(dao.getAllForPeerUpToAgeInDays(PUBKEY, SEVEN_DAYS)) + when(dao.getAllForPeerUpToAgeInDays(PUBKEY, FOURTEEN_DAYS)) .thenReturn(List.of(new OnlineStatus(true, early))); assertThat(onlinePeersService.getOnlinePercentage(PUBKEY)).isEqualTo(100); } @@ -93,7 +95,7 @@ class OnlinePeersServiceTest { @Test void getOnlinePercentage_always_offline() { ZonedDateTime early = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); - when(dao.getAllForPeerUpToAgeInDays(PUBKEY, SEVEN_DAYS)) + when(dao.getAllForPeerUpToAgeInDays(PUBKEY, FOURTEEN_DAYS)) .thenReturn(List.of(new OnlineStatus(false, early))); assertThat(onlinePeersService.getOnlinePercentage(PUBKEY)).isZero(); } @@ -101,7 +103,7 @@ class OnlinePeersServiceTest { @Test void getOnlinePercentage_limited_data_offline() { ZonedDateTime oneHourAgo = NOW.minusHours(1); - when(dao.getAllForPeerUpToAgeInDays(PUBKEY, SEVEN_DAYS)) + when(dao.getAllForPeerUpToAgeInDays(PUBKEY, FOURTEEN_DAYS)) .thenReturn(List.of(new OnlineStatus(false, oneHourAgo))); assertThat(onlinePeersService.getOnlinePercentage(PUBKEY)).isZero(); } @@ -109,7 +111,7 @@ class OnlinePeersServiceTest { @Test void getOnlinePercentage_limited_data_online() { ZonedDateTime oneHourAgo = NOW.minusHours(1); - when(dao.getAllForPeerUpToAgeInDays(PUBKEY, SEVEN_DAYS)) + when(dao.getAllForPeerUpToAgeInDays(PUBKEY, FOURTEEN_DAYS)) .thenReturn(List.of(new OnlineStatus(true, oneHourAgo))); assertThat(onlinePeersService.getOnlinePercentage(PUBKEY)).isEqualTo(100); } @@ -118,7 +120,7 @@ class OnlinePeersServiceTest { void getOnlinePercentage_limited_data_online_then_offline() { ZonedDateTime twoHoursAgo = NOW.minusHours(2); ZonedDateTime oneHourAgo = NOW.minusHours(1); - when(dao.getAllForPeerUpToAgeInDays(PUBKEY, SEVEN_DAYS)).thenReturn(List.of( + when(dao.getAllForPeerUpToAgeInDays(PUBKEY, FOURTEEN_DAYS)).thenReturn(List.of( new OnlineStatus(true, oneHourAgo), new OnlineStatus(false, twoHoursAgo) )); @@ -132,7 +134,7 @@ class OnlinePeersServiceTest { ZonedDateTime threeHoursAgo = NOW.minusHours(3); ZonedDateTime twoHoursAgo = NOW.minusHours(2); ZonedDateTime oneHourAgo = NOW.minusHours(1); - when(dao.getAllForPeerUpToAgeInDays(PUBKEY, SEVEN_DAYS)).thenReturn(List.of( + when(dao.getAllForPeerUpToAgeInDays(PUBKEY, FOURTEEN_DAYS)).thenReturn(List.of( new OnlineStatus(true, oneHourAgo), new OnlineStatus(false, twoHoursAgo), new OnlineStatus(true, threeHoursAgo), @@ -146,7 +148,7 @@ class OnlinePeersServiceTest { void getOnlinePercentage_limited_data_offline_then_online() { ZonedDateTime twoHoursAgo = NOW.minusHours(2); ZonedDateTime oneHourAgo = NOW.minusHours(1); - when(dao.getAllForPeerUpToAgeInDays(PUBKEY, SEVEN_DAYS)).thenReturn(List.of( + when(dao.getAllForPeerUpToAgeInDays(PUBKEY, FOURTEEN_DAYS)).thenReturn(List.of( new OnlineStatus(false, oneHourAgo), new OnlineStatus(true, twoHoursAgo) )); @@ -158,23 +160,23 @@ class OnlinePeersServiceTest { ZonedDateTime twoYearsAgo = NOW.minusYears(2); ZonedDateTime oneYearAgo = NOW.minusYears(1); ZonedDateTime thirteenDaysAgo = NOW.minusDays(6); - when(dao.getAllForPeerUpToAgeInDays(PUBKEY, SEVEN_DAYS)).thenReturn(List.of( + when(dao.getAllForPeerUpToAgeInDays(PUBKEY, FOURTEEN_DAYS)).thenReturn(List.of( new OnlineStatus(true, thirteenDaysAgo), new OnlineStatus(false, oneYearAgo), new OnlineStatus(true, twoYearsAgo) )); - assertThat(onlinePeersService.getOnlinePercentage(PUBKEY)).isCloseTo(85, offset(1)); + assertThat(onlinePeersService.getOnlinePercentage(PUBKEY)).isCloseTo(42, offset(1)); } @Test void getOnlinePercentage_is_rounded() { - mockFor23PercentOffline(); - assertThat(onlinePeersService.getOnlinePercentage(PUBKEY)).isCloseTo(77, offset(1)); + mockFor12PercentOffline(); + assertThat(onlinePeersService.getOnlinePercentage(PUBKEY)).isCloseTo(88, offset(1)); } @Test void getDaysForChanges() { - assertThat(onlinePeersService.getDaysForChanges()).isEqualTo(7); + assertThat(onlinePeersService.getDaysForChanges()).isEqualTo(SEVEN_DAYS); } @Test @@ -247,12 +249,14 @@ class OnlinePeersServiceTest { assertThat(since.getNano()).isZero(); } - private void mockFor23PercentOffline() { - ZonedDateTime longAgo = NOW.minusDays(14); + private void mockFor12PercentOffline() { + ZonedDateTime longAgo = NOW.minusDays(21); ZonedDateTime offlineSince = NOW.minusMinutes(2318); - when(dao.getAllForPeerUpToAgeInDays(PUBKEY, SEVEN_DAYS)).thenReturn(List.of( + List onlineStatusList = List.of( new OnlineStatus(false, offlineSince), new OnlineStatus(true, longAgo) - )); + ); + lenient().when(dao.getAllForPeerUpToAgeInDays(PUBKEY, SEVEN_DAYS)).thenReturn(onlineStatusList); + when(dao.getAllForPeerUpToAgeInDays(PUBKEY, FOURTEEN_DAYS)).thenReturn(onlineStatusList); } } \ No newline at end of file diff --git a/model/src/test/java/de/cotto/lndmanagej/model/OnlineReportTest.java b/model/src/test/java/de/cotto/lndmanagej/model/OnlineReportTest.java index c9f88820..6c3a0eea 100644 --- a/model/src/test/java/de/cotto/lndmanagej/model/OnlineReportTest.java +++ b/model/src/test/java/de/cotto/lndmanagej/model/OnlineReportTest.java @@ -28,7 +28,7 @@ class OnlineReportTest { @Test void daysForOnlinePercentage() { - assertThat(ONLINE_REPORT.daysForOnlinePercentage()).isEqualTo(7); + assertThat(ONLINE_REPORT.daysForOnlinePercentage()).isEqualTo(14); } @Test @@ -46,7 +46,7 @@ class OnlineReportTest { assertThat(OnlineReport.createFromStatus( ONLINE_STATUS, 77, - 7, + 14, 5, 7 )).isEqualTo(ONLINE_REPORT); diff --git a/model/src/test/java/de/cotto/lndmanagej/model/warnings/NodeOnlinePercentageWarningTest.java b/model/src/test/java/de/cotto/lndmanagej/model/warnings/NodeOnlinePercentageWarningTest.java index 230211a6..ed60dc5d 100644 --- a/model/src/test/java/de/cotto/lndmanagej/model/warnings/NodeOnlinePercentageWarningTest.java +++ b/model/src/test/java/de/cotto/lndmanagej/model/warnings/NodeOnlinePercentageWarningTest.java @@ -20,12 +20,12 @@ class NodeOnlinePercentageWarningTest { @Test void description() { assertThat(NODE_ONLINE_PERCENTAGE_WARNING.description()) - .isEqualTo("Node has been online 51% in the past 7 days"); + .isEqualTo("Node has been online 51% in the past 14 days"); } @Test void description_2() { assertThat(NODE_ONLINE_PERCENTAGE_WARNING_2.description()) - .isEqualTo("Node has been online 1% in the past 14 days"); + .isEqualTo("Node has been online 1% in the past 21 days"); } } \ No newline at end of file diff --git a/model/src/testFixtures/java/de/cotto/lndmanagej/model/NodeWarningFixtures.java b/model/src/testFixtures/java/de/cotto/lndmanagej/model/NodeWarningFixtures.java index d9798f94..d032ec55 100644 --- a/model/src/testFixtures/java/de/cotto/lndmanagej/model/NodeWarningFixtures.java +++ b/model/src/testFixtures/java/de/cotto/lndmanagej/model/NodeWarningFixtures.java @@ -6,9 +6,9 @@ import de.cotto.lndmanagej.model.warnings.NodeOnlinePercentageWarning; public class NodeWarningFixtures { public static final NodeOnlinePercentageWarning NODE_ONLINE_PERCENTAGE_WARNING = - new NodeOnlinePercentageWarning(51, 7); + new NodeOnlinePercentageWarning(51, 14); public static final NodeOnlinePercentageWarning NODE_ONLINE_PERCENTAGE_WARNING_2 = - new NodeOnlinePercentageWarning(1, 14); + new NodeOnlinePercentageWarning(1, 21); public static final NodeOnlineChangesWarning NODE_ONLINE_CHANGES_WARNING = new NodeOnlineChangesWarning(123, 7); public static final NodeOnlineChangesWarning NODE_ONLINE_CHANGES_WARNING_2 = diff --git a/model/src/testFixtures/java/de/cotto/lndmanagej/model/OnlineReportFixtures.java b/model/src/testFixtures/java/de/cotto/lndmanagej/model/OnlineReportFixtures.java index bce5b569..a85312a5 100644 --- a/model/src/testFixtures/java/de/cotto/lndmanagej/model/OnlineReportFixtures.java +++ b/model/src/testFixtures/java/de/cotto/lndmanagej/model/OnlineReportFixtures.java @@ -7,6 +7,6 @@ import static java.time.ZoneOffset.UTC; public class OnlineReportFixtures { public static final ZonedDateTime TIMESTAMP = LocalDateTime.of(2021, 12, 23, 1, 2, 3).atZone(UTC); - public static final OnlineReport ONLINE_REPORT = new OnlineReport(true, TIMESTAMP, 77, 7, 5, 7); - public static final OnlineReport ONLINE_REPORT_OFFLINE = new OnlineReport(false, TIMESTAMP, 85, 7, 123, 7); + public static final OnlineReport ONLINE_REPORT = new OnlineReport(true, TIMESTAMP, 77, 14, 5, 7); + public static final OnlineReport ONLINE_REPORT_OFFLINE = new OnlineReport(false, TIMESTAMP, 85, 14, 123, 7); } diff --git a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java index 4d8e4782..8535003d 100644 --- a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java +++ b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java @@ -111,7 +111,7 @@ class NodeControllerIT { .andExpect(jsonPath("$.feeReport.earned", is("1234"))) .andExpect(jsonPath("$.feeReport.sourced", is("567"))) .andExpect(jsonPath("$.nodeWarnings", containsInAnyOrder( - "Node has been online 51% in the past 7 days", + "Node has been online 51% in the past 14 days", "Node changed between online and offline 123 times in the past 7 days", "No flow in the past 16 days" ))) @@ -120,7 +120,7 @@ class NodeControllerIT { .andExpect(jsonPath("$.onChainCosts.sweepCosts", is("3000"))) .andExpect(jsonPath("$.onlineReport.online", is(true))) .andExpect(jsonPath("$.onlineReport.onlinePercentage", is(77))) - .andExpect(jsonPath("$.onlineReport.daysForOnlinePercentage", is(7))) + .andExpect(jsonPath("$.onlineReport.daysForOnlinePercentage", is(14))) .andExpect(jsonPath("$.onlineReport.changes", is(5))) .andExpect(jsonPath("$.onlineReport.daysForChanges", is(7))) .andExpect(jsonPath("$.onlineReport.since", is("2021-12-23T01:02:03Z"))); diff --git a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/WarningsControllerIT.java b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/WarningsControllerIT.java index 21954fcc..daa0a7b8 100644 --- a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/WarningsControllerIT.java +++ b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/WarningsControllerIT.java @@ -37,7 +37,7 @@ class WarningsControllerIT { mockMvc.perform(get(NODE_PREFIX + "/warnings")) .andExpect(jsonPath("$.nodeWarnings", containsInAnyOrder( "No flow in the past 16 days", - "Node has been online 51% in the past 7 days", + "Node has been online 51% in the past 14 days", "Node changed between online and offline 123 times in the past 7 days" ))); } diff --git a/web/src/test/java/de/cotto/lndmanagej/controller/dto/NodeWarningsDtoTest.java b/web/src/test/java/de/cotto/lndmanagej/controller/dto/NodeWarningsDtoTest.java index 4d2fafaf..9c0c53cd 100644 --- a/web/src/test/java/de/cotto/lndmanagej/controller/dto/NodeWarningsDtoTest.java +++ b/web/src/test/java/de/cotto/lndmanagej/controller/dto/NodeWarningsDtoTest.java @@ -12,7 +12,7 @@ class NodeWarningsDtoTest { void createFromModel() { assertThat(NodeWarningsDto.createFromModel(NODE_WARNINGS)).isEqualTo(new NodeWarningsDto(Set.of( "No flow in the past 16 days", - "Node has been online 51% in the past 7 days", + "Node has been online 51% in the past 14 days", "Node changed between online and offline 123 times in the past 7 days" ))); }