Skip to content

Commit

Permalink
Handle timestamp value in response from Bridge (#107)
Browse files Browse the repository at this point in the history
* Handle timestamp value in response from Bridge

Signed-off-by: Lukas Kral <[email protected]>

* fix the ConsumerRecord toString() method

Signed-off-by: Lukas Kral <[email protected]>

---------

Signed-off-by: Lukas Kral <[email protected]>
  • Loading branch information
im-konge authored Aug 6, 2024
1 parent 07db3e7 commit d045f13
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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) &&
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d045f13

Please sign in to comment.