Skip to content

KAFKA-17278: Add FetchRequest compatibility tests for KafkaRaftClient #17801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions raft/src/test/java/org/apache/kafka/raft/RaftUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,29 @@ public void testSingletonFetchRequestForAllVersion(final FetchRequestTestCase te
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) {
Expand Down Expand Up @@ -437,6 +460,35 @@ public void testSingletonFetchSnapshotRequestForAllVersion(final short version,
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) {
Expand Down
Loading