mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-22 07:24:23 +01:00
only load channels when needed
This commit is contained in:
@@ -16,6 +16,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -100,15 +101,15 @@ public class ChannelService {
|
||||
}
|
||||
|
||||
public Stream<LocalChannel> getAllLocalChannels() {
|
||||
Set<LocalOpenChannel> openChannels = getOpenChannels();
|
||||
Set<WaitingCloseChannel> waitingCloseChannels = getWaitingCloseChannels();
|
||||
Set<ForceClosingChannel> forceClosingChannels = getForceClosingChannels();
|
||||
Set<ClosedChannel> closedChannels = getClosedChannels();
|
||||
Supplier<Set<LocalOpenChannel>> openChannels = this::getOpenChannels;
|
||||
Supplier<Set<ClosedChannel>> closedChannels = this::getClosedChannels;
|
||||
Supplier<Set<WaitingCloseChannel>> waitingCloseChannels = this::getWaitingCloseChannels;
|
||||
Supplier<Set<ForceClosingChannel>> forceClosingChannels = this::getForceClosingChannels;
|
||||
return Stream.of(
|
||||
openChannels,
|
||||
closedChannels,
|
||||
waitingCloseChannels,
|
||||
forceClosingChannels
|
||||
).flatMap(Collection::stream);
|
||||
).map(Supplier::get).flatMap(Collection::stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ import static de.cotto.lndmanagej.model.WaitingCloseChannelFixtures.WAITING_CLOS
|
||||
import static de.cotto.lndmanagej.model.WaitingCloseChannelFixtures.WAITING_CLOSE_CHANNEL_2;
|
||||
import static de.cotto.lndmanagej.model.WaitingCloseChannelFixtures.WAITING_CLOSE_CHANNEL_TO_NODE_3;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -65,6 +67,15 @@ class ChannelServiceTest {
|
||||
assertThat(channelService.getLocalChannel(CHANNEL_ID)).contains(LOCAL_OPEN_CHANNEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getLocalChannel_open_tried_first() {
|
||||
when(grpcChannels.getChannels()).thenReturn(Set.of(LOCAL_OPEN_CHANNEL));
|
||||
assertThat(channelService.getLocalChannel(CHANNEL_ID)).contains(LOCAL_OPEN_CHANNEL);
|
||||
verify(grpcClosedChannels, never()).getClosedChannels();
|
||||
verify(grpcChannels, never()).getForceClosingChannels();
|
||||
verify(grpcChannels, never()).getWaitingCloseChannels();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getLocalChannel_waiting_close_channel() {
|
||||
when(grpcChannels.getWaitingCloseChannels()).thenReturn(Set.of(WAITING_CLOSE_CHANNEL, WAITING_CLOSE_CHANNEL_2));
|
||||
@@ -83,6 +94,14 @@ class ChannelServiceTest {
|
||||
assertThat(channelService.getLocalChannel(CHANNEL_ID)).contains(CLOSED_CHANNEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getLocalChannel_closed_tried_second() {
|
||||
when(grpcClosedChannels.getClosedChannels()).thenReturn(Set.of(CLOSED_CHANNEL));
|
||||
assertThat(channelService.getLocalChannel(CHANNEL_ID)).contains(CLOSED_CHANNEL);
|
||||
verify(grpcChannels, never()).getForceClosingChannels();
|
||||
verify(grpcChannels, never()).getWaitingCloseChannels();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getOpenChannel() {
|
||||
when(grpcChannels.getChannel(CHANNEL_ID_2)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL));
|
||||
|
||||
Reference in New Issue
Block a user