|
|
|
@ -46,6 +46,7 @@ import org.mockito.junit.MockitoJUnitRunner; |
|
|
|
|
@RunWith(MockitoJUnitRunner.class) |
|
|
|
|
public class ValidatorPeersTest { |
|
|
|
|
|
|
|
|
|
public static final String PROTOCOL_NAME = "BFT"; |
|
|
|
|
private final List<Address> validators = newArrayList(); |
|
|
|
|
private final List<PublicKey> publicKeys = newArrayList(); |
|
|
|
|
|
|
|
|
@ -81,7 +82,7 @@ public class ValidatorPeersTest { |
|
|
|
|
// Only add the first Peer's address to the validators.
|
|
|
|
|
validators.add(Util.publicKeyToAddress(publicKeys.get(0))); |
|
|
|
|
|
|
|
|
|
final ValidatorPeers peers = new ValidatorPeers(voteTallyCache); |
|
|
|
|
final ValidatorPeers peers = new ValidatorPeers(voteTallyCache, PROTOCOL_NAME); |
|
|
|
|
for (final PeerConnection peer : peerConnections) { |
|
|
|
|
peers.add(peer); |
|
|
|
|
} |
|
|
|
@ -89,7 +90,7 @@ public class ValidatorPeersTest { |
|
|
|
|
final MessageData messageToSend = new RawMessage(1, Bytes.EMPTY); |
|
|
|
|
peers.send(messageToSend); |
|
|
|
|
|
|
|
|
|
verify(peerConnections.get(0), times(1)).sendForProtocol("IBF", messageToSend); |
|
|
|
|
verify(peerConnections.get(0), times(1)).sendForProtocol(PROTOCOL_NAME, messageToSend); |
|
|
|
|
verify(peerConnections.get(1), never()).sendForProtocol(any(), any()); |
|
|
|
|
verify(peerConnections.get(2), never()).sendForProtocol(any(), any()); |
|
|
|
|
verify(peerConnections.get(3), never()).sendForProtocol(any(), any()); |
|
|
|
@ -101,7 +102,7 @@ public class ValidatorPeersTest { |
|
|
|
|
validators.add(peer0Address); |
|
|
|
|
final PeerConnection duplicatePeer = mockPeerConnection(peer0Address); |
|
|
|
|
|
|
|
|
|
final ValidatorPeers peers = new ValidatorPeers(voteTallyCache); |
|
|
|
|
final ValidatorPeers peers = new ValidatorPeers(voteTallyCache, PROTOCOL_NAME); |
|
|
|
|
for (final PeerConnection peer : peerConnections) { |
|
|
|
|
peers.add(peer); |
|
|
|
|
} |
|
|
|
@ -110,8 +111,8 @@ public class ValidatorPeersTest { |
|
|
|
|
final MessageData messageToSend = new RawMessage(1, Bytes.EMPTY); |
|
|
|
|
peers.send(messageToSend); |
|
|
|
|
|
|
|
|
|
verify(peerConnections.get(0), times(1)).sendForProtocol("IBF", messageToSend); |
|
|
|
|
verify(duplicatePeer, times(1)).sendForProtocol("IBF", messageToSend); |
|
|
|
|
verify(peerConnections.get(0), times(1)).sendForProtocol(PROTOCOL_NAME, messageToSend); |
|
|
|
|
verify(duplicatePeer, times(1)).sendForProtocol(PROTOCOL_NAME, messageToSend); |
|
|
|
|
verify(peerConnections.get(1), never()).sendForProtocol(any(), any()); |
|
|
|
|
verify(peerConnections.get(2), never()).sendForProtocol(any(), any()); |
|
|
|
|
verify(peerConnections.get(3), never()).sendForProtocol(any(), any()); |
|
|
|
@ -123,7 +124,7 @@ public class ValidatorPeersTest { |
|
|
|
|
validators.add(peer0Address); |
|
|
|
|
final PeerConnection duplicatePeer = mockPeerConnection(peer0Address); |
|
|
|
|
|
|
|
|
|
final ValidatorPeers peers = new ValidatorPeers(voteTallyCache); |
|
|
|
|
final ValidatorPeers peers = new ValidatorPeers(voteTallyCache, PROTOCOL_NAME); |
|
|
|
|
for (final PeerConnection peer : peerConnections) { |
|
|
|
|
peers.add(peer); |
|
|
|
|
} |
|
|
|
@ -133,7 +134,7 @@ public class ValidatorPeersTest { |
|
|
|
|
final MessageData messageToSend = new RawMessage(1, Bytes.EMPTY); |
|
|
|
|
peers.send(messageToSend); |
|
|
|
|
|
|
|
|
|
verify(peerConnections.get(0), times(1)).sendForProtocol("IBF", messageToSend); |
|
|
|
|
verify(peerConnections.get(0), times(1)).sendForProtocol(PROTOCOL_NAME, messageToSend); |
|
|
|
|
verify(duplicatePeer, never()).sendForProtocol("IBF", messageToSend); |
|
|
|
|
verify(peerConnections.get(1), never()).sendForProtocol(any(), any()); |
|
|
|
|
verify(peerConnections.get(2), never()).sendForProtocol(any(), any()); |
|
|
|
@ -144,7 +145,7 @@ public class ValidatorPeersTest { |
|
|
|
|
public void doesntSendToValidatorsWhichAreNotDirectlyConnected() throws PeerNotConnected { |
|
|
|
|
validators.add(Util.publicKeyToAddress(publicKeys.get(0))); |
|
|
|
|
|
|
|
|
|
final ValidatorPeers peers = new ValidatorPeers(voteTallyCache); |
|
|
|
|
final ValidatorPeers peers = new ValidatorPeers(voteTallyCache, PROTOCOL_NAME); |
|
|
|
|
|
|
|
|
|
// only add peer connections 1, 2 & 3, none of which should be invoked.
|
|
|
|
|
newArrayList(1, 2, 3).forEach(i -> peers.add(peerConnections.get(i))); |
|
|
|
@ -165,7 +166,7 @@ public class ValidatorPeersTest { |
|
|
|
|
validators.add(validatorAddress); |
|
|
|
|
validators.add(Util.publicKeyToAddress(publicKeys.get(1))); |
|
|
|
|
|
|
|
|
|
final ValidatorPeers peers = new ValidatorPeers(voteTallyCache); |
|
|
|
|
final ValidatorPeers peers = new ValidatorPeers(voteTallyCache, PROTOCOL_NAME); |
|
|
|
|
for (final PeerConnection peer : peerConnections) { |
|
|
|
|
peers.add(peer); |
|
|
|
|
} |
|
|
|
|