### Question:
AbstractPeerBlockValidator implements PeerValidator { @Override public CompletableFuture<Boolean> validatePeer( final EthContext ethContext, final EthPeer ethPeer) { final AbstractPeerTask<List<BlockHeader>> getHeaderTask = GetHeadersFromPeerByNumberTask.forSingleNumber( protocolSchedule, ethContext, blockNumber, metricsSystem) .setTimeout(Duration.ofSeconds(20)) .assignPeer(ethPeer); return getHeaderTask .run() .handle( (res, err) -> { if (err != null) { LOG.debug( "Peer {} is invalid because required block block ({}) is unavailable: {}", ethPeer, blockNumber, err.toString()); return false; } final List<BlockHeader> headers = res.getResult(); if (headers.size() == 0) { LOG.debug( "Peer {} is invalid because required block ({}) is unavailable.", ethPeer, blockNumber); return false; } final BlockHeader header = headers.get(0); return validateBlockHeader(ethPeer, header); }); } AbstractPeerBlockValidator(
      final ProtocolSchedule protocolSchedule,
      final MetricsSystem metricsSystem,
      final long blockNumber,
      final long chainHeightEstimationBuffer); protected  AbstractPeerBlockValidator(
      final ProtocolSchedule protocolSchedule,
      final MetricsSystem metricsSystem,
      final long blockNumber); @Override CompletableFuture<Boolean> validatePeer(
      final EthContext ethContext, final EthPeer ethPeer); @Override boolean canBeValidated(final EthPeer ethPeer); @Override Duration nextValidationCheckTimeout(final EthPeer ethPeer);  }### Answer:
@Test public void validatePeer_unresponsivePeer() { final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(DeterministicEthScheduler.TimeoutPolicy.ALWAYS_TIMEOUT); final long blockNumber = 500; final PeerValidator validator = createValidator(blockNumber, 0); final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, blockNumber); final CompletableFuture<Boolean> result = validator.validatePeer(ethProtocolManager.ethContext(), peer.getEthPeer()); assertThat(result).isDone(); assertThat(result).isCompletedWithValue(false); }
@Test public void validatePeer_requestBlockFromPeerBeingTested() { final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final BlockDataGenerator gen = new BlockDataGenerator(1); final long blockNumber = 500; final Block block = gen.block(BlockOptions.create().setBlockNumber(blockNumber)); final PeerValidator validator = createValidator(blockNumber, 0); final int peerCount = 1000; final List<RespondingEthPeer> otherPeers = Stream.generate( () -> EthProtocolManagerTestUtil.createPeer(ethProtocolManager, blockNumber)) .limit(peerCount) .collect(Collectors.toList()); final RespondingEthPeer targetPeer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, blockNumber); final CompletableFuture<Boolean> result = validator.validatePeer(ethProtocolManager.ethContext(), targetPeer.getEthPeer()); assertThat(result).isNotDone(); for (final RespondingEthPeer otherPeer : otherPeers) { final AtomicBoolean blockRequestedForOtherPeer = respondToBlockRequest(otherPeer, block); assertThat(blockRequestedForOtherPeer).isFalse(); } final AtomicBoolean blockRequested = respondToBlockRequest(targetPeer, block); assertThat(blockRequested).isTrue(); }