Skip to content

Commit 60857e5

Browse files
authored
feat: support calibrate local timestamp (#73)
1 parent 5082af4 commit 60857e5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

clickstream/src/main/java/software/aws/solution/clickstream/client/network/NetRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private static Response request(@NonNull String eventJson, @NonNull ClickstreamC
110110
.addQueryParameter("appId", appId)
111111
.addQueryParameter("hashCode", StringUtil.getHashCode(curStr))
112112
.addQueryParameter("event_bundle_sequence_id", String.valueOf(bundleSequenceId))
113+
.addQueryParameter("upload_timestamp", String.valueOf(System.currentTimeMillis()))
113114
.addQueryParameter("compression", compression)
114115
.build();
115116
Request.Builder builder = request.newBuilder().url(url).post(body);

clickstream/src/test/java/software/aws/solution/clickstream/EventRecorderTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import static com.github.dreamhead.moco.Moco.and;
5656
import static com.github.dreamhead.moco.Moco.by;
5757
import static com.github.dreamhead.moco.Moco.eq;
58+
import static com.github.dreamhead.moco.Moco.exist;
5859
import static com.github.dreamhead.moco.Moco.httpServer;
5960
import static com.github.dreamhead.moco.Moco.query;
6061
import static com.github.dreamhead.moco.Moco.status;
@@ -76,6 +77,7 @@ public class EventRecorderTest {
7677
private static final String COLLECT_SUCCESS = "/collect/success";
7778
private static final String COLLECT_FAIL = "/collect/fail";
7879
private static final String COLLECT_FOR_VERIFY_HASH_CODE = "/collect/hashcode";
80+
private static final String COLLECT_FOR_VERIFY_UPLOAD_TIMESTAMP = "/collect/timestamp";
7981
private static Runner runner;
8082
private static String jsonString;
8183
private static HttpServer server;
@@ -553,6 +555,21 @@ public void testRecordEventRequestWithHashCode() throws Exception {
553555
assertTrue(requestResult);
554556
}
555557

558+
/**
559+
* test record event with request parameter upload timestamp.
560+
*
561+
* @throws Exception exception.
562+
*/
563+
@Test
564+
public void testRecordEventRequestUploadTimestamp() throws Exception {
565+
setRequestPath(COLLECT_FOR_VERIFY_UPLOAD_TIMESTAMP);
566+
server.request(
567+
and(by(uri(COLLECT_FOR_VERIFY_UPLOAD_TIMESTAMP)), exist(query("upload_timestamp"))))
568+
.response(status(200), text("success"));
569+
boolean requestResult = NetRequest.uploadEvents("[]", clickstreamContext.getClickstreamConfiguration(), 1);
570+
assertTrue(requestResult);
571+
}
572+
556573
/**
557574
* common method to set request path.
558575
*

0 commit comments

Comments
 (0)