diff --git a/clients/src/main/java/io/strimzi/common/records/consumer/http/ConsumerRecord.java b/clients/src/main/java/io/strimzi/common/records/consumer/http/ConsumerRecord.java index 407c5e0..28ec401 100644 --- a/clients/src/main/java/io/strimzi/common/records/consumer/http/ConsumerRecord.java +++ b/clients/src/main/java/io/strimzi/common/records/consumer/http/ConsumerRecord.java @@ -12,6 +12,7 @@ public class ConsumerRecord { private Object value; private int partition; private long offset; + private Long timestamp; public void setTopic(String topic) { this.topic = topic; @@ -33,6 +34,10 @@ public void setOffset(long offset) { this.offset = offset; } + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + @Override public boolean equals(Object o) { // self check @@ -49,7 +54,8 @@ public boolean equals(Object o) { ConsumerRecord cr = (ConsumerRecord) o; - return cr.partition == partition && + return Objects.equals(cr.timestamp, timestamp) && + cr.partition == partition && cr.offset == offset && Objects.equals(cr.value, value) && Objects.equals(cr.topic, topic) && @@ -64,10 +70,11 @@ public int hashCode() { @Override public String toString() { return "ConsumerRecord: " + - ", topic = " + this.topic + + "topic = " + this.topic + ", key = " + this.key + ", value = " + this.value + ", partition = " + this.partition + - ", offset = " + this.offset; + ", offset = " + this.offset + + ", timestamp = " + this.timestamp; } } diff --git a/clients/src/test/java/io/strimzi/common/records/consumer/http/ConsumerRecordUtilsTest.java b/clients/src/test/java/io/strimzi/common/records/consumer/http/ConsumerRecordUtilsTest.java index e9eaf75..3f120cf 100644 --- a/clients/src/test/java/io/strimzi/common/records/consumer/http/ConsumerRecordUtilsTest.java +++ b/clients/src/test/java/io/strimzi/common/records/consumer/http/ConsumerRecordUtilsTest.java @@ -14,7 +14,25 @@ public class ConsumerRecordUtilsTest { @Test - void testParseConsumerRecordsFromJson() throws JsonProcessingException { + void testParseConsumerRecordsWithTimestampFromJson() throws JsonProcessingException { + String response = "[{\"topic\":\"random-topic\",\"key\":\"key-0\",\"value\":\"Hello world-0\",\"partition\":0,\"offset\":0,\"timestamp\":\"1722874490\"}]"; + + ConsumerRecord expectedResult = new ConsumerRecord(); + expectedResult.setPartition(0); + expectedResult.setOffset(0); + expectedResult.setTopic("random-topic"); + expectedResult.setKey("key-0"); + expectedResult.setValue("Hello world-0"); + expectedResult.setTimestamp(1722874490L); + + ConsumerRecord[] result = ConsumerRecordUtils.parseConsumerRecordsFromJson(response); + + assertThat(result.length, is(1)); + assertThat(result[0], is(expectedResult)); + } + + @Test + void testParseConsumerRecordsWithoutTimestampFromJson() throws JsonProcessingException { String response = "[{\"topic\":\"random-topic\",\"key\":\"key-0\",\"value\":\"Hello world-0\",\"partition\":0,\"offset\":0}]"; ConsumerRecord expectedResult = new ConsumerRecord();