kevin-wu24 commented on code in PR #23136:
URL: https://github.com/apache/kafka/pull/23136#discussion_r3766888308


##########
raft/src/testFixtures/java/org/apache/kafka/raft/RaftClientTestContext.java:
##########
@@ -1363,6 +1371,60 @@ public void 
advanceLocalLeaderHighWatermarkToLogEndOffset() throws InterruptedEx
         pollUntil(() -> 
OptionalLong.of(localLogEndOffset).equals(client.highWatermark()));
     }
 
+    @Override
+    RaftRequest.Inbound inboundRequest(ApiMessage request, short version) {
+        return super.inboundRequest(roundTripApiMessage(request, version), 
version);
+    }
+
+    @Override
+    void deliverResponse(int correlationId, Node source, ApiMessage response) {
+        ApiMessage versionedResponse = roundTripApiMessage(response, 
raftResponseVersion(response));
+        super.deliverResponse(correlationId, source, versionedResponse);
+    }
+
+    // Round-trips a message through serialization to mimic the network, 
exercising the client's
+    // request/response encoding on every delivery.
+    private ApiMessage roundTripApiMessage(ApiMessage message, short version) {
+        ObjectSerializationCache cache =  new ObjectSerializationCache();
+        ByteArrayOutputStream  buffer = new 
ByteArrayOutputStream(message.size(cache, version));
+
+        // Encode the message to a byte array with the given version
+        DataOutputStreamWritable writer = new DataOutputStreamWritable(new 
DataOutputStream(buffer));
+        message.write(writer, cache, version);
+
+        // Decode the message from the byte array
+        ByteBufferAccessor reader = new 
ByteBufferAccessor(ByteBuffer.wrap(buffer.toByteArray()));
+        message.read(reader, version);
+
+        return message;
+    }
+
+    private short raftResponseVersion(ApiMessage response) {

Review Comment:
   This is still something we would need in `SharedRaftClientContext`. We could 
write benchmarks where the local node handles a response, and we need to 
deliver a versioned response based on the raft protocol, similar to delivering 
a request to the local node and using `raftRequestVersion`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to