Skip to content

Commit 68a5e3e

Browse files
committed
updated struct and schema to leverage the timestamp type
1 parent 238fd86 commit 68a5e3e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/main/java/com/simplesteph/kafka/GitHubSourceTask.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ private Struct buildRecordKey(Issue issue){
137137
return key;
138138
}
139139

140-
private Struct buildRecordValue(Issue issue){
140+
public Struct buildRecordValue(Issue issue){
141141

142142
// Issue top level fields
143143
Struct valueStruct = new Struct(VALUE_SCHEMA)
144144
.put(URL_FIELD, issue.getUrl())
145145
.put(TITLE_FIELD, issue.getTitle())
146-
.put(CREATED_AT_FIELD, issue.getCreatedAt().toEpochMilli())
147-
.put(UPDATED_AT_FIELD, issue.getUpdatedAt().toEpochMilli())
146+
.put(CREATED_AT_FIELD, Date.from(issue.getCreatedAt()))
147+
.put(UPDATED_AT_FIELD, Date.from(issue.getUpdatedAt()))
148148
.put(NUMBER_FIELD, issue.getNumber())
149149
.put(STATE_FIELD, issue.getState());
150150

src/test/java/com/simplesteph/kafka/model/IssueTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.simplesteph.kafka.model;
22

3+
import com.simplesteph.kafka.GitHubSourceTask;
4+
import org.apache.kafka.connect.data.Struct;
35
import org.json.JSONObject;
46
import org.junit.Test;
57

8+
import java.util.Date;
9+
610
import static org.junit.Assert.assertEquals;
711
import static org.junit.Assert.assertNotNull;
812

@@ -84,4 +88,12 @@ public void canParseJson(){
8488

8589
}
8690

91+
@Test
92+
public void convertsToStruct(){
93+
// issue
94+
Issue issue = Issue.fromJson(issueJson);
95+
Struct struct = new GitHubSourceTask().buildRecordValue(issue);
96+
assert struct.get("created_at").getClass() == Date.class;
97+
}
98+
8799
}

0 commit comments

Comments
 (0)