7311: Rename parseResponse to processResponse

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
pull/7638/head
Matilda Clerke 1 month ago
parent 095e31d876
commit c2205c4768
  1. 4
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTask.java
  2. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java
  3. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java
  4. 12
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java
  5. 7
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java

@ -41,13 +41,13 @@ public interface PeerTask<T> {
MessageData getRequestMessage(); MessageData getRequestMessage();
/** /**
* Parses the MessageData response from the EthPeer * Parses and processes the MessageData response from the EthPeer
* *
* @param messageData the response MessageData to be parsed * @param messageData the response MessageData to be parsed
* @return a T built from the response MessageData * @return a T built from the response MessageData
* @throws InvalidPeerTaskResponseException if the response messageData is invalid * @throws InvalidPeerTaskResponseException if the response messageData is invalid
*/ */
T parseResponse(MessageData messageData) throws InvalidPeerTaskResponseException; T processResponse(MessageData messageData) throws InvalidPeerTaskResponseException;
/** /**
* Gets the number of times this task may be attempted against other peers * Gets the number of times this task may be attempted against other peers

@ -133,7 +133,7 @@ public class PeerTaskExecutor {
MessageData responseMessageData = MessageData responseMessageData =
requestSender.sendRequest(peerTask.getSubProtocol(), requestMessageData, peer); requestSender.sendRequest(peerTask.getSubProtocol(), requestMessageData, peer);
result = peerTask.parseResponse(responseMessageData); result = peerTask.processResponse(responseMessageData);
} finally { } finally {
inflightRequestCountForThisTaskClass.decrementAndGet(); inflightRequestCountForThisTaskClass.decrementAndGet();
} }

@ -83,7 +83,7 @@ public class GetReceiptsFromPeerTask
} }
@Override @Override
public Map<BlockHeader, List<TransactionReceipt>> parseResponse(final MessageData messageData) public Map<BlockHeader, List<TransactionReceipt>> processResponse(final MessageData messageData)
throws InvalidPeerTaskResponseException { throws InvalidPeerTaskResponseException {
if (messageData == null) { if (messageData == null) {
throw new InvalidPeerTaskResponseException(); throw new InvalidPeerTaskResponseException();

@ -72,7 +72,7 @@ public class PeerTaskExecutorTest {
Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(subprotocol.getName()).thenReturn("subprotocol");
Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer))
.thenReturn(responseMessageData); .thenReturn(responseMessageData);
Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject);
Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true);
PeerTaskExecutorResult<Object> result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); PeerTaskExecutorResult<Object> result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer);
@ -101,7 +101,7 @@ public class PeerTaskExecutorTest {
Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(subprotocol.getName()).thenReturn("subprotocol");
Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer))
.thenReturn(responseMessageData); .thenReturn(responseMessageData);
Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject);
Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(false); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(false);
PeerTaskExecutorResult<Object> result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); PeerTaskExecutorResult<Object> result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer);
@ -130,7 +130,7 @@ public class PeerTaskExecutorTest {
.thenThrow(new TimeoutException()) .thenThrow(new TimeoutException())
.thenReturn(responseMessageData); .thenReturn(responseMessageData);
Mockito.when(requestMessageData.getCode()).thenReturn(requestMessageDataCode); Mockito.when(requestMessageData.getCode()).thenReturn(requestMessageDataCode);
Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject);
Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true);
PeerTaskExecutorResult<Object> result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); PeerTaskExecutorResult<Object> result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer);
@ -204,7 +204,7 @@ public class PeerTaskExecutorTest {
Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(subprotocol.getName()).thenReturn("subprotocol");
Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer))
.thenReturn(responseMessageData); .thenReturn(responseMessageData);
Mockito.when(peerTask.parseResponse(responseMessageData)) Mockito.when(peerTask.processResponse(responseMessageData))
.thenThrow(new InvalidPeerTaskResponseException()); .thenThrow(new InvalidPeerTaskResponseException());
PeerTaskExecutorResult<Object> result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); PeerTaskExecutorResult<Object> result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer);
@ -236,7 +236,7 @@ public class PeerTaskExecutorTest {
Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(subprotocol.getName()).thenReturn("subprotocol");
Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer))
.thenReturn(responseMessageData); .thenReturn(responseMessageData);
Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject);
Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true);
PeerTaskExecutorResult<Object> result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); PeerTaskExecutorResult<Object> result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer);
@ -274,7 +274,7 @@ public class PeerTaskExecutorTest {
Mockito.when(requestMessageData.getCode()).thenReturn(requestMessageDataCode); Mockito.when(requestMessageData.getCode()).thenReturn(requestMessageDataCode);
Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, peer2)) Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, peer2))
.thenReturn(responseMessageData); .thenReturn(responseMessageData);
Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject);
Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true);
PeerTaskExecutorResult<Object> result = peerTaskExecutor.execute(peerTask); PeerTaskExecutorResult<Object> result = peerTaskExecutor.execute(peerTask);

@ -77,7 +77,8 @@ public class GetReceiptsFromPeerTaskTest {
public void testParseResponseWithNullResponseMessage() { public void testParseResponseWithNullResponseMessage() {
GetReceiptsFromPeerTask task = GetReceiptsFromPeerTask task =
new GetReceiptsFromPeerTask(Collections.emptyList(), null, () -> null); new GetReceiptsFromPeerTask(Collections.emptyList(), null, () -> null);
Assertions.assertThrows(InvalidPeerTaskResponseException.class, () -> task.parseResponse(null)); Assertions.assertThrows(
InvalidPeerTaskResponseException.class, () -> task.processResponse(null));
} }
@Test @Test
@ -95,7 +96,7 @@ public class GetReceiptsFromPeerTaskTest {
new TransactionReceipt(1, 101112, Collections.emptyList(), Optional.empty())))); new TransactionReceipt(1, 101112, Collections.emptyList(), Optional.empty()))));
Assertions.assertThrows( Assertions.assertThrows(
InvalidPeerTaskResponseException.class, () -> task.parseResponse(receiptsMessage)); InvalidPeerTaskResponseException.class, () -> task.processResponse(receiptsMessage));
} }
@Test @Test
@ -127,7 +128,7 @@ public class GetReceiptsFromPeerTaskTest {
Mockito.when(bodyValidator.receiptsRoot(List.of(receiptForBlock3))) Mockito.when(bodyValidator.receiptsRoot(List.of(receiptForBlock3)))
.thenReturn(Hash.fromHexString(StringUtils.repeat("00", 31) + "32")); .thenReturn(Hash.fromHexString(StringUtils.repeat("00", 31) + "32"));
Map<BlockHeader, List<TransactionReceipt>> resultMap = task.parseResponse(receiptsMessage); Map<BlockHeader, List<TransactionReceipt>> resultMap = task.processResponse(receiptsMessage);
Assertions.assertEquals(3, resultMap.size()); Assertions.assertEquals(3, resultMap.size());
Assertions.assertEquals(List.of(receiptForBlock1), resultMap.get(blockHeader1)); Assertions.assertEquals(List.of(receiptForBlock1), resultMap.get(blockHeader1));

Loading…
Cancel
Save