From 60857e5451487343759cdd85c3d4f99f1ac7d30a Mon Sep 17 00:00:00 2001 From: Xiaowei Zhu <33129495+zhu-xiaowei@users.noreply.github.com> Date: Wed, 6 Mar 2024 20:25:02 +0800 Subject: [PATCH] feat: support calibrate local timestamp (#73) --- .../clickstream/client/network/NetRequest.java | 1 + .../solution/clickstream/EventRecorderTest.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/clickstream/src/main/java/software/aws/solution/clickstream/client/network/NetRequest.java b/clickstream/src/main/java/software/aws/solution/clickstream/client/network/NetRequest.java index 1b48a8c..bf62ab0 100644 --- a/clickstream/src/main/java/software/aws/solution/clickstream/client/network/NetRequest.java +++ b/clickstream/src/main/java/software/aws/solution/clickstream/client/network/NetRequest.java @@ -110,6 +110,7 @@ private static Response request(@NonNull String eventJson, @NonNull ClickstreamC .addQueryParameter("appId", appId) .addQueryParameter("hashCode", StringUtil.getHashCode(curStr)) .addQueryParameter("event_bundle_sequence_id", String.valueOf(bundleSequenceId)) + .addQueryParameter("upload_timestamp", String.valueOf(System.currentTimeMillis())) .addQueryParameter("compression", compression) .build(); Request.Builder builder = request.newBuilder().url(url).post(body); diff --git a/clickstream/src/test/java/software/aws/solution/clickstream/EventRecorderTest.java b/clickstream/src/test/java/software/aws/solution/clickstream/EventRecorderTest.java index 7e7d585..fb282c3 100644 --- a/clickstream/src/test/java/software/aws/solution/clickstream/EventRecorderTest.java +++ b/clickstream/src/test/java/software/aws/solution/clickstream/EventRecorderTest.java @@ -55,6 +55,7 @@ import static com.github.dreamhead.moco.Moco.and; import static com.github.dreamhead.moco.Moco.by; import static com.github.dreamhead.moco.Moco.eq; +import static com.github.dreamhead.moco.Moco.exist; import static com.github.dreamhead.moco.Moco.httpServer; import static com.github.dreamhead.moco.Moco.query; import static com.github.dreamhead.moco.Moco.status; @@ -76,6 +77,7 @@ public class EventRecorderTest { private static final String COLLECT_SUCCESS = "/collect/success"; private static final String COLLECT_FAIL = "/collect/fail"; private static final String COLLECT_FOR_VERIFY_HASH_CODE = "/collect/hashcode"; + private static final String COLLECT_FOR_VERIFY_UPLOAD_TIMESTAMP = "/collect/timestamp"; private static Runner runner; private static String jsonString; private static HttpServer server; @@ -553,6 +555,21 @@ public void testRecordEventRequestWithHashCode() throws Exception { assertTrue(requestResult); } + /** + * test record event with request parameter upload timestamp. + * + * @throws Exception exception. + */ + @Test + public void testRecordEventRequestUploadTimestamp() throws Exception { + setRequestPath(COLLECT_FOR_VERIFY_UPLOAD_TIMESTAMP); + server.request( + and(by(uri(COLLECT_FOR_VERIFY_UPLOAD_TIMESTAMP)), exist(query("upload_timestamp")))) + .response(status(200), text("success")); + boolean requestResult = NetRequest.uploadEvents("[]", clickstreamContext.getClickstreamConfiguration(), 1); + assertTrue(requestResult); + } + /** * common method to set request path. *