use of tech.pegasys.teku.network.p2p.peer.StubPeer in project teku by ConsenSys.
the class Eth2PeerSelectionStrategyTest method selectPeersToDisconnect_shouldDisconnectLowestScoringPeersWhenPeerCountExceedsUpperBound.
@Test
void selectPeersToDisconnect_shouldDisconnectLowestScoringPeersWhenPeerCountExceedsUpperBound() {
final Eth2PeerSelectionStrategy strategy = createStrategy(0, 1, 0);
final StubPeer peer1 = new StubPeer(new MockNodeId(1));
final StubPeer peer2 = new StubPeer(new MockNodeId(2));
final StubPeer peer3 = new StubPeer(new MockNodeId(3));
peerScorer.setScore(peer1.getId(), 100);
peerScorer.setScore(peer2.getId(), 200);
peerScorer.setScore(peer3.getId(), 150);
when(network.getPeerCount()).thenReturn(3);
when(network.streamPeers()).thenReturn(Stream.of(peer1, peer2, peer3));
assertThat(strategy.selectPeersToDisconnect(network, peerPools)).containsExactlyInAnyOrder(peer1, peer3);
}
use of tech.pegasys.teku.network.p2p.peer.StubPeer in project teku by ConsenSys.
the class Eth2PeerSelectionStrategyTest method selectPeersToDisconnect_shouldNotDisconnectFromStaticPeers.
@Test
void selectPeersToDisconnect_shouldNotDisconnectFromStaticPeers() {
final Eth2PeerSelectionStrategy strategy = createStrategy(0, 0, 0);
final StubPeer peer1 = new StubPeer(new MockNodeId(1));
final StubPeer peer2 = new StubPeer(new MockNodeId(2));
final StubPeer peer3 = new StubPeer(new MockNodeId(3));
when(network.getPeerCount()).thenReturn(3);
when(network.streamPeers()).thenReturn(Stream.of(peer1, peer2, peer3));
peerPools.addPeerToPool(peer2.getId(), PeerPool.STATIC);
assertThat(strategy.selectPeersToDisconnect(network, peerPools)).containsExactlyInAnyOrder(peer1, peer3);
}
use of tech.pegasys.teku.network.p2p.peer.StubPeer in project teku by ConsenSys.
the class Eth2PeerSelectionStrategyTest method selectPeersToDisconnect_shouldNotDisconnectRandomlySelectedPeersBasedOnScore.
@Test
void selectPeersToDisconnect_shouldNotDisconnectRandomlySelectedPeersBasedOnScore() {
final Eth2PeerSelectionStrategy strategy = createStrategy(2, 2, 1);
final StubPeer peer1 = new StubPeer(new MockNodeId(1));
final StubPeer peer2 = new StubPeer(new MockNodeId(2));
final StubPeer peer3 = new StubPeer(new MockNodeId(3));
when(network.getPeerCount()).thenReturn(3);
when(network.streamPeers()).thenReturn(Stream.of(peer1, peer2, peer3));
peerPools.addPeerToPool(peer2.getId(), PeerPool.RANDOMLY_SELECTED);
peerScorer.setScore(peer1.getId(), 100);
peerScorer.setScore(peer2.getId(), 0);
peerScorer.setScore(peer3.getId(), 50);
// peer2 has the lowest score but is safe because it's in the randomly selected pool
assertThat(strategy.selectPeersToDisconnect(network, peerPools)).containsExactlyInAnyOrder(peer3);
}
Aggregations