You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by js...@apache.org on 2025/01/06 15:18:20 UTC
(kafka) branch trunk updated: KAFKA-17278; Add KRaft RPC compatibility tests (#17801)
This is an automated email from the ASF dual-hosted git repository.
jsancio pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new 9818e9db26f KAFKA-17278; Add KRaft RPC compatibility tests (#17801)
9818e9db26f is described below
commit 9818e9db26fa4eb1242f2dcba384702781e50930
Author: kevin-wu24 <66...@users.noreply.github.com>
AuthorDate: Mon Jan 6 09:18:13 2025 -0600
KAFKA-17278; Add KRaft RPC compatibility tests (#17801)
Adds RPC compatibility tests for FETCH and FETCH_SNAPSHOT.
Reviewers: José Armando García Sancio <js...@apache.org>
---
.../java/org/apache/kafka/raft/RaftUtilTest.java | 52 ++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/raft/src/test/java/org/apache/kafka/raft/RaftUtilTest.java b/raft/src/test/java/org/apache/kafka/raft/RaftUtilTest.java
index 681bcaae8de..6bfaf7b7ff3 100644
--- a/raft/src/test/java/org/apache/kafka/raft/RaftUtilTest.java
+++ b/raft/src/test/java/org/apache/kafka/raft/RaftUtilTest.java
@@ -341,6 +341,29 @@ public class RaftUtilTest {
assertEquals(testCase.expectedJson, json.toString());
}
+ // Test that the replicaDirectoryId field introduced in version 17 is ignorable for older versions.
+ // This is done by setting a FetchPartition's replicaDirectoryId explicitly to a non-zero uuid and
+ // checking that the FetchRequestData can still be written to an older version specified by
+ // testCase.version.
+ @ParameterizedTest
+ @MethodSource("singletonFetchRequestTestCases")
+ public void testFetchRequestV17Compatibility(final FetchRequestTestCase testCase) {
+ FetchRequestData fetchRequestData = RaftUtil.singletonFetchRequest(
+ topicPartition,
+ Uuid.ONE_UUID,
+ partition -> partition
+ .setPartitionMaxBytes(10)
+ .setCurrentLeaderEpoch(5)
+ .setFetchOffset(333)
+ .setLastFetchedEpoch(testCase.lastFetchedEpoch)
+ .setPartition(2)
+ .setReplicaDirectoryId(Uuid.ONE_UUID)
+ .setLogStartOffset(0)
+ );
+ JsonNode json = FetchRequestDataJsonConverter.write(fetchRequestData, testCase.version);
+ assertEquals(testCase.expectedJson, json.toString());
+ }
+
@ParameterizedTest
@MethodSource("singletonFetchResponseTestCases")
public void testSingletonFetchResponseForAllVersion(final FetchResponseTestCase testCase) {
@@ -444,6 +467,35 @@ public class RaftUtilTest {
assertEquals(expectedJson, json.toString());
}
+ // Test that the replicaDirectoryId field introduced in version 1 is ignorable for version 0
+ // This is done by setting a FetchPartition's replicaDirectoryId explicitly to a non-zero uuid and
+ // checking that the FetchSnapshotRequestData can still be written to an older version specified by
+ // testCase.version.
+ @ParameterizedTest
+ @MethodSource("fetchSnapshotRequestTestCases")
+ public void testSingletonFetchSnapshotRequestV1Compatibility(
+ short version,
+ Uuid directoryId,
+ String expectedJson
+ ) {
+ int epoch = 1;
+ int maxBytes = 1000;
+ int position = 10;
+
+ FetchSnapshotRequestData fetchSnapshotRequestData = RaftUtil.singletonFetchSnapshotRequest(
+ clusterId,
+ ReplicaKey.of(1, directoryId),
+ topicPartition,
+ epoch,
+ new OffsetAndEpoch(10, epoch),
+ maxBytes,
+ position
+ );
+ fetchSnapshotRequestData.topics().get(0).partitions().get(0).setReplicaDirectoryId(Uuid.ONE_UUID);
+ JsonNode json = FetchSnapshotRequestDataJsonConverter.write(fetchSnapshotRequestData, version);
+ assertEquals(expectedJson, json.toString());
+ }
+
@ParameterizedTest
@MethodSource("fetchSnapshotResponseTestCases")
public void testSingletonFetchSnapshotResponseForAllVersion(final short version, final String expectedJson) {