@Test
  public void completesWhenPeerReturnsPartialResult() {
    // Setup a partially responsive peer
    final RespondingEthPeer.Responder responder =
        RespondingEthPeer.partialResponder(
            blockchain,
            protocolContext.getWorldStateArchive(),
            transactionPool,
            protocolSchedule,
            0.5f);
    final RespondingEthPeer respondingEthPeer =
        EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 32);

    // Execute task and wait for response
    final AtomicReference<T> actualResult = new AtomicReference<>();
    final AtomicReference<EthPeer> actualPeer = new AtomicReference<>();
    final AtomicBoolean done = new AtomicBoolean(false);
    final T requestedData = generateDataToBeRequested();
    final EthTask<AbstractPeerTask.PeerTaskResult<T>> task = createTask(requestedData);
    final CompletableFuture<AbstractPeerTask.PeerTaskResult<T>> future = task.run();
    respondingEthPeer.respondWhile(responder, () -> !future.isDone());
    future.whenComplete(
        (response, error) -> {
          actualResult.set(response.getResult());
          actualPeer.set(response.getPeer());
          done.compareAndSet(false, true);
        });

    assertThat(done).isTrue();
    assertPartialResultMatchesExpectation(requestedData, actualResult.get());
    assertThat(actualPeer.get()).isEqualTo(respondingEthPeer.getEthPeer());
  }
Tests ethTasks that interact with a single peer to retrieve data from the network.

@param <T> The type of data being retrieved.
ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/PeerMessageTaskTest.java