Skip to content
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

Handle timestamp value in response from Bridge #107

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
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
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