-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-10697: Remove ProduceResponse.responses #10332
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
Changes from 3 commits
1bd25d2
f585557
8194adf
a3aacd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,15 +17,19 @@ | |
|
|
||
| package org.apache.kafka.common.requests; | ||
|
|
||
| import org.apache.kafka.common.message.ProduceResponseData; | ||
| import org.apache.kafka.common.TopicPartition; | ||
| import org.apache.kafka.common.protocol.ApiKeys; | ||
| import org.apache.kafka.common.protocol.Errors; | ||
| import org.apache.kafka.common.record.RecordBatch; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.apache.kafka.common.protocol.ApiKeys.PRODUCE; | ||
|
|
@@ -40,42 +44,56 @@ public class ProduceResponseTest { | |
| public void produceResponseV5Test() { | ||
| Map<TopicPartition, ProduceResponse.PartitionResponse> responseData = new HashMap<>(); | ||
| TopicPartition tp0 = new TopicPartition("test", 0); | ||
| responseData.put(tp0, new ProduceResponse.PartitionResponse(Errors.NONE, | ||
| 10000, RecordBatch.NO_TIMESTAMP, 100)); | ||
| responseData.put(tp0, new ProduceResponse.PartitionResponse(Errors.NONE, 10000, RecordBatch.NO_TIMESTAMP, 100)); | ||
|
|
||
| ProduceResponse v5Response = new ProduceResponse(responseData, 10); | ||
| short version = 5; | ||
|
|
||
| ByteBuffer buffer = RequestTestUtils.serializeResponseWithHeader(v5Response, version, 0); | ||
|
|
||
| ResponseHeader.parse(buffer, ApiKeys.PRODUCE.responseHeaderVersion(version)); // throw away. | ||
| ProduceResponse v5FromBytes = (ProduceResponse) AbstractResponse.parseResponse(ApiKeys.PRODUCE, | ||
| buffer, version); | ||
|
|
||
| assertEquals(1, v5FromBytes.responses().size()); | ||
| assertTrue(v5FromBytes.responses().containsKey(tp0)); | ||
| ProduceResponse.PartitionResponse partitionResponse = v5FromBytes.responses().get(tp0); | ||
| assertEquals(100, partitionResponse.logStartOffset); | ||
| assertEquals(10000, partitionResponse.baseOffset); | ||
| assertEquals(10, v5FromBytes.throttleTimeMs()); | ||
| assertEquals(responseData, v5Response.responses()); | ||
| ProduceResponse v5FromBytes = (ProduceResponse) AbstractResponse.parseResponse(ApiKeys.PRODUCE, buffer, version); | ||
|
|
||
| assertEquals(1, v5FromBytes.data().responses().size()); | ||
|
chia7712 marked this conversation as resolved.
Outdated
|
||
| ProduceResponseData.TopicProduceResponse topicProduceResponse = v5FromBytes.data().responses().iterator().next(); | ||
| assertEquals(1, topicProduceResponse.partitionResponses().size()); | ||
| ProduceResponseData.PartitionProduceResponse partitionProduceResponse = topicProduceResponse.partitionResponses().iterator().next(); | ||
| TopicPartition tp = new TopicPartition(topicProduceResponse.name(), partitionProduceResponse.index()); | ||
| assertEquals(tp0, tp); | ||
|
|
||
| assertEquals(100, partitionProduceResponse.logStartOffset()); | ||
| assertEquals(10000, partitionProduceResponse.baseOffset()); | ||
| assertEquals(RecordBatch.NO_TIMESTAMP, partitionProduceResponse.logAppendTimeMs()); | ||
| assertEquals(Errors.NONE, Errors.forCode(partitionProduceResponse.errorCode())); | ||
| assertNull(partitionProduceResponse.errorMessage()); | ||
| assertTrue(partitionProduceResponse.recordErrors().isEmpty()); | ||
| } | ||
|
|
||
| @SuppressWarnings("deprecation") | ||
| @Test | ||
| public void produceResponseVersionTest() { | ||
| Map<TopicPartition, ProduceResponse.PartitionResponse> responseData = new HashMap<>(); | ||
| responseData.put(new TopicPartition("test", 0), new ProduceResponse.PartitionResponse(Errors.NONE, | ||
| 10000, RecordBatch.NO_TIMESTAMP, 100)); | ||
| responseData.put(new TopicPartition("test", 0), new ProduceResponse.PartitionResponse(Errors.NONE, 10000, RecordBatch.NO_TIMESTAMP, 100)); | ||
| ProduceResponse v0Response = new ProduceResponse(responseData); | ||
| ProduceResponse v1Response = new ProduceResponse(responseData, 10); | ||
| ProduceResponse v2Response = new ProduceResponse(responseData, 10); | ||
| assertEquals(0, v0Response.throttleTimeMs(), "Throttle time must be zero"); | ||
| assertEquals(10, v1Response.throttleTimeMs(), "Throttle time must be 10"); | ||
| assertEquals(10, v2Response.throttleTimeMs(), "Throttle time must be 10"); | ||
| assertEquals(responseData, v0Response.responses(), "Response data does not match"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add similar checks?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| assertEquals(responseData, v1Response.responses(), "Response data does not match"); | ||
| assertEquals(responseData, v2Response.responses(), "Response data does not match"); | ||
|
|
||
| List<ProduceResponse> arrResponse = Arrays.asList(v0Response, v1Response, v2Response); | ||
| for(ProduceResponse produceResponse:arrResponse) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. code style:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| assertEquals(1, produceResponse.data().responses().size()); | ||
| ProduceResponseData.TopicProduceResponse topicProduceResponse = produceResponse.data().responses().iterator().next(); | ||
| assertEquals(1, topicProduceResponse.partitionResponses().size()); | ||
| ProduceResponseData.PartitionProduceResponse partitionProduceResponse = topicProduceResponse.partitionResponses().iterator().next(); | ||
| assertEquals(100, partitionProduceResponse.logStartOffset()); | ||
| assertEquals(10000, partitionProduceResponse.baseOffset()); | ||
| assertEquals(RecordBatch.NO_TIMESTAMP, partitionProduceResponse.logAppendTimeMs()); | ||
| assertEquals(Errors.NONE, Errors.forCode(partitionProduceResponse.errorCode())); | ||
| assertNull(partitionProduceResponse.errorMessage()); | ||
| assertTrue(partitionProduceResponse.recordErrors().isEmpty()); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("deprecation") | ||
|
|
@@ -91,15 +109,18 @@ public void produceResponseRecordErrorsTest() { | |
|
|
||
| for (short version : PRODUCE.allVersions()) { | ||
| ProduceResponse response = new ProduceResponse(responseData); | ||
| ProduceResponse.PartitionResponse deserialized = ProduceResponse.parse(response.serialize(version), version).responses().get(tp); | ||
|
|
||
| ProduceResponse produceResponse = ProduceResponse.parse(response.serialize(version), version); | ||
| ProduceResponseData.TopicProduceResponse topicProduceResponse = produceResponse.data().responses().iterator().next(); | ||
| ProduceResponseData.PartitionProduceResponse deserialized = topicProduceResponse.partitionResponses().iterator().next(); | ||
| if (version >= 8) { | ||
| assertEquals(1, deserialized.recordErrors.size()); | ||
| assertEquals(3, deserialized.recordErrors.get(0).batchIndex); | ||
| assertEquals("Record error", deserialized.recordErrors.get(0).message); | ||
| assertEquals("Produce failed", deserialized.errorMessage); | ||
| assertEquals(1, deserialized.recordErrors().size()); | ||
| assertEquals(3, deserialized.recordErrors().get(0).batchIndex()); | ||
| assertEquals("Record error", deserialized.recordErrors().get(0).batchIndexErrorMessage()); | ||
| assertEquals("Produce failed", deserialized.errorMessage()); | ||
| } else { | ||
| assertEquals(0, deserialized.recordErrors.size()); | ||
| assertNull(deserialized.errorMessage); | ||
| assertEquals(0, deserialized.recordErrors().size()); | ||
| assertNull(deserialized.errorMessage()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.