use of tech.pegasys.teku.networking.p2p.mock.MockNodeId in project teku by ConsenSys.
the class FetchBlockTaskTest method registerNewPeer.
private Eth2Peer registerNewPeer(final int id) {
final Eth2Peer peer = mock(Eth2Peer.class);
when(peer.getOutstandingRequests()).thenReturn(0);
when(peer.getId()).thenReturn(new MockNodeId(id));
peers.add(peer);
return peer;
}
use of tech.pegasys.teku.networking.p2p.mock.MockNodeId in project teku by ConsenSys.
the class Eth2PeerManagerTest method createPeer.
private Peer createPeer(final int id) {
final Peer peer = mock(Peer.class);
final Eth2Peer eth2Peer = createEth2Peer(peer);
eth2Peers.put(peer, eth2Peer);
when(peer.getId()).thenReturn(new MockNodeId(id));
when(eth2PeerFactory.create(same(peer), any())).thenReturn(eth2Peer);
return peer;
}
use of tech.pegasys.teku.networking.p2p.mock.MockNodeId in project teku by ConsenSys.
the class Eth2PeerSelectionStrategyTest method setUp.
@BeforeEach
void setUp() {
when(peerSubnetSubscriptions.createScorer()).thenReturn(peerScorer);
when(reputationManager.isConnectionInitiationAllowed(any())).thenReturn(true);
when(network.createPeerAddress(any(DiscoveryPeer.class))).thenAnswer(invocation -> {
final DiscoveryPeer peer = invocation.getArgument(0);
return new PeerAddress(new MockNodeId(peer.getPublicKey()));
});
}
use of tech.pegasys.teku.networking.p2p.mock.MockNodeId in project teku by ConsenSys.
the class Eth2PeerSelectionStrategyTest method selectPeersToDisconnect_shouldDisconnectExcessRandomlySelectedPeersWhenOutscored.
@Test
void selectPeersToDisconnect_shouldDisconnectExcessRandomlySelectedPeersWhenOutscored() {
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(peer1.getId(), PeerPool.RANDOMLY_SELECTED);
peerPools.addPeerToPool(peer2.getId(), PeerPool.RANDOMLY_SELECTED);
peerScorer.setScore(peer1.getId(), 100);
peerScorer.setScore(peer2.getId(), 50);
peerScorer.setScore(peer3.getId(), 250);
withShuffleOrder(peer2, peer1, peer3);
// Peer2 was dropped from the random pool and had the worst score so got dropped
assertThat(strategy.selectPeersToDisconnect(network, peerPools)).containsExactlyInAnyOrder(peer2);
}
use of tech.pegasys.teku.networking.p2p.mock.MockNodeId in project teku by ConsenSys.
the class Eth2PeerSelectionStrategyTest method selectPeersToDisconnect_shouldMoveExcessRandomlySelectedPeersBackToScoreBasedPool.
@Test
void selectPeersToDisconnect_shouldMoveExcessRandomlySelectedPeersBackToScoreBasedPool() {
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(peer1.getId(), PeerPool.RANDOMLY_SELECTED);
peerPools.addPeerToPool(peer2.getId(), PeerPool.RANDOMLY_SELECTED);
peerScorer.setScore(peer1.getId(), 100);
peerScorer.setScore(peer2.getId(), 200);
peerScorer.setScore(peer3.getId(), 50);
withShuffleOrder(peer2, peer1, peer3);
// Peer2 was dropped from the random pool but had a better score than peer3 so was kept
assertThat(strategy.selectPeersToDisconnect(network, peerPools)).containsExactlyInAnyOrder(peer3);
assertThat(peerPools.getPool(peer2.getId())).isEqualTo(PeerPool.SCORE_BASED);
}
Aggregations