From 4f562ccafbe7ffb1edc41f21e4027554f8251287 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Fri, 16 Feb 2024 12:40:51 +0000 Subject: [PATCH 01/18] [Java] Disable three styling rules (#242) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update ruleset.xml * Update ruleset.xml * Update ruleset.xml --------- Co-authored-by: Artūrs Kadiķis --- ruleset.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ruleset.xml b/ruleset.xml index cf461ba6b..b3030850e 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -93,7 +93,9 @@ + @@ -284,6 +286,7 @@ + @@ -319,7 +323,9 @@ + @@ -449,4 +455,4 @@ - \ No newline at end of file + From 2111ce3d9e69ff92081a8b93efbe98c99fdea999 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Mon, 19 Feb 2024 08:41:18 +0000 Subject: [PATCH 02/18] [Java] Add underscore to the numerics #Codacy (#243) * feat: add underscore to numerics * revert: BackendModeTests.java * fix: tests --- .../java/ly/count/java/demo/BackendModeExample.java | 4 ++-- .../count/java/demo/BackendModePerformanceTests.java | 4 ++-- .../main/java/ly/count/sdk/java/internal/Device.java | 6 +++--- .../java/ly/count/sdk/java/internal/TimeUtils.java | 6 +++--- .../ly/count/sdk/java/internal/BackendModeTests.java | 2 +- .../ly/count/sdk/java/internal/EventImplTests.java | 4 ++-- .../ly/count/sdk/java/internal/ModuleViewsTests.java | 10 +++++----- .../ly/count/sdk/java/internal/SessionImplTests.java | 10 +++++----- .../count/sdk/java/internal/TimeGeneratorTests.java | 12 ++++++------ .../ly/count/sdk/java/internal/TimeUtilsTests.java | 6 +++--- .../ly/count/sdk/java/internal/UserEditorTests.java | 2 +- 11 files changed, 33 insertions(+), 33 deletions(-) diff --git a/app-java/src/main/java/ly/count/java/demo/BackendModeExample.java b/app-java/src/main/java/ly/count/java/demo/BackendModeExample.java index 83aaf4d92..626f1711e 100644 --- a/app-java/src/main/java/ly/count/java/demo/BackendModeExample.java +++ b/app-java/src/main/java/ly/count/java/demo/BackendModeExample.java @@ -37,7 +37,7 @@ private static void recordView() { segmentation.put("segment", "Windows"); segmentation.put("start", "1"); - Countly.instance().backendM().recordView(DEVICE_ID, "SampleView", segmentation, 1646640780130L); + Countly.instance().backendM().recordView(DEVICE_ID, "SampleView", segmentation, 1_646_640_780_130L); } private static void recordEvent() { @@ -298,7 +298,7 @@ public static void main(String[] args) throws Exception { Config config = new Config(COUNTLY_SERVER_URL, COUNTLY_APP_KEY) .setLoggingLevel(Config.LoggingLevel.DEBUG) .enableBackendMode() - .setRequestQueueMaxSize(10000) + .setRequestQueueMaxSize(10_000) .setDeviceIdStrategy(Config.DeviceIdStrategy.UUID) .setRequiresConsent(false) .setEventQueueSizeToSend(1000); diff --git a/app-java/src/main/java/ly/count/java/demo/BackendModePerformanceTests.java b/app-java/src/main/java/ly/count/java/demo/BackendModePerformanceTests.java index 5be824dce..e8f692dda 100644 --- a/app-java/src/main/java/ly/count/java/demo/BackendModePerformanceTests.java +++ b/app-java/src/main/java/ly/count/java/demo/BackendModePerformanceTests.java @@ -40,7 +40,7 @@ private static void initSDK(int eventQueueSize, int requestQueueSize) { static void performLargeRequestQueueSizeTest() { DemoUtils.println("===== Test Started: 'Large request queue size' ====="); - int requestQSize = 1000000; + int requestQSize = 1_000_000; DemoUtils.printf("Before SDK Initialization: Total Memory = %dMb, Available RAM = %dMb %n", Device.dev.getRAMTotal(), Device.dev.getRAMAvailable()); initSDK(1, requestQSize); DemoUtils.printf("After SDK Initialization: Total Memory = %d Mb, Available RAM= %d Mb %n", Device.dev.getRAMTotal(), Device.dev.getRAMAvailable()); @@ -121,7 +121,7 @@ static void performLargeEventQueueTest() { DemoUtils.printf("After SDK Initialization: Total Memory = %d Mb, Available RAM= %d Mb %n", Device.dev.getRAMTotal(), Device.dev.getRAMAvailable()); int noOfDevices = 10; for (int d = 0; d <= noOfDevices; ++d) { - DemoUtils.printf("Adding %d events into event Queue against deviceID = %s%n", 1_000_00, "device-id-" + d); + DemoUtils.printf("Adding %d events into event Queue against deviceID = %s%n", 100_000, "device-id-" + d); for (int i = 1; i <= noOfEvents; ++i) { Map segment = new ConcurrentHashMap<>(); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java index 7746a72a5..baf5279b7 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java @@ -44,8 +44,8 @@ public void setLog(Log L) { /** * One second in nanoseconds */ - protected static final Double NS_IN_SECOND = 1000000000.0d; - protected static final Double NS_IN_MS = 1000000.0d; + protected static final Double NS_IN_SECOND = 1_000_000_000.0d; + protected static final Double NS_IN_MS = 1_000_000.0d; protected static final Double MS_IN_SECOND = 1000d; protected static final Long BYTES_IN_MB = 1024L * 1024; @@ -74,7 +74,7 @@ public String getOSVersion() { * @return timezone offset in seconds */ public int getTimezoneOffset() { - return TimeZone.getDefault().getOffset(new Date().getTime()) / 60000; + return TimeZone.getDefault().getOffset(new Date().getTime()) / 60_000; } /** diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/TimeUtils.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/TimeUtils.java index 842fd7aec..d5d460df5 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/TimeUtils.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/TimeUtils.java @@ -4,8 +4,8 @@ public class TimeUtils { - protected static final Double NS_IN_SECOND = 1000000000.0d; - protected static final Double NS_IN_MS = 1000000.0d; + protected static final Double NS_IN_SECOND = 1_000_000_000.0d; + protected static final Double NS_IN_MS = 1_000_000.0d; protected static final long MS_IN_SECOND = 1000; private static final UniqueTimeGenerator uniqueTimer = new UniqueTimeGenerator(); @@ -39,7 +39,7 @@ protected static Instant getCurrentInstant(long timestamp) { return new Instant(timestamp, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.DAY_OF_WEEK) - 1, // Calendar days are 1-based, Countly days are 0-based - calendar.get(Calendar.ZONE_OFFSET) / 60000); //convert it to seconds + calendar.get(Calendar.ZONE_OFFSET) / 60_000); //convert it to seconds } /** diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/BackendModeTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/BackendModeTests.java index a1f2fa764..678a5682b 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/BackendModeTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/BackendModeTests.java @@ -954,4 +954,4 @@ private int getHourFromTimeStamp(long timeStamp) { return calendar.get(Calendar.HOUR_OF_DAY); } -} \ No newline at end of file +} diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/EventImplTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/EventImplTests.java index c8225d820..70df02df5 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/EventImplTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/EventImplTests.java @@ -211,7 +211,7 @@ public void validateFromJson_toJson_segmentation() { segmentation.put("quantity", 3); segmentation.put("name", "test"); segmentation.put("null", null); - segmentation.put("checksum", 56476587L); + segmentation.put("checksum", 56_476_587L); segmentation.put("divisor", 0.2f); event.segmentation = segmentation; @@ -220,7 +220,7 @@ public void validateFromJson_toJson_segmentation() { expectedSegmentation.put("price", BigDecimal.valueOf(9.43)); expectedSegmentation.put("quantity", 3); expectedSegmentation.put("name", "test"); - expectedSegmentation.put("checksum", 56476587); + expectedSegmentation.put("checksum", 56_476_587); expectedSegmentation.put("divisor", BigDecimal.valueOf(0.2)); JSONObject json = new JSONObject(); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleViewsTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleViewsTests.java index 3575f17ef..2c25479da 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleViewsTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleViewsTests.java @@ -260,7 +260,7 @@ public void mixedTestFlow1() throws InterruptedException { Countly.instance().init(TestUtils.getConfigViews()); TestUtils.validateEQSize(0); - Map customSegmentationA = TestUtils.map("money", 238746798234739L, "start", "1", "visit", "1", "name", TestUtils.keysValues[0], "segment", TestUtils.keysValues[1]); + Map customSegmentationA = TestUtils.map("money", 238_746_798_234_739L, "start", "1", "visit", "1", "name", TestUtils.keysValues[0], "segment", TestUtils.keysValues[1]); Map customSegmentationB = TestUtils.map("gone_to", "Wall Sina", "map", TestUtils.map("titan", true, "level", 65)); Countly.instance().views().startView("A", customSegmentationA); @@ -270,7 +270,7 @@ public void mixedTestFlow1() throws InterruptedException { TestUtils.validateEQSize(4); - validateView("A", 0.0, 0, 4, true, true, TestUtils.map("money", 238746798234739L), "idv1", ""); // starting + validateView("A", 0.0, 0, 4, true, true, TestUtils.map("money", 238_746_798_234_739L), "idv1", ""); // starting validateView("AutoStopped", 0.0, 1, 4, false, true, TestUtils.map("gone_to", "Wall Sina"), "idv2", "idv1"); // starting validateView("AutoStopped", 1.0, 2, 4, false, false, null, "idv2", "idv1"); // closing validateView("B", 0.0, 3, 4, false, true, null, "idv3", "idv2"); // starting @@ -376,7 +376,7 @@ public void validateSegmentation2() { validateView("A", 0.0, 0, 2, true, true, null, "idv1", ""); validateView("B", 0.0, 1, 2, false, true, null, "idv2", "idv1"); - Map allSegmentation = TestUtils.map("Copyright", "Countly", "AppExit", true, "DestroyToken", false, "ExitedAt", 1702975890000L); + Map allSegmentation = TestUtils.map("Copyright", "Countly", "AppExit", true, "DestroyToken", false, "ExitedAt", 1_702_975_890_000L); Countly.instance().views().stopAllViews(allSegmentation); validateView("A", 0.0, 2, 4, false, false, allSegmentation, "idv1", "idv1"); @@ -401,9 +401,9 @@ public void validateSegmentation_internalKeys() { Map internalKeysSegmentation = TestUtils.map("start", "YES", "name", TestUtils.keysValues[0], "visit", "YES", "segment", TestUtils.keysValues[1]); Countly.instance().views().startView("A", TestUtils.map(internalKeysSegmentation, "ultimate", "YES")); - Countly.instance().views().stopViewWithName("A", TestUtils.map(internalKeysSegmentation, "end", "Unfortunately", "time", 1234567890L)); + Countly.instance().views().stopViewWithName("A", TestUtils.map(internalKeysSegmentation, "end", "Unfortunately", "time", 1_234_567_890L)); validateView("A", 0.0, 0, 2, true, true, TestUtils.map("ultimate", "YES"), "idv1", ""); - validateView("A", 0.0, 1, 2, false, false, TestUtils.map("end", "Unfortunately", "time", 1234567890), "idv1", ""); + validateView("A", 0.0, 1, 2, false, false, TestUtils.map("end", "Unfortunately", "time", 1_234_567_890), "idv1", ""); } /** diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java index 2f0655eff..859d50c34 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java @@ -41,7 +41,7 @@ public void stop() { @Test public void constructor() { Countly.instance().init(TestUtils.getConfigSessions()); - assertEquals(new Long(12345L), createSessionImpl(12345L).getId()); + assertEquals(new Long(12_345L), createSessionImpl(12_345L).getId()); } /** @@ -488,7 +488,7 @@ private void addCrashReport_base(Config config, int rqSize) { @Test public void hashCode_id() { Countly.instance().init(TestUtils.getConfigSessions()); - assertEquals(new Long(12345L).hashCode(), createSessionImpl(12345L).hashCode()); + assertEquals(new Long(12_345L).hashCode(), createSessionImpl(12_345L).hashCode()); } /** @@ -521,7 +521,7 @@ public void equals_test() { @Test public void equals_notInstanceOf() { Countly.instance().init(TestUtils.getConfigSessions()); - Assert.assertFalse(createSessionImpl(12345L).equals(new Object())); + Assert.assertFalse(createSessionImpl(12_345L).equals(new Object())); } /** @@ -632,8 +632,8 @@ public void view_stopStartedAndNext() { private void validateNotEquals(int idOffset, BiFunction> setter) { Countly.instance().init(TestUtils.getConfigSessions()); long ts = TimeUtils.timestampMs(); - SessionImpl session = createSessionImpl(12345L); - SessionImpl session2 = createSessionImpl(12345L + idOffset); + SessionImpl session = createSessionImpl(12_345L); + SessionImpl session2 = createSessionImpl(12_345L + idOffset); setter.apply(session, session).accept(ts); Assert.assertFalse(session.equals(session2)); } diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/TimeGeneratorTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/TimeGeneratorTests.java index 8a1b9aab0..8adf8f3c1 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/TimeGeneratorTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/TimeGeneratorTests.java @@ -10,7 +10,7 @@ public void testAsIs() { long last = simulator.timestamp(); - for (int i = 0; i < 10000; i++) { + for (int i = 0; i < 10_000; i++) { long next = simulator.timestamp(); Assert.assertNotSame(last, next); } @@ -27,7 +27,7 @@ public void testMidTimeChange() { Assert.assertNotSame(last, next); } - simulator.addition = -10000; + simulator.addition = -10_000; for (int i = 0; i < 100; i++) { long next = simulator.timestamp(); @@ -41,7 +41,7 @@ public void testMidTimeChange() { Assert.assertNotSame(last, next); } - simulator.addition = 10000; + simulator.addition = 10_000; for (int i = 0; i < 100; i++) { long next = simulator.timestamp(); @@ -55,9 +55,9 @@ public void testMidTimeRandomChange() { long last = simulator.timestamp(); - for (int i = 0; i < 100000; i++) { + for (int i = 0; i < 100_000; i++) { if (i % 30 == 0) { - simulator.addition = Math.round(Math.random() * 10000 - 5000); + simulator.addition = Math.round(Math.random() * 10_000 - 5000); } long next = simulator.timestamp(); Assert.assertNotSame(last, next); @@ -65,7 +65,7 @@ public void testMidTimeRandomChange() { simulator.addition = 0; - for (int i = 0; i < 100000; i++) { + for (int i = 0; i < 100_000; i++) { if (i % 30 == 0) { simulator.addition += Math.round(Math.random() * 1000 - 500); } diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/TimeUtilsTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/TimeUtilsTests.java index 55576f266..b2dc38407 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/TimeUtilsTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/TimeUtilsTests.java @@ -45,7 +45,7 @@ public void uniqueTimestamp() { */ @Test public void nsToMs() { - Assert.assertEquals(1, TimeUtils.nsToMs(1000000)); + Assert.assertEquals(1, TimeUtils.nsToMs(1_000_000)); } /** @@ -54,7 +54,7 @@ public void nsToMs() { */ @Test public void nsToSec() { - Assert.assertEquals(1, TimeUtils.nsToSec(1000000000)); + Assert.assertEquals(1, TimeUtils.nsToSec(1_000_000_000)); } /** @@ -72,6 +72,6 @@ public void secToMs() { */ @Test public void secToNs() { - Assert.assertEquals(1000000000, TimeUtils.secToNs(1)); + Assert.assertEquals(1_000_000_000, TimeUtils.secToNs(1)); } } diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/UserEditorTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/UserEditorTests.java index 6a4aed96d..af01cc86b 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/UserEditorTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/UserEditorTests.java @@ -624,7 +624,7 @@ public void set_notAString() { .set(PredefinedUserPropertyKeys.USERNAME, new TestUtils.AtomicString("TestUsername")) .set(PredefinedUserPropertyKeys.EMAIL, new TestUtils.AtomicString("test@test.ly")) .set(PredefinedUserPropertyKeys.ORGANIZATION, new TestUtils.AtomicString("Magical Org")) - .set(PredefinedUserPropertyKeys.PHONE, 123456789) + .set(PredefinedUserPropertyKeys.PHONE, 123_456_789) .set(PredefinedUserPropertyKeys.PICTURE, new TestUtils.AtomicString("Not a picture")) .set(PredefinedUserPropertyKeys.PICTURE_PATH, new TestUtils.AtomicString("Not a picture path")) .set(PredefinedUserPropertyKeys.BIRTH_YEAR, new TestUtils.AtomicString("Not a birthyear")) From 5953ffba6aa7e93941573b74903a842a89600958 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Mon, 19 Feb 2024 08:42:15 +0000 Subject: [PATCH 03/18] [Java] Add underscore to the numerics 2 #Codacy (#244) * feat: codacy numeric * fix: timestamp --- .../sdk/java/internal/BackendModeTests.java | 144 +++++++++--------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/BackendModeTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/BackendModeTests.java index 678a5682b..5e8dc8e3d 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/BackendModeTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/BackendModeTests.java @@ -80,7 +80,7 @@ public void testMethodRecordView() { segmentation.put("start", "1"); Assert.assertEquals(0L, moduleBackendMode.eventQSize); - backendMode.recordView("device-id-1", TestUtils.keysValues[0], segmentation, 1646640780130L); + backendMode.recordView("device-id-1", TestUtils.keysValues[0], segmentation, 1_646_640_780_130L); JSONArray events = moduleBackendMode.eventQueues.get("device-id-1"); Assert.assertEquals(1L, events.length()); @@ -100,7 +100,7 @@ public void testMethodRecordView() { Assert.assertEquals("Windows", segments.get("segment")); Assert.assertEquals("1", segments.get("start")); - backendMode.recordView("device-id-2", TestUtils.keysValues[1], null, 1646640780130L); + backendMode.recordView("device-id-2", TestUtils.keysValues[1], null, 1_646_640_780_130L); events = moduleBackendMode.eventQueues.get("device-id-2"); Assert.assertEquals(1L, events.length()); @@ -129,16 +129,16 @@ public void testMethodRecordViewWithInvalidData() { /* Invalid Device ID */ Assert.assertEquals(0L, moduleBackendMode.eventQSize); - backendMode.recordView("", TestUtils.keysValues[0], segmentation, 1646640780130L); - backendMode.recordView(null, TestUtils.keysValues[1], segmentation, 1646640780130L); + backendMode.recordView("", TestUtils.keysValues[0], segmentation, 1_646_640_780_130L); + backendMode.recordView(null, TestUtils.keysValues[1], segmentation, 1_646_640_780_130L); Assert.assertTrue(moduleBackendMode.eventQueues.isEmpty()); Assert.assertEquals(0L, moduleBackendMode.eventQSize); /* Invalid view name */ Assert.assertEquals(0L, moduleBackendMode.eventQSize); - backendMode.recordView("device-id-1", "", segmentation, 1646640780130L); - backendMode.recordView("device-id-2", null, segmentation, 1646640780130L); + backendMode.recordView("device-id-1", "", segmentation, 1_646_640_780_130L); + backendMode.recordView("device-id-2", null, segmentation, 1_646_640_780_130L); Assert.assertTrue(moduleBackendMode.eventQueues.isEmpty()); Assert.assertEquals(0L, moduleBackendMode.eventQSize); @@ -157,7 +157,7 @@ public void testMethodRecordEventWithSingleDeviceID() { segmentation.put("key2", "value2"); Assert.assertEquals(0, moduleBackendMode.eventQSize); - backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); JSONArray events = moduleBackendMode.eventQueues.get("device-id-1"); Assert.assertEquals(1, events.length()); @@ -190,15 +190,15 @@ public void testMethodRecordEventWithInvalidData() { Assert.assertEquals(0, moduleBackendMode.eventQSize); /* Invalid Device ID */ - backendMode.recordEvent("", "key-1", 1, 0.1, 10.0, segmentation, 1646640780130L); - backendMode.recordEvent(null, "key-2", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("", "key-1", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); + backendMode.recordEvent(null, "key-2", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertTrue(moduleBackendMode.eventQueues.isEmpty()); Assert.assertEquals(0L, moduleBackendMode.eventQSize); /* Invalid view name */ - backendMode.recordEvent("device-id-1", "", 1, 0.1, 10.0, segmentation, 1646640780130L); - backendMode.recordEvent("device-id-1", null, 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-1", "", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); + backendMode.recordEvent("device-id-1", null, 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertTrue(moduleBackendMode.eventQueues.isEmpty()); Assert.assertEquals(0L, moduleBackendMode.eventQSize); @@ -223,12 +223,12 @@ public void testMethodRecordEventWithMultipleDeviceID() { segmentation1.put("key4", "value4"); Assert.assertEquals(0, moduleBackendMode.eventQSize); - backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(1, moduleBackendMode.eventQSize); Assert.assertEquals(1, backendMode.getQueueSize()); - backendMode.recordEvent("device-id-2", "key-2", 1, 0.1, 10.0, segmentation, 1646640780130L); - backendMode.recordEvent("device-id-2", "key-3", 2, 0.2, 20.0, segmentation1, 1646644457826L); + backendMode.recordEvent("device-id-2", "key-2", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); + backendMode.recordEvent("device-id-2", "key-3", 2, 0.2, 20.0, segmentation1, 1_646_644_457_826L); Assert.assertEquals(3, moduleBackendMode.eventQSize); Assert.assertEquals(2, backendMode.getQueueSize()); @@ -239,7 +239,7 @@ public void testMethodRecordEventWithMultipleDeviceID() { JSONObject event = events.getJSONObject(0); - long expectedTimestamp = 1646640780130L; + long expectedTimestamp = 1_646_640_780_130L; int expectedHour = getHourFromTimeStamp(expectedTimestamp); validateEventFields("key-2", 1, 0.1, 10.0, 1, expectedHour, expectedTimestamp, event); @@ -263,7 +263,7 @@ public void testMethodRecordEventWithMultipleDeviceID() { event = events.getJSONObject(1); Assert.assertEquals("key-3", event.get("key")); - expectedTimestamp = 1646644457826L; + expectedTimestamp = 1_646_644_457_826L; expectedHour = getHourFromTimeStamp(expectedTimestamp); validateEventFields("key-3", 2, 0.2, 20.0, 1, expectedHour, expectedTimestamp, event); @@ -290,43 +290,43 @@ public void TestEventThreshHoldWithSingleAndMultiple() { Assert.assertEquals(0, moduleBackendMode.eventQSize); - backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(1, moduleBackendMode.eventQSize); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-1").length()); Assert.assertEquals(1, backendMode.getQueueSize()); - backendMode.recordEvent("device-id-1", "key-2", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-1", "key-2", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(2, moduleBackendMode.eventQSize); Assert.assertEquals(2, moduleBackendMode.eventQueues.get("device-id-1").length()); Assert.assertEquals(1, backendMode.getQueueSize()); - backendMode.recordEvent("device-id-1", "key-3", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-1", "key-3", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(3, moduleBackendMode.eventQSize); Assert.assertEquals(1, backendMode.getQueueSize()); - backendMode.recordEvent("device-id-1", "key-3", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-1", "key-3", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(0, moduleBackendMode.eventQSize); Assert.assertNull(moduleBackendMode.eventQueues.get("device-id-1")); Assert.assertEquals(1, backendMode.getQueueSize()); - backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(1, moduleBackendMode.eventQSize); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-1").length()); Assert.assertEquals(2, backendMode.getQueueSize()); - backendMode.recordEvent("device-id-2", "key-2", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-2", "key-2", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(2, moduleBackendMode.eventQSize); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-1").length()); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-2").length()); Assert.assertEquals(3, backendMode.getQueueSize()); - backendMode.recordEvent("device-id-2", "key-3", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-2", "key-3", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(3, moduleBackendMode.eventQSize); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-1").length()); Assert.assertEquals(2, moduleBackendMode.eventQueues.get("device-id-2").length()); Assert.assertEquals(3, backendMode.getQueueSize()); - backendMode.recordEvent("device-id-2", "key-4", 2, 0.2, 20.0, segmentation1, 1646644457826L); + backendMode.recordEvent("device-id-2", "key-4", 2, 0.2, 20.0, segmentation1, 1_646_644_457_826L); Assert.assertEquals(0, moduleBackendMode.eventQSize); Assert.assertEquals(3, backendMode.getQueueSize()); Assert.assertNull(moduleBackendMode.eventQueues.get("device-id-1")); @@ -351,18 +351,18 @@ public void testFunctionalityAddEventsIntoRequestQueueOnSessionUpdate() { Assert.assertEquals(0, moduleBackendMode.eventQSize); Assert.assertEquals(0, SDKCore.instance.requestQueueMemory.size()); - backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(1, moduleBackendMode.eventQSize); Assert.assertEquals(0, SDKCore.instance.requestQueueMemory.size()); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-1").length()); - backendMode.recordEvent("device-id-2", "key-3", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-2", "key-3", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(2, moduleBackendMode.eventQSize); Assert.assertEquals(0, SDKCore.instance.requestQueueMemory.size()); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-1").length()); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-2").length()); - backendMode.recordEvent("device-id-2", "key-4", 2, 0.2, 20.0, segmentation1, 1646644457826L); + backendMode.recordEvent("device-id-2", "key-4", 2, 0.2, 20.0, segmentation1, 1_646_644_457_826L); Assert.assertEquals(3, moduleBackendMode.eventQSize); Assert.assertEquals(0, SDKCore.instance.requestQueueMemory.size()); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-1").length()); @@ -387,18 +387,18 @@ public void testFunctionalityAddEventsIntoRequestQueueOnSessionEnd() { Assert.assertEquals(0, moduleBackendMode.eventQSize); Assert.assertEquals(0, SDKCore.instance.requestQueueMemory.size()); - backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(1, moduleBackendMode.eventQSize); Assert.assertEquals(0, SDKCore.instance.requestQueueMemory.size()); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-1").length()); - backendMode.recordEvent("device-id-2", "key-3", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-2", "key-3", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); Assert.assertEquals(2, moduleBackendMode.eventQSize); Assert.assertEquals(0, SDKCore.instance.requestQueueMemory.size()); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-1").length()); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-2").length()); - backendMode.recordEvent("device-id-2", "key-4", 2, 0.2, 20.0, segmentation1, 1646644457826L); + backendMode.recordEvent("device-id-2", "key-4", 2, 0.2, 20.0, segmentation1, 1_646_644_457_826L); Assert.assertEquals(3, moduleBackendMode.eventQSize); Assert.assertEquals(0, SDKCore.instance.requestQueueMemory.size()); Assert.assertEquals(1, moduleBackendMode.eventQueues.get("device-id-1").length()); @@ -427,7 +427,7 @@ public void testMethodSessionBegin() { location.put("country_code", "PK"); location.put("location", "31.5204,74.3587"); - backendMode.sessionBegin("device-id-1", metrics, location, 1646640780130L); + backendMode.sessionBegin("device-id-1", metrics, location, 1_646_640_780_130L); Assert.assertEquals(1, SDKCore.instance.requestQueueMemory.size()); Request request = SDKCore.instance.requestQueueMemory.remove(); @@ -443,7 +443,7 @@ public void testMethodSessionBegin() { Assert.assertEquals("windows", sessionJson.get("os")); Assert.assertEquals("0.1", sessionJson.get("app-version")); Assert.assertEquals("1", request.params.get("begin_session")); - validateRequestTimeFields("device-id-1", 1646640780130L, request); + validateRequestTimeFields("device-id-1", 1_646_640_780_130L, request); } /** @@ -456,8 +456,8 @@ public void testMethodSessionBeginWithInvalidData() { metrics.put("os", "windows"); metrics.put("app-version", "0.1"); - backendMode.sessionBegin("", metrics, null, 1646640780130L); - backendMode.sessionBegin(null, metrics, null, 1646640780130L); + backendMode.sessionBegin("", metrics, null, 1_646_640_780_130L); + backendMode.sessionBegin(null, metrics, null, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); } @@ -468,7 +468,7 @@ public void testMethodSessionBeginWithInvalidData() { @Test public void testMethodSessionUpdate() { ModuleBackendMode.BackendMode backendMode = moduleBackendMode.new BackendMode(); - backendMode.sessionUpdate("device-id-1", 10.5, 1646640780130L); + backendMode.sessionUpdate("device-id-1", 10.5, 1_646_640_780_130L); Assert.assertEquals(1, SDKCore.instance.requestQueueMemory.size()); Request request = SDKCore.instance.requestQueueMemory.remove(); @@ -483,8 +483,8 @@ public void testMethodSessionUpdate() { @Test public void testMethodSessionUpdateWithInvalidData() { ModuleBackendMode.BackendMode backendMode = moduleBackendMode.new BackendMode(); - backendMode.sessionUpdate("", 10.5, 1646640780130L); - backendMode.sessionUpdate(null, 10.5, 1646640780130L); + backendMode.sessionUpdate("", 10.5, 1_646_640_780_130L); + backendMode.sessionUpdate(null, 10.5, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); } @@ -495,14 +495,14 @@ public void testMethodSessionUpdateWithInvalidData() { @Test public void testSessionEnd() { ModuleBackendMode.BackendMode backendMode = moduleBackendMode.new BackendMode(); - backendMode.sessionEnd("device-id-1", 10.5, 1646640780130L); + backendMode.sessionEnd("device-id-1", 10.5, 1_646_640_780_130L); Assert.assertEquals(1, SDKCore.instance.requestQueueMemory.size()); Request request = SDKCore.instance.requestQueueMemory.remove(); Assert.assertEquals("1", request.params.get("end_session")); Assert.assertEquals("10.5", request.params.get("session_duration")); - validateRequestTimeFields("device-id-1", 1646640780130L, request); + validateRequestTimeFields("device-id-1", 1_646_640_780_130L, request); } /** @@ -511,8 +511,8 @@ public void testSessionEnd() { @Test public void testMethodSessionEndWithInvalidData() { ModuleBackendMode.BackendMode backendMode = moduleBackendMode.new BackendMode(); - backendMode.sessionEnd("", 10.5, 1646640780130L); - backendMode.sessionEnd(null, 20.5, 1646640780130L); + backendMode.sessionEnd("", 10.5, 1_646_640_780_130L); + backendMode.sessionEnd(null, 20.5, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); } @@ -533,8 +533,8 @@ public void testMethodRecordException() { try { int a = 10 / 0; } catch (Exception e) { - backendMode.recordException("device-id-1", e, segmentation, crashDetails, 1646640780130L); - backendMode.recordException("device-id-2", "Divided By Zero", "stack traces", null, null, 1646640780130L); + backendMode.recordException("device-id-1", e, segmentation, crashDetails, 1_646_640_780_130L); + backendMode.recordException("device-id-2", "Divided By Zero", "stack traces", null, null, 1_646_640_780_130L); Assert.assertEquals(2, SDKCore.instance.requestQueueMemory.size()); Request request = SDKCore.instance.requestQueueMemory.remove(); @@ -550,7 +550,7 @@ public void testMethodRecordException() { Assert.assertEquals("Custom Error", crashJson.get("_error")); Assert.assertEquals("Logs", crashJson.get("_logs")); Assert.assertEquals("Operating System", crashJson.get("_os")); - validateRequestTimeFields("device-id-1", 1646640780130L, request); + validateRequestTimeFields("device-id-1", 1_646_640_780_130L, request); JSONObject segments = crashJson.getJSONObject("_custom"); Assert.assertEquals("value1", segments.get("key1")); @@ -564,7 +564,7 @@ public void testMethodRecordException() { Assert.assertEquals("Divided By Zero", crashJson.get("_name")); Assert.assertEquals("stack traces", crashJson.get("_error")); - validateRequestTimeFields("device-id-2", 1646640780130L, request); + validateRequestTimeFields("device-id-2", 1_646_640_780_130L, request); segments = crashJson.getJSONObject("_custom"); Assert.assertTrue(segments.isEmpty()); @@ -580,25 +580,25 @@ public void testMethodRecordExceptionWithInvalidData() { Map segmentation = new ConcurrentHashMap<>(); segmentation.put("key1", "value1"); - backendMode.recordException("", null, segmentation, null, 1646640780130L); + backendMode.recordException("", null, segmentation, null, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); - backendMode.recordException(null, null, segmentation, null, 1646640780130L); + backendMode.recordException(null, null, segmentation, null, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); - backendMode.recordException("device-id-1", null, segmentation, null, 1646640780130L); + backendMode.recordException("device-id-1", null, segmentation, null, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); - backendMode.recordException("device-id-2", "", "stack traces", null, null, 1646640780130L); + backendMode.recordException("device-id-2", "", "stack traces", null, null, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); - backendMode.recordException("device-id-2", "device-id", "", null, null, 1646640780130L); + backendMode.recordException("device-id-2", "device-id", "", null, null, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); - backendMode.recordException("device-id-2", null, "stack traces", null, null, 1646640780130L); + backendMode.recordException("device-id-2", null, "stack traces", null, null, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); - backendMode.recordException("device-id-2", "device-id", null, null, null, 1646640780130L); + backendMode.recordException("device-id-2", "device-id", null, null, null, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); } @@ -612,11 +612,11 @@ public void testUserDetailCustomDetailAndOperations() { // User detail Map userDetail = populateUserProperties(true, true, false); - backendMode.recordUserProperties("device-id-1", userDetail, 1646640780130L); + backendMode.recordUserProperties("device-id-1", userDetail, 1_646_640_780_130L); Assert.assertEquals(1, SDKCore.instance.requestQueueMemory.size()); Request request = SDKCore.instance.requestQueueMemory.remove(); - validateRequestTimeFields("device-id-1", 1646640780130L, request); + validateRequestTimeFields("device-id-1", 1_646_640_780_130L, request); String userDetails = request.params.get("user_details"); validateUserProperties(userDetails, true, true, false); @@ -632,11 +632,11 @@ public void testUserDetailStructureAllDataAtSameLevel() { // User detail Map userDetail = populateUserProperties(true, true, true); - backendMode.recordUserProperties("device-id-1", userDetail, 1646640780130L); + backendMode.recordUserProperties("device-id-1", userDetail, 1_646_640_780_130L); Assert.assertEquals(1, SDKCore.instance.requestQueueMemory.size()); Request request = SDKCore.instance.requestQueueMemory.remove(); - validateRequestTimeFields("device-id-1", 1646640780130L, request); + validateRequestTimeFields("device-id-1", 1_646_640_780_130L, request); String userDetails = request.params.get("user_details"); validateUserProperties(userDetails, true, true, true); @@ -652,11 +652,11 @@ public void testUserDetailStructureWithOnlyCustomDetail() { Map userDetail = populateUserProperties(false, true, false); - backendMode.recordUserProperties("device-id-1", userDetail, 1646640780130L); + backendMode.recordUserProperties("device-id-1", userDetail, 1_646_640_780_130L); Assert.assertEquals(1, SDKCore.instance.requestQueueMemory.size()); Request request = SDKCore.instance.requestQueueMemory.remove(); - validateRequestTimeFields("device-id-1", 1646640780130L, request); + validateRequestTimeFields("device-id-1", 1_646_640_780_130L, request); String userDetails = request.params.get("user_details"); validateUserProperties(userDetails, false, true, false); @@ -672,11 +672,11 @@ public void testUserDetailStructureWithOnlyOperationData() { Map userDetail = populateUserProperties(false, false, true); - backendMode.recordUserProperties("device-id-1", userDetail, 1646640780130L); + backendMode.recordUserProperties("device-id-1", userDetail, 1_646_640_780_130L); Assert.assertEquals(1, SDKCore.instance.requestQueueMemory.size()); Request request = SDKCore.instance.requestQueueMemory.remove(); - validateRequestTimeFields("device-id-1", 1646640780130L, request); + validateRequestTimeFields("device-id-1", 1_646_640_780_130L, request); String userDetails = request.params.get("user_details"); validateUserProperties(userDetails, false, false, true); @@ -690,17 +690,17 @@ public void testMethodRecordUserPropertiesWithInvalidData() { ModuleBackendMode.BackendMode backendMode = moduleBackendMode.new BackendMode(); Map userDetail = populateUserProperties(true, false, false); - backendMode.recordUserProperties("", userDetail, 1646640780130L); + backendMode.recordUserProperties("", userDetail, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); - backendMode.recordUserProperties(null, userDetail, 1646640780130L); + backendMode.recordUserProperties(null, userDetail, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); - backendMode.recordUserProperties("device-id", null, 1646640780130L); + backendMode.recordUserProperties("device-id", null, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); userDetail.clear(); - backendMode.recordUserProperties("device-id", userDetail, 1646640780130L); + backendMode.recordUserProperties("device-id", userDetail, 1_646_640_780_130L); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); } @@ -721,7 +721,7 @@ public void testEventSegmentDataType() { segmentation.put("key7", 10L); Assert.assertEquals(0, moduleBackendMode.eventQSize); - backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1646640780130L); + backendMode.recordEvent("device-id-1", "key-1", 1, 0.1, 10.0, segmentation, 1_646_640_780_130L); JSONArray events = moduleBackendMode.eventQueues.get("device-id-1"); Assert.assertEquals(1, events.length()); @@ -729,7 +729,7 @@ public void testEventSegmentDataType() { JSONObject event = events.getJSONObject(0); - long expectedTimestamp = 1646640780130L; + long expectedTimestamp = 1_646_640_780_130L; int expectedHour = getHourFromTimeStamp(expectedTimestamp); validateEventFields("key-1", 1, 0.1, 10.0, 1, expectedHour, expectedTimestamp, event); @@ -763,7 +763,7 @@ public void testViewSegmentDataType() { segmentation.put("key7", 10L); Assert.assertEquals(0, moduleBackendMode.eventQSize); - backendMode.recordView("device-id-1", "view-1", segmentation, 1646640780130L); + backendMode.recordView("device-id-1", "view-1", segmentation, 1_646_640_780_130L); JSONArray events = moduleBackendMode.eventQueues.get("device-id-1"); Assert.assertEquals(1, events.length()); @@ -804,7 +804,7 @@ public void testCrashSegmentDataType() { crashDetails.put("K2", "V2"); Assert.assertEquals(0, moduleBackendMode.eventQSize); - backendMode.recordException("device-id-1", "key-1", "stacktrace", segmentation, crashDetails, 1646640780130L); + backendMode.recordException("device-id-1", "key-1", "stacktrace", segmentation, crashDetails, 1_646_640_780_130L); Request request = SDKCore.instance.requestQueueMemory.remove(); String crash = request.params.get("crash"); @@ -845,14 +845,14 @@ public void testRecordDirectRequest() { Assert.assertEquals(0, moduleBackendMode.eventQSize); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); - backendMode.recordDirectRequest("device-id-2", requestData, 1647938191782L); + backendMode.recordDirectRequest("device-id-2", requestData, 1_647_938_191_782L); Assert.assertEquals(1, SDKCore.instance.requestQueueMemory.size()); Request request = SDKCore.instance.requestQueueMemory.remove(); Assert.assertEquals("value1", request.params.get("data1")); Assert.assertEquals("value3", request.params.get("data3")); Assert.assertEquals("1", request.params.get("dr")); - validateRequestTimeFields("device-id-2", 1647938191782L, request); + validateRequestTimeFields("device-id-2", 1_647_938_191_782L, request); // Direct request without timestamp and device id requestData = new ConcurrentHashMap<>(); @@ -861,7 +861,7 @@ public void testRecordDirectRequest() { Assert.assertEquals(0, moduleBackendMode.eventQSize); Assert.assertTrue(SDKCore.instance.requestQueueMemory.isEmpty()); - backendMode.recordDirectRequest("device-id-2", requestData, 987654321L); + backendMode.recordDirectRequest("device-id-2", requestData, 987_654_321L); Assert.assertEquals(1, SDKCore.instance.requestQueueMemory.size()); request = SDKCore.instance.requestQueueMemory.remove(); @@ -869,7 +869,7 @@ public void testRecordDirectRequest() { Assert.assertEquals("value4", request.params.get("data4")); Assert.assertEquals("1", request.params.get("dr")); - validateRequestTimeFields("device-id-2", 987654321L, request); + validateRequestTimeFields("device-id-2", 987_654_321L, request); } private Map populateUserProperties(boolean addUserDetail, boolean addCustomDetail, boolean addOperation) { From 812c14a53ade1374e1bd8e75fe20718da809d6f6 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Wed, 21 Feb 2024 22:54:47 +0000 Subject: [PATCH 04/18] refactor: reorder field declarations to the top (#245) --- .../main/java/ly/count/sdk/java/Config.java | 303 +++++++++--------- .../main/java/ly/count/sdk/java/Countly.java | 5 +- .../count/sdk/java/internal/ConfigViews.java | 3 +- .../ly/count/sdk/java/internal/Device.java | 9 +- .../ly/count/sdk/java/internal/EventImpl.java | 26 +- .../java/internal/ImmediateRequestMaker.java | 6 +- .../sdk/java/internal/ModuleDeviceIdCore.java | 6 +- .../ly/count/sdk/java/internal/SDKCore.java | 37 +-- .../ly/count/sdk/java/internal/Tasks.java | 22 +- 9 files changed, 203 insertions(+), 214 deletions(-) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Config.java b/sdk-java/src/main/java/ly/count/sdk/java/Config.java index 783022c06..51709a6a1 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Config.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Config.java @@ -22,136 +22,6 @@ * Countly configuration object. */ public class Config { - /** - * Logging level for {@link Log} module - */ - public enum LoggingLevel { - VERBOSE(0), - DEBUG(1), - INFO(2), - WARN(3), - ERROR(4), - OFF(5); - - private final int level; - - LoggingLevel(int level) { - this.level = level; - } - - public int getLevel() { - return level; - } - - public boolean prints(LoggingLevel l) { - return level <= l.level; - } - } - - public enum DeviceIdStrategy { - UUID(0), - CUSTOM_ID(10); - - private final int index; - - DeviceIdStrategy(int level) { - this.index = level; - } - - public int getIndex() { - return index; - } - - public static DeviceIdStrategy fromIndex(int index) { - if (index == UUID.index) { - return UUID; - } - if (index == CUSTOM_ID.index) { - return CUSTOM_ID; - } - return null; - } - } - - public enum Feature { - Events(CoreFeature.Events.getIndex()), - Sessions(CoreFeature.Sessions.getIndex()), - Views(CoreFeature.Views.getIndex()), - CrashReporting(CoreFeature.CrashReporting.getIndex()), - Location(CoreFeature.Location.getIndex()), - UserProfiles(CoreFeature.UserProfiles.getIndex()), - Feedback(CoreFeature.Feedback.getIndex()), - RemoteConfig(CoreFeature.RemoteConfig.getIndex()); - // StarRating(1 << 12), - // PerformanceMonitoring(1 << 14); - - private final int index; - - Feature(int index) { - this.index = index; - } - - public int getIndex() { - return index; - } - - public static Config.Feature byIndex(int index) { - if (index == Events.index) { - return Events; - } else if (index == Sessions.index) { - return Sessions; - } else if (index == Views.index) { - return Views; - } else if (index == CrashReporting.index) { - return CrashReporting; - } else if (index == Location.index) { - return Location; - } else if (index == UserProfiles.index) { - return UserProfiles; - } else if (index == RemoteConfig.index) { - return RemoteConfig; - } else if (index == Feedback.index) { - return Feedback; - } else { - return null; - } - } - } - - /** - * Holder class for various ids met - * adata and id itself. Final, unmodifiable. - */ - public static final class DID { - public static final int STRATEGY_UUID = 0; - public static final int STRATEGY_CUSTOM = 10; - public int strategy; - public String id; - - public DID(int strategy, String id) { - this.strategy = strategy; - this.id = id; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof DID)) { - return false; - } - DID did = (DID) obj; - return did.strategy == strategy && Objects.equals(did.id, id); - } - - @Override - public int hashCode() { - return id.hashCode(); - } - - @Override - public String toString() { - return "DID " + id + " ( " + strategy + ")"; - } - } protected Log configLog; @@ -360,26 +230,7 @@ public String toString() { */ protected boolean unhandledCrashReportingEnabled = true; - /** - * Get the maximum amount of breadcrumbs. Default is 100. - * - * @param maxBreadcrumbCount the maximum amount of breadcrumbs - * @return {@code this} instance for method chaining - */ - public Config setMaxBreadcrumbCount(int maxBreadcrumbCount) { - this.maxBreadcrumbCount = maxBreadcrumbCount; - return this; - } - - /** - * Disable automatic crash reporting for unhandled exceptions. - * - * @return {@code this} instance for method chaining - */ - public Config disableUnhandledCrashReporting() { - this.unhandledCrashReportingEnabled = false; - return this; - } + public ConfigViews views = new ConfigViews(this); protected String location = null; protected String ip = null; @@ -425,6 +276,27 @@ public Config(String serverURL, String serverAppKey, File sdkStorageRootDirector this.sdkStorageRootDirectory = sdkStorageRootDirectory; } + /** + * Get the maximum amount of breadcrumbs. Default is 100. + * + * @param maxBreadcrumbCount the maximum amount of breadcrumbs + * @return {@code this} instance for method chaining + */ + public Config setMaxBreadcrumbCount(int maxBreadcrumbCount) { + this.maxBreadcrumbCount = maxBreadcrumbCount; + return this; + } + + /** + * Disable automatic crash reporting for unhandled exceptions. + * + * @return {@code this} instance for method chaining + */ + public Config disableUnhandledCrashReporting() { + this.unhandledCrashReportingEnabled = false; + return this; + } + /** * Whether to allow fallback from unavailable device id strategy to Countly OpenUDID derivative. * @@ -1458,5 +1330,134 @@ public Config disableLocation() { return this; } - public ConfigViews views = new ConfigViews(this); + /** + * Logging level for {@link Log} module + */ + public enum LoggingLevel { + VERBOSE(0), + DEBUG(1), + INFO(2), + WARN(3), + ERROR(4), + OFF(5); + + private final int level; + + LoggingLevel(int level) { + this.level = level; + } + + public int getLevel() { + return level; + } + + public boolean prints(LoggingLevel l) { + return level <= l.level; + } + } + + public enum DeviceIdStrategy { + UUID(0), + CUSTOM_ID(10); + + private final int index; + + DeviceIdStrategy(int level) { + this.index = level; + } + + public int getIndex() { + return index; + } + + public static DeviceIdStrategy fromIndex(int index) { + if (index == UUID.index) { + return UUID; + } + if (index == CUSTOM_ID.index) { + return CUSTOM_ID; + } + return null; + } + } + + public enum Feature { + Events(CoreFeature.Events.getIndex()), + Sessions(CoreFeature.Sessions.getIndex()), + Views(CoreFeature.Views.getIndex()), + CrashReporting(CoreFeature.CrashReporting.getIndex()), + Location(CoreFeature.Location.getIndex()), + UserProfiles(CoreFeature.UserProfiles.getIndex()), + Feedback(CoreFeature.Feedback.getIndex()), + RemoteConfig(CoreFeature.RemoteConfig.getIndex()); + // StarRating(1 << 12), + // PerformanceMonitoring(1 << 14); + + private final int index; + + Feature(int index) { + this.index = index; + } + + public int getIndex() { + return index; + } + + public static Config.Feature byIndex(int index) { + if (index == Events.index) { + return Events; + } else if (index == Sessions.index) { + return Sessions; + } else if (index == Views.index) { + return Views; + } else if (index == CrashReporting.index) { + return CrashReporting; + } else if (index == Location.index) { + return Location; + } else if (index == UserProfiles.index) { + return UserProfiles; + } else if (index == RemoteConfig.index) { + return RemoteConfig; + } else if (index == Feedback.index) { + return Feedback; + } else { + return null; + } + } + } + + /** + * Holder class for various ids met + * adata and id itself. Final, unmodifiable. + */ + public static final class DID { + public static final int STRATEGY_UUID = 0; + public static final int STRATEGY_CUSTOM = 10; + public int strategy; + public String id; + + public DID(int strategy, String id) { + this.strategy = strategy; + this.id = id; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof DID)) { + return false; + } + DID did = (DID) obj; + return did.strategy == strategy && Objects.equals(did.id, id); + } + + @Override + public int hashCode() { + return id.hashCode(); + } + + @Override + public String toString() { + return "DID " + id + " ( " + strategy + ")"; + } + } } diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Countly.java b/sdk-java/src/main/java/ly/count/sdk/java/Countly.java index c1dbbab4f..e044a13f4 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Countly.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Countly.java @@ -35,6 +35,8 @@ public class Countly implements Usage { public static final Device device = Device.dev; private static final Countly cly = SingletonHolder.INSTANCE; + protected SDKCore sdk; + protected Log L; private static class SingletonHolder { private static final Countly INSTANCE = new Countly(); @@ -49,9 +51,6 @@ private static void empty() { } } - protected SDKCore sdk; - protected Log L; - protected Countly(SDKCore sdk, final Log logger) { L = logger; this.sdk = sdk; diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigViews.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigViews.java index 6886181b0..62ba62631 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigViews.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigViews.java @@ -5,13 +5,12 @@ public class ConfigViews { private final Config config; + protected Map globalViewSegmentation = null; public ConfigViews(Config config) { this.config = config; } - protected Map globalViewSegmentation = null; - /** * @param segmentation segmentation values that will be added for all recorded views (manual and automatic) * @return Returns the same config object for convenient linking diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java index baf5279b7..30278712d 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java @@ -28,8 +28,11 @@ public class Device { private String orientation; private Boolean online; private Boolean muted; - private Log L; + protected static final Double NS_IN_SECOND = 1_000_000_000.0d; + protected static final Double NS_IN_MS = 1_000_000.0d; + protected static final Double MS_IN_SECOND = 1000d; + protected static final Long BYTES_IN_MB = 1024L * 1024; private final Map metricOverride = new ConcurrentHashMap<>(); @@ -44,10 +47,6 @@ public void setLog(Log L) { /** * One second in nanoseconds */ - protected static final Double NS_IN_SECOND = 1_000_000_000.0d; - protected static final Double NS_IN_MS = 1_000_000.0d; - protected static final Double MS_IN_SECOND = 1000d; - protected static final Long BYTES_IN_MB = 1024L * 1024; /** * Get operation system name diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java index 978fbc0e1..211628f56 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java @@ -33,6 +33,19 @@ class EventImpl implements Event, JSONable { final Log L; + protected static final String SEGMENTATION_KEY = "segmentation"; + protected static final String KEY_KEY = "key"; + protected static final String COUNT_KEY = "count"; + protected static final String SUM_KEY = "sum"; + protected static final String DUR_KEY = "dur"; + protected static final String TIMESTAMP_KEY = "timestamp"; + protected static final String DAY_OF_WEEK = "dow"; + protected static final String HOUR = "hour"; + protected static final String ID_KEY = "id"; + protected static final String PV_ID_KEY = "pvid"; + protected static final String CV_ID_KEY = "cvid"; + protected static final String PE_ID_KEY = "peid"; + public interface EventRecorder { void recordEvent(Event event); } @@ -240,19 +253,6 @@ public boolean equals(Object obj) { return true; } - protected static final String SEGMENTATION_KEY = "segmentation"; - protected static final String KEY_KEY = "key"; - protected static final String COUNT_KEY = "count"; - protected static final String SUM_KEY = "sum"; - protected static final String DUR_KEY = "dur"; - protected static final String TIMESTAMP_KEY = "timestamp"; - protected static final String DAY_OF_WEEK = "dow"; - protected static final String HOUR = "hour"; - protected static final String ID_KEY = "id"; - protected static final String PV_ID_KEY = "pvid"; - protected static final String CV_ID_KEY = "cvid"; - protected static final String PE_ID_KEY = "peid"; - /** * Serialize to JSON format according to Countly server requirements * diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java index abced9ad7..36683c06a 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java @@ -10,6 +10,9 @@ */ class ImmediateRequestMaker implements ImmediateRequestI { + private InternalImmediateRequestCallback callback; + private Log L; + @Override public void doWork(String requestData, String customEndpoint, Transport cp, boolean requestShouldBeDelayed, boolean networkingIsEnabled, InternalImmediateRequestCallback callback, Log log) { CompletableFuture.supplyAsync(() -> doInBackground(requestData, customEndpoint, cp, requestShouldBeDelayed, networkingIsEnabled, callback, log)) @@ -23,9 +26,6 @@ protected interface InternalImmediateRequestCallback { void callback(JSONObject checkResponse); } - private InternalImmediateRequestCallback callback; - private Log L; - /** * params fields: * 0 - requestData diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java index dbc410e1d..7e39ecfe8 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java @@ -21,6 +21,8 @@ public class ModuleDeviceIdCore extends ModuleBase { * Tasks instance for async execution */ private Tasks tasks; + private static final Map generators = new ConcurrentHashMap<>(); + protected DeviceId deviceIdInterface; private static final class UUIDGenerator implements DeviceIdGenerator { @@ -44,10 +46,6 @@ public String generate(InternalConfig config) { } } - private static final Map generators = new ConcurrentHashMap<>(); - - protected DeviceId deviceIdInterface; - @Override public void init(InternalConfig config) throws IllegalArgumentException { super.init(config); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java index ee5a38598..b912c567f 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java @@ -6,26 +6,37 @@ import java.util.Map; import java.util.Queue; import java.util.TreeMap; -import javax.annotation.Nonnull; import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import ly.count.sdk.java.Config; public class SDKCore { protected static SDKCore instance; - protected final SDKStorage sdkStorage; private UserImpl user; - public InternalConfig config; protected Networking networking; protected Queue requestQueueMemory = null; - protected final Object lockBRQStorage = new Object(); - private CountlyTimer countlyTimer; + protected Log L = null; + protected static ModuleBase testDummyModule = null;//set during testing when trying to check the SDK's lifecycle + /** + * Currently enabled features with consents + */ + protected int consents = 0; + + /** + * Selected by config map of module mappings + */ + private static final Map> moduleMappings = new ConcurrentHashMap<>(); + + // TreeMap to keep modules sorted by their feature indexes + protected final Map modules; + public enum Signal { DID(1), Crash(2), @@ -49,9 +60,6 @@ public SDKCore() { sdkStorage = new SDKStorage(); } - protected Log L = null; - protected static ModuleBase testDummyModule = null;//set during testing when trying to check the SDK's lifecycle - protected static void registerDefaultModuleMappings() { moduleMappings.put(CoreFeature.DeviceId, ModuleDeviceIdCore.class); moduleMappings.put(CoreFeature.Requests, ModuleRequests.class); @@ -67,19 +75,6 @@ protected static void registerDefaultModuleMappings() { moduleMappings.put(CoreFeature.Location, ModuleLocation.class); } - /** - * Currently enabled features with consents - */ - protected int consents = 0; - - /** - * Selected by config map of module mappings - */ - private static final Map> moduleMappings = new ConcurrentHashMap<>(); - - // TreeMap to keep modules sorted by their feature indexes - protected final Map modules; - /** * Check if consent has been given for a feature * diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Tasks.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Tasks.java index 86767e935..9d1659708 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Tasks.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Tasks.java @@ -17,8 +17,17 @@ public class Tasks { public static final Long ID_STRICT = 0L; public static final Long ID_LIST = -1L; - final Log L; + /** + * Service which runs {@link Callable}s + */ + private final ExecutorService executor; + private Long running = null; + + /** + * Map of {@link Future}s for {@link Callable}s not yet resolved + */ + private final Map pending; public static abstract class Task implements Callable { Long id; @@ -34,17 +43,6 @@ public interface Callback { void call(T param) throws Exception; } - /** - * Service which runs {@link Callable}s - */ - private final ExecutorService executor; - private Long running = null; - - /** - * Map of {@link Future}s for {@link Callable}s not yet resolved - */ - private final Map pending; - public Tasks(final String name, Log L) { this.L = L; executor = Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, name)); From bb3d8892b13890fc5dd8846126c854c284f89cac Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Thu, 22 Feb 2024 15:36:44 +0000 Subject: [PATCH 05/18] Update Device.java (#246) --- .../src/main/java/ly/count/sdk/java/internal/Device.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java index 30278712d..391343742 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java @@ -29,6 +29,10 @@ public class Device { private Boolean online; private Boolean muted; private Log L; + + /** + * One second in nanoseconds + */ protected static final Double NS_IN_SECOND = 1_000_000_000.0d; protected static final Double NS_IN_MS = 1_000_000.0d; protected static final Double MS_IN_SECOND = 1000d; @@ -44,10 +48,6 @@ public void setLog(Log L) { this.L = L; } - /** - * One second in nanoseconds - */ - /** * Get operation system name * From 1348243e1f06ed161350bf09c55a4b07130570c8 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Thu, 22 Feb 2024 15:37:11 +0000 Subject: [PATCH 06/18] Update UtilsTests.java (#247) --- .../src/test/java/ly/count/sdk/java/internal/UtilsTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java index d6e2bf8aa..471a6bf8d 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java @@ -208,9 +208,9 @@ public void urlencode_empty() { */ @Test public void urlencode_symbols() { - final String givenString = "~!@ #$%^&()_+{ }:\"|[]\\|,./<>?❤️"; + final String givenString = "~!@ #$%^&()_+{ }:\"|[]\\|,./<>?"; final String res = Utils.urlencode(givenString, null); - Assert.assertEquals("%7E%21%40+%23%24%25%5E%26%28%29_%2B%7B+%7D%3A%22%7C%5B%5D%5C%7C%2C.%2F%3C%3E%3F%E2%9D%A4%EF%B8%8F", res); + Assert.assertEquals("%7E%21%40+%23%24%25%5E%26%28%29_%2B%7B+%7D%3A%22%7C%5B%5D%5C%7C%2C.%2F%3C%3E%3F", res); } /** From 47e7a33b07b5542811df2d71bcfb9bfac6981cb1 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Thu, 22 Feb 2024 15:37:35 +0000 Subject: [PATCH 07/18] Update UtilsTests.java (#248) --- .../test/java/ly/count/sdk/java/internal/UtilsTests.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java index 471a6bf8d..1b409e272 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java @@ -411,13 +411,12 @@ public void readFileContent_fileNotReadable() throws IOException { BufferedWriter writer = Files.newBufferedWriter(file.toPath()); writer.write(fileContent); writer.close(); - Files.setPosixFilePermissions(file.toPath(), EnumSet.of(PosixFilePermission.OWNER_WRITE)); - String content = Utils.readFileContent(file, logger); if (System.getProperty("os.name").toLowerCase().contains("win")) { - Assert.assertEquals(fileContent, content); + Assert.assertEquals(fileContent, Utils.readFileContent(file, logger)); } else { - Assert.assertEquals("", content); + Files.setPosixFilePermissions(file.toPath(), EnumSet.of(PosixFilePermission.OWNER_WRITE)); + Assert.assertEquals("", Utils.readFileContent(file, logger)); } } finally { File file = new File(TEST_FILE_NAME); From 04894bf1e86acd3f1ea409ea742c0f9006fd9f08 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:28:51 +0000 Subject: [PATCH 08/18] Update dated-out authType check for SSLSecurity (#249) --- .../java/ly/count/sdk/java/internal/Transport.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java index f275270fc..c158e4fb6 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java @@ -465,8 +465,12 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) throws throw new IllegalArgumentException("PublicKeyManager: X509Certificate is empty"); } - if (!(null != authType && authType.contains("RSA"))) { - throw new CertificateException("PublicKeyManager: AuthType is not RSA"); + if (authType == null) { + throw new CertificateException("PublicKeyManager: AuthType is null"); + } + + if (authType.isEmpty()) { + throw new CertificateException("PublicKeyManager: AuthType is empty"); } // Perform standard SSL/TLS checks @@ -496,4 +500,4 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) throws public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } -} \ No newline at end of file +} From c6db76602264dadd9b72fd29a21990ecdb2d0142 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Mon, 8 Apr 2024 08:16:04 +0000 Subject: [PATCH 09/18] feat: set id (#250) * feat: set id * feat: changelog * doc: comments * refactor: spread out * feat: pr changes * feat: combine tests * feat: add comment to test setId * Update ModuleDeviceIdTests.java --- CHANGELOG.md | 4 + .../sdk/java/internal/ModuleDeviceIdCore.java | 35 +++ .../java/internal/ModuleDeviceIdTests.java | 221 ++++++++++++++++-- 3 files changed, 236 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bd4f5c38..7a269ceef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## XX.XX.XX + +* Added a new function "setID(newDeviceId)" for managing device id changes according to the device ID Type. + ## 24.1.0 * !! Major breaking change !! The following method and its functionality is deprecated from the "UserEditor" interface and will not function anymore: diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java index 7e39ecfe8..e77f93c54 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java @@ -195,6 +195,29 @@ protected Config.DID acquireId() { return did; } + private void setIDInternal(String newDeviceID) { + if (Utils.isEmptyOrNull(newDeviceID)) { + L.w("[ModuleDeviceIdCore] setID, Empty id passed to setID method"); + return; + } + + if (getIDInternal().equals(newDeviceID)) { + L.w("[ModuleDeviceIdCore] setID, Same id passed to setID method, ignoring"); + return; + } + + if (getTypeInternal().equals(DeviceIdType.DEVELOPER_SUPPLIED)) { + // an ID was provided by the host app previously + // we can assume that a device ID change with merge was executed previously + // now we change it without merging + changeDeviceIdInternal(newDeviceID, DeviceIdType.DEVELOPER_SUPPLIED, false); + } else { + // SDK generated ID + // we change device ID with merge so that data is combined + changeDeviceIdInternal(newDeviceID, DeviceIdType.DEVELOPER_SUPPLIED, true); + } + } + @Override public void stop(InternalConfig config, boolean clear) { if (tasks != null) { @@ -225,6 +248,18 @@ public String getID() { } } + /** + * Sets device ID according to the device ID Type. + * If previous ID was Developer Supplied sets it without merge, otherwise with merge. + * + * @param newDeviceID device id to set + */ + public void setID(String newDeviceID) { + synchronized (Countly.instance()) { + setIDInternal(newDeviceID); + } + } + /** * Returns current device id type. * diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleDeviceIdTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleDeviceIdTests.java index a0882287d..9dc24366f 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleDeviceIdTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleDeviceIdTests.java @@ -4,6 +4,7 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import ly.count.sdk.java.Config; import ly.count.sdk.java.Countly; @@ -59,7 +60,7 @@ public void customDeviceId() { @Test public void changeWithMerge() { TestUtils.AtomicString deviceID = new TestUtils.AtomicString(TestUtils.DEVICE_ID); - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, false, DeviceIdType.DEVELOPER_SUPPLIED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, no(), DeviceIdType.DEVELOPER_SUPPLIED); Countly.instance().init(TestUtils.getConfigDeviceId(null)); // to create sdk generated device id setupView_Event_Session(); Assert.assertEquals(1, TestUtils.getCurrentRQ().length); // began session request @@ -96,7 +97,7 @@ public void changeWithoutMerge() throws InterruptedException { //why atomic string? Because changing it should also trigger dummy module callback asserts. //so it should be modifiable from outside TestUtils.AtomicString deviceID = new TestUtils.AtomicString(TestUtils.keysValues[0]); - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, true, DeviceIdType.DEVELOPER_SUPPLIED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, yes(), DeviceIdType.DEVELOPER_SUPPLIED); Countly.instance().init(TestUtils.getConfigDeviceId(TestUtils.DEVICE_ID)); //custom id given setupView_Event_Session(); // setup view, event and session to simulate a device id change validateBeganSessionRequest(); // also validates rq size is 1 @@ -129,7 +130,7 @@ public void changeWithoutMerge_sameDeviceId() { //why atomic string? Because changing it should also trigger dummy module callback asserts. //so it should be modifiable from outside TestUtils.AtomicString deviceID = new TestUtils.AtomicString(TestUtils.keysValues[0]); - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, true, DeviceIdType.DEVELOPER_SUPPLIED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, yes(), DeviceIdType.DEVELOPER_SUPPLIED); Countly.instance().init(TestUtils.getConfigDeviceId(null)); //let sdk generate setupView_Event_Session(); // setup view, event and session to simulate a device id change validateBeganSessionRequest(); // also validates rq size is 1 @@ -153,7 +154,7 @@ public void changeWithoutMerge_nullDeviceId() { //why atomic string? Because changing it should also trigger dummy module callback asserts. //so it should be modifiable from outside TestUtils.AtomicString deviceID = new TestUtils.AtomicString(TestUtils.keysValues[0]); - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, true, DeviceIdType.DEVELOPER_SUPPLIED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, yes(), DeviceIdType.DEVELOPER_SUPPLIED); Countly.instance().init(TestUtils.getConfigDeviceId(null)); //let sdk generate setupView_Event_Session(); // setup view, event and session to simulate a device id change validateBeganSessionRequest(); // also validates rq size is 1 @@ -177,7 +178,7 @@ public void changeWithoutMerge_emptyDeviceId() { //why atomic string? Because changing it should also trigger dummy module callback asserts. //so it should be modifiable from outside TestUtils.AtomicString deviceID = new TestUtils.AtomicString(TestUtils.keysValues[0]); - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, true, DeviceIdType.DEVELOPER_SUPPLIED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, yes(), DeviceIdType.DEVELOPER_SUPPLIED); Countly.instance().init(TestUtils.getConfigDeviceId(null)); //let sdk generate setupView_Event_Session(); // setup view, event and session to simulate a device id change validateBeganSessionRequest(); // also validates rq size is 1 @@ -198,7 +199,7 @@ public void changeWithoutMerge_emptyDeviceId() { */ @Test public void changeWithMerge_nullDeviceId() { - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(null, false, DeviceIdType.SDK_GENERATED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(null, no(), DeviceIdType.SDK_GENERATED); Countly.instance().init(TestUtils.getConfigDeviceId(null)); // to create sdk generated device id setupView_Event_Session(); @@ -220,7 +221,7 @@ public void changeWithMerge_nullDeviceId() { */ @Test public void changeWithMerge_emptyDeviceId() { - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(new TestUtils.AtomicString(""), false, DeviceIdType.SDK_GENERATED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(new TestUtils.AtomicString(""), no(), DeviceIdType.SDK_GENERATED); Countly.instance().init(TestUtils.getConfigDeviceId(null)); // to create sdk generated device id setupView_Event_Session(); @@ -243,7 +244,7 @@ public void changeWithMerge_emptyDeviceId() { */ @Test public void changeWithMerge_sameDeviceId() throws InterruptedException { - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(new TestUtils.AtomicString(TestUtils.DEVICE_ID), false, DeviceIdType.DEVELOPER_SUPPLIED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(new TestUtils.AtomicString(TestUtils.DEVICE_ID), no(), DeviceIdType.DEVELOPER_SUPPLIED); Countly.instance().init(TestUtils.getConfigDeviceId(null)); // to create sdk generated device id setupView_Event_Session(); Thread.sleep(200); // wait for session request to written to the disk @@ -273,7 +274,7 @@ public void changeWithMerge_sameDeviceId() throws InterruptedException { */ @Test public void changeWithMerge_sessionNotStarted() { - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(new TestUtils.AtomicString(TestUtils.DEVICE_ID), false, DeviceIdType.DEVELOPER_SUPPLIED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(new TestUtils.AtomicString(TestUtils.DEVICE_ID), no(), DeviceIdType.DEVELOPER_SUPPLIED); Countly.instance().init(TestUtils.getConfigDeviceId(null)); // to create sdk generated device id setupEvent(); @@ -296,7 +297,7 @@ public void changeWithMerge_sessionNotStarted() { */ @Test public void changeWithoutMerge_sessionNotStarted() { - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(new TestUtils.AtomicString(TestUtils.DEVICE_ID), true, DeviceIdType.DEVELOPER_SUPPLIED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(new TestUtils.AtomicString(TestUtils.DEVICE_ID), yes(), DeviceIdType.DEVELOPER_SUPPLIED); Countly.instance().init(TestUtils.getConfigDeviceId(null)); // to create sdk generated device id validateDeviceIdIsSdkGenerated(); @@ -314,7 +315,7 @@ public void changeWithoutMerge_sessionNotStarted() { */ @Test public void changeWithoutMerge_sessionNotStarted_withEvents() throws InterruptedException { - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(new TestUtils.AtomicString(TestUtils.DEVICE_ID), true, DeviceIdType.DEVELOPER_SUPPLIED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(new TestUtils.AtomicString(TestUtils.DEVICE_ID), yes(), DeviceIdType.DEVELOPER_SUPPLIED); Countly.instance().init(TestUtils.getConfigDeviceId(null)); // to create sdk generated device id setupEvent(); // two events created one is timed event it is started, the other is casual event String oldDeviceId = Countly.instance().deviceId().getID(); @@ -360,7 +361,7 @@ public void getID_getType_customDeviceId() { */ @Test public void logout_sdkGenerated() throws InterruptedException { - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(null, true, DeviceIdType.SDK_GENERATED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(null, yes(), DeviceIdType.SDK_GENERATED); Countly.instance().init(TestUtils.getConfigDeviceId(null)); // to create sdk generated device id setupView_Event_Session(); @@ -382,7 +383,7 @@ public void logout_sdkGenerated() throws InterruptedException { @Test public void logout_developerSupplied() { TestUtils.AtomicString deviceID = new TestUtils.AtomicString(TestUtils.DEVICE_ID); - AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, true, DeviceIdType.SDK_GENERATED); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, yes(), DeviceIdType.SDK_GENERATED); Countly.instance().init(TestUtils.getConfigDeviceId(TestUtils.DEVICE_ID)); // to create sdk generated device id setupView_Event_Session(); @@ -422,6 +423,164 @@ public void acquireId_customId() { Assert.assertEquals(TestUtils.DEVICE_ID, did.id); } + /** + * "setID" + * - Validate that device id is generated by the sdk + * - Set a new id and validate that it is set + * - Set null and validate that it is not changed + * - Set empty and validate that it is not changed + * - Set the same id and validate that it is not changed + */ + @Test + public void setID() { + Countly.instance().init(TestUtils.getBaseConfig(null)); // no custom id provided + validateDeviceIdIsSdkGenerated(); // validate id exist and sdk generated + + String newId = TestUtils.keysValues[0]; + Countly.instance().deviceId().setID(newId); + validateDeviceIdDeveloperSupplied(newId); + + Countly.instance().deviceId().setID(null); + validateDeviceIdDeveloperSupplied(newId); + + Countly.instance().deviceId().setID(""); + validateDeviceIdDeveloperSupplied(newId); + + Countly.instance().deviceId().setID(Countly.instance().deviceId().getID()); + validateDeviceIdDeveloperSupplied(newId); + } + + /** + * "setID" with custom device id + * - validate that device id is developer supplied + * - set same id and validate that it is not set + */ + @Test + public void setID_sameCustom() { + Countly.instance().init(TestUtils.getBaseConfig(TestUtils.DEVICE_ID)); // custom id provided + validateDeviceIdDeveloperSupplied(TestUtils.DEVICE_ID); // validate id exist and developer supplied + + Countly.instance().deviceId().setID(TestUtils.DEVICE_ID); + validateDeviceIdDeveloperSupplied(TestUtils.DEVICE_ID); + } + + /** + * "setID" with custom device id + * - validate that device id is developer supplied + * - set new id and validate that it is set + */ + @Test + public void setID_custom() { + Countly.instance().init(TestUtils.getBaseConfig(TestUtils.DEVICE_ID)); // custom id provided + validateDeviceIdDeveloperSupplied(TestUtils.DEVICE_ID); // validate id exist and developer supplied + + String newId = TestUtils.keysValues[0]; + Countly.instance().deviceId().setID(newId); + validateDeviceIdDeveloperSupplied(newId); + } + + /** + * "setID" with double without merge + * Validating that new id set and callback is called, and existing events,timed events and session must end, new session must begin + * request order should be first began session, 1 events, 1 end session, second began session, second end session, third began session + *
+ * - Init the SDK with custom device id TestUtil.DEVICE_ID + * - Setup session, view and event + * - Validate that session is begun + * - Validate that device id is developer supplied, and it is TestUtil.DEVICE_ID + * - Wait for view duration to end + * - Validate that there are 2 events in the event queue (view start and casual event) + * - Set new device id TestUtil.keysValues[0] + * - Validate that there are no events in the event queue because it is flushed due to device id without merge change + * - Validate that callback is called once which is "deviceIdChanged" internal callback + * - Validate that there are 4 requests in the request queue, first began session, 1 events, 1 end session, second began session + * - Flush the request queue with old device id TestUtil.DEVICE_ID + * - Change device id to TestUtils.DEVICE_ID + "1" + * - Validate that there are 2 calls to the callback + * - Validate that there are 3 requests in the request queue, second began session, second end session, third began session + */ + @Test + public void setID_changeWithoutMerge() throws InterruptedException { + //why atomic string? Because changing it should also trigger dummy module callback asserts. + //so it should be modifiable from outside + TestUtils.AtomicString deviceID = new TestUtils.AtomicString(TestUtils.keysValues[0]); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, yes(), DeviceIdType.DEVELOPER_SUPPLIED); + Countly.instance().init(TestUtils.getConfigDeviceId(TestUtils.DEVICE_ID)); //custom id given + setupView_Event_Session(); // setup view, event and session to simulate a device id change + validateBeganSessionRequest(); // also validates rq size is 1 + + validateDeviceIdDeveloperSupplied(TestUtils.DEVICE_ID); + Assert.assertEquals(0, callCount.get()); + + Thread.sleep(1000); // waiting for timed event duration + Assert.assertEquals(2, TestUtils.getCurrentEQ().size()); // size should be 2 one view and a casual event + Countly.instance().deviceId().setID(deviceID.value); + Assert.assertEquals(0, TestUtils.getCurrentEQ().size()); // size should be zero because queue is flushed + Assert.assertEquals(1, callCount.get()); + validateDeviceIdWithoutMergeChange(4, TestUtils.DEVICE_ID); // there should be 2 began, 1 end, 1 events request + TestUtils.flushCurrentRQWithOldDeviceId(TestUtils.DEVICE_ID); // clean current rq with old device id requests + + deviceID.value += "1"; //change device id + Countly.instance().deviceId().setID(deviceID.value); + Assert.assertEquals(2, callCount.get()); + //if device id is not merged, then device id change request should not exist + validateDeviceIdWithoutMergeChange(3, TestUtils.keysValues[0]); // additional 1 session end 1 session begin, no events because no events exist + } + + /** + * "setID" first sdk generated then developer supplied + * Validating that first call acts like "changeWithMerge" and second call acts like "changeWithoutMerge" + * SDK must generate an id first, then should change with developer supplied two times + *
+ * - Init the SDK with no custom id + * - Setup session, view and event to simulate a device id change + * - Validate that session is begun + * - Validate that device id is sdk generated + * - Set new device id TestUtils.DEVICE_ID + * - Validate that EQ size is not changed because it is merge request + * - Validate that callback is called once which is "deviceIdChanged" internal callback + * - Validate that there are 2 requests in the event queue (first is begun session second one is device id change request) + * - Flush the request queue with old device id + * - Change device id to TestUtils.DEVICE_ID + "1" + * - Validate that EQ is flushed because it is not a merge request + * - Validate that callback is called twice + * - Validate that there are 3 requests in the request queue, first began session, 1 events, 1 end session + */ + @Test + public void setID_changeWithMerge_then_withoutMerge() throws InterruptedException { + TestUtils.AtomicString deviceID = new TestUtils.AtomicString(TestUtils.DEVICE_ID); + AtomicBoolean withMerge = new AtomicBoolean(false); + AtomicInteger callCount = initDummyModuleForDeviceIdChangedCallback(deviceID, withMerge, DeviceIdType.DEVELOPER_SUPPLIED); + Countly.instance().init(TestUtils.getConfigDeviceId(null)); // to create sdk generated device id + setupView_Event_Session(); + Assert.assertEquals(1, TestUtils.getCurrentRQ().length); // began session request + // validate began session request with generated id + validateBeganSessionRequest(); + validateDeviceIdIsSdkGenerated(); // validate device id generated by the sdk + + String oldDeviceId = Countly.instance().deviceId().getID(); + Assert.assertEquals(0, callCount.get()); // validate "deviceIdChanged" callback not called + + Assert.assertEquals(2, TestUtils.getCurrentEQ().size()); // size should not change because it is merge request + Countly.instance().deviceId().setID(TestUtils.DEVICE_ID); // TestUtils.DEVICE_ID + Assert.assertEquals(2, TestUtils.getCurrentEQ().size()); // size should not change because it is merge request + + Assert.assertEquals(1, callCount.get()); + validateDeviceIdWithMergeChange(oldDeviceId, 1, 2); + TestUtils.flushCurrentRQWithOldDeviceId(oldDeviceId); // clean current rq with old device id requests + + deviceID.value = TestUtils.DEVICE_ID + "1"; + withMerge.set(true); // set atomic boolean to true to validate without merge + Thread.sleep(1000); // waiting for timed event duration + + Assert.assertEquals(2, TestUtils.getCurrentEQ().size()); // size should not change because it is merge request + Countly.instance().deviceId().setID(TestUtils.DEVICE_ID + "1"); // TestUtils.DEVICE_ID + "1" + Assert.assertEquals(0, TestUtils.getCurrentEQ().size()); // size should change because it is not a merge request + + Assert.assertEquals(2, callCount.get()); + validateDeviceIdWithoutMergeChange(3, TestUtils.DEVICE_ID, false); // there should be 1 began, 1 events request + } + /** * validates that requests in RQ are valid for without merge request * It validates the requests after a without merge device id change @@ -438,20 +597,22 @@ public void acquireId_customId() { * @param rqSize expected RQ size * @param oldDeviceId to validate device id in requests before device id change */ - private void validateDeviceIdWithoutMergeChange(final int rqSize, String oldDeviceId) { + private void validateDeviceIdWithoutMergeChange(final int rqSize, String oldDeviceId, boolean checkFirstReq) { Map[] requests = TestUtils.getCurrentRQ(); Assert.assertEquals(rqSize, TestUtils.getCurrentRQ().length); - - // validate first begin session request - TestUtils.validateRequiredParams(requests[0], oldDeviceId); // first request must be began session request - TestUtils.validateMetrics(requests[0].get("metrics")); // validate metrics exist in the first session request - Assert.assertEquals("1", requests[0].get("begin_session")); // validate begin session value is 1 - - int remainingRequestIndex = 1; // if there is no event request, then this will be 1 to continue checking + int remainingRequestIndex = 0; // if there is no begin session request, then this will be 0 to continue checking + + if (checkFirstReq) { + remainingRequestIndex = 1; // if no event request exists, then this will be 1 to continue checking + // validate first begin session request + TestUtils.validateRequiredParams(requests[0], oldDeviceId); // first request must be began session request + TestUtils.validateMetrics(requests[0].get("metrics")); // validate metrics exist in the first session request + Assert.assertEquals("1", requests[0].get("begin_session")); // validate begin session value is 1 + } // validate event request if exists try { - List existingEvents = validateEvents(1, oldDeviceId, 2); + List existingEvents = validateEvents(remainingRequestIndex, oldDeviceId, 2); if (!existingEvents.isEmpty()) { Map viewSegmentation = new ConcurrentHashMap<>(); viewSegmentation.put("segment", Device.dev.getOS()); @@ -478,6 +639,10 @@ private void validateDeviceIdWithoutMergeChange(final int rqSize, String oldDevi Assert.assertEquals("1", requests[remainingRequestIndex].get("begin_session")); // validate begin session value is 1 } + private void validateDeviceIdWithoutMergeChange(final int rqSize, String oldDeviceId) { + validateDeviceIdWithoutMergeChange(rqSize, oldDeviceId, true); + } + /** * Validates that the device id change request is valid * @@ -501,14 +666,14 @@ private void validateDeviceIdWithMergeChange(String oldDeviceId, final int rqIdx * @param type to validate by types * @return call count of the callback */ - private AtomicInteger initDummyModuleForDeviceIdChangedCallback(TestUtils.AtomicString deviceId, boolean withoutMerge, DeviceIdType type) { + private AtomicInteger initDummyModuleForDeviceIdChangedCallback(TestUtils.AtomicString deviceId, AtomicBoolean withoutMerge, DeviceIdType type) { AtomicInteger callCount = new AtomicInteger(0); SDKCore.testDummyModule = new ModuleBase() { @Override protected void deviceIdChanged(String oldDeviceId, boolean withMerge) { super.deviceIdChanged(oldDeviceId, withMerge); callCount.incrementAndGet(); - Assert.assertEquals(!withoutMerge, withMerge); + Assert.assertEquals(!withoutMerge.get(), withMerge); if (type == DeviceIdType.SDK_GENERATED) { validateDeviceIdIsSdkGenerated(); } else { @@ -601,4 +766,12 @@ private List validateEvents(int requestIndex, String deviceId, int ti return existingEvents; } + + private AtomicBoolean yes() { + return new AtomicBoolean(true); + } + + private AtomicBoolean no() { + return new AtomicBoolean(false); + } } From ed4a5806b4e0e8f015d6e29806ea96e7c6c701a9 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Wed, 25 Sep 2024 09:51:54 +0300 Subject: [PATCH 10/18] feat: upgrade vulnerable dependencies --- .idea/modules/app-java/countly-sdk-java.app-java.main.iml | 3 ++- .idea/modules/app-java/countly-sdk-java.app-java.test.iml | 3 ++- .idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml | 2 +- .idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml | 4 ++-- sdk-java/build.gradle | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.idea/modules/app-java/countly-sdk-java.app-java.main.iml b/.idea/modules/app-java/countly-sdk-java.app-java.main.iml index 5ca1f4c14..75acfebfc 100644 --- a/.idea/modules/app-java/countly-sdk-java.app-java.main.iml +++ b/.idea/modules/app-java/countly-sdk-java.app-java.main.iml @@ -8,8 +8,9 @@ - + + \ No newline at end of file diff --git a/.idea/modules/app-java/countly-sdk-java.app-java.test.iml b/.idea/modules/app-java/countly-sdk-java.app-java.test.iml index 5aa9fed79..e0a5b5d38 100644 --- a/.idea/modules/app-java/countly-sdk-java.app-java.test.iml +++ b/.idea/modules/app-java/countly-sdk-java.app-java.test.iml @@ -7,8 +7,9 @@ - + + diff --git a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml index 4617fbb81..f3724da88 100644 --- a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml +++ b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml index f85eb88cf..a01acf446 100644 --- a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml +++ b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml @@ -9,10 +9,10 @@ - + - + diff --git a/sdk-java/build.gradle b/sdk-java/build.gradle index b34615369..944a58bd1 100644 --- a/sdk-java/build.gradle +++ b/sdk-java/build.gradle @@ -13,10 +13,10 @@ buildscript { } dependencies { - implementation 'org.json:json:20230227' + implementation 'org.json:json:20231013' implementation 'com.google.code.findbugs:jsr305:3.0.2' - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13.1' testImplementation 'org.mockito:mockito-core:2.8.9' testImplementation "org.powermock:powermock-core:${POWERMOCK_VERSION}" testImplementation "org.powermock:powermock-module-junit4:${POWERMOCK_VERSION}" From 2a21abf0e2ae25207549e109330817f5c20e30f3 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Wed, 25 Sep 2024 09:52:52 +0300 Subject: [PATCH 11/18] feat: added changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a269ceef..55050453d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ * Added a new function "setID(newDeviceId)" for managing device id changes according to the device ID Type. +* Mitigated an issue where json and junit dependencies had vulnerabilities. + ## 24.1.0 * !! Major breaking change !! The following method and its functionality is deprecated from the "UserEditor" interface and will not function anymore: From 63b717350d38242b5ed739c981eab5903ff45784 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Wed, 5 Mar 2025 09:50:40 +0300 Subject: [PATCH 12/18] feat: bump json lib --- .idea/modules/app-java/countly-sdk-java.app-java.main.iml | 2 +- .idea/modules/app-java/countly-sdk-java.app-java.test.iml | 2 +- .idea/modules/sdk-java/countly-sdk-java.sdk-java.iml | 2 +- .idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml | 4 ++-- .idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml | 4 ++-- CHANGELOG.md | 2 +- build.gradle | 2 +- gradle.properties | 2 +- sdk-java/build.gradle | 2 +- sdk-java/src/main/java/ly/count/sdk/java/Config.java | 2 +- .../src/test/java/ly/count/sdk/java/internal/TestUtils.java | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.idea/modules/app-java/countly-sdk-java.app-java.main.iml b/.idea/modules/app-java/countly-sdk-java.app-java.main.iml index 75acfebfc..277e7c859 100644 --- a/.idea/modules/app-java/countly-sdk-java.app-java.main.iml +++ b/.idea/modules/app-java/countly-sdk-java.app-java.main.iml @@ -10,7 +10,7 @@ - + \ No newline at end of file diff --git a/.idea/modules/app-java/countly-sdk-java.app-java.test.iml b/.idea/modules/app-java/countly-sdk-java.app-java.test.iml index e0a5b5d38..8b92dbd4f 100644 --- a/.idea/modules/app-java/countly-sdk-java.app-java.test.iml +++ b/.idea/modules/app-java/countly-sdk-java.app-java.test.iml @@ -9,7 +9,7 @@ - + diff --git a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.iml b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.iml index 55ecd8caf..cd854dd06 100644 --- a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.iml +++ b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml index f3724da88..e0acadea5 100644 --- a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml +++ b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml @@ -1,5 +1,5 @@ - + @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml index a01acf446..fef2e76f8 100644 --- a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml +++ b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml @@ -1,5 +1,5 @@ - + @@ -9,7 +9,7 @@ - + diff --git a/CHANGELOG.md b/CHANGELOG.md index 55050453d..af507a368 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## XX.XX.XX +## 24.1.1 * Added a new function "setID(newDeviceId)" for managing device id changes according to the device ID Type. diff --git a/build.gradle b/build.gradle index fd17790c3..836bacca2 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ buildscript { } allprojects { - ext.CLY_VERSION = "24.1.0" + ext.CLY_VERSION = "24.1.1" ext.POWERMOCK_VERSION = "1.7.4" tasks.withType(Javadoc) { diff --git a/gradle.properties b/gradle.properties index baba749bd..ea49db4c2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,7 @@ # org.gradle.parallel=true # RELEASE FIELD SECTION -VERSION_NAME=24.1.0 +VERSION_NAME=24.1.1 GROUP=ly.count.sdk POM_URL=https://github.com/Countly/countly-sdk-java diff --git a/sdk-java/build.gradle b/sdk-java/build.gradle index 944a58bd1..0ecf75088 100644 --- a/sdk-java/build.gradle +++ b/sdk-java/build.gradle @@ -13,7 +13,7 @@ buildscript { } dependencies { - implementation 'org.json:json:20231013' + implementation 'org.json:json:20250107' implementation 'com.google.code.findbugs:jsr305:3.0.2' testImplementation 'junit:junit:4.13.1' diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Config.java b/sdk-java/src/main/java/ly/count/sdk/java/Config.java index 51709a6a1..c29d60379 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Config.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Config.java @@ -68,7 +68,7 @@ public class Config { /** * Countly SDK version to be sent in HTTP requests */ - protected String sdkVersion = "24.1.0"; + protected String sdkVersion = "24.1.1"; /** * Countly SDK version to be sent in HTTP requests diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java index 59ea53c04..b87d31402 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java @@ -39,7 +39,7 @@ public class TestUtils { static String SERVER_APP_KEY = "COUNTLY_APP_KEY"; static String DEVICE_ID = "some_random_test_device_id"; static String SDK_NAME = "java-native"; - static String SDK_VERSION = "24.1.0"; + static String SDK_VERSION = "24.1.1"; static String APPLICATION_VERSION = "1.0"; public static final String[] eKeys = new String[] { "eventKey1", "eventKey2", "eventKey3", "eventKey4", "eventKey5", "eventKey6", "eventKey7" }; From 62d0153d5ae9dde98db1225dbd544d7387759c55 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Wed, 16 Jul 2025 11:38:47 +0300 Subject: [PATCH 13/18] feat: network headers example --- app-java/src/main/java/ly/count/java/demo/Example.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app-java/src/main/java/ly/count/java/demo/Example.java b/app-java/src/main/java/ly/count/java/demo/Example.java index 831b87879..6516a6f06 100755 --- a/app-java/src/main/java/ly/count/java/demo/Example.java +++ b/app-java/src/main/java/ly/count/java/demo/Example.java @@ -210,9 +210,14 @@ public static void main(String[] args) throws Exception { } } + Map customNetworkRequestHeaders = new ConcurrentHashMap<>(); + customNetworkRequestHeaders.put("X-Countly-Example", "true"); + customNetworkRequestHeaders.put("X-Countly-Example-Version", "1.0"); + Config config = new Config(COUNTLY_SERVER_URL, COUNTLY_APP_KEY, sdkStorageRootDirectory) .setLoggingLevel(Config.LoggingLevel.DEBUG) .setDeviceIdStrategy(Config.DeviceIdStrategy.UUID) + .addCustomNetworkRequestHeaders(customNetworkRequestHeaders) .enableFeatures(Config.Feature.Events, Config.Feature.Sessions, Config.Feature.CrashReporting, Config.Feature.Views, Config.Feature.UserProfiles, Config.Feature.Location, Config.Feature.Feedback) .setRequiresConsent(true) //.enableParameterTamperingProtection("test-salt-checksum") From d2e90620732e5cc85c271644c4bfd88b17971a35 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Wed, 16 Jul 2025 11:38:59 +0300 Subject: [PATCH 14/18] feat: network headers config entry --- .../main/java/ly/count/sdk/java/Config.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Config.java b/sdk-java/src/main/java/ly/count/sdk/java/Config.java index c29d60379..36f0feaec 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Config.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Config.java @@ -230,6 +230,12 @@ public class Config { */ protected boolean unhandledCrashReportingEnabled = true; + /** + * Custom network request headers to be sent with each request. + * If you want to add a header, use {@link #addCustomNetworkRequestHeaders(Map)}. + */ + protected Map customNetworkRequestHeaders = null; + public ConfigViews views = new ConfigViews(this); protected String location = null; @@ -1330,6 +1336,20 @@ public Config disableLocation() { return this; } + /** + * Allows you to add custom header key/value pairs to each request + * + * @return Returns the same config object for convenient linking + */ + public Config addCustomNetworkRequestHeaders(Map customHeaderValues) { + this.customNetworkRequestHeaders = customHeaderValues; + return this; + } + + public Map getCustomNetworkRequestHeaders() { + return customNetworkRequestHeaders; + } + /** * Logging level for {@link Log} module */ From aa326cb910fece5674445dcb23196a4029468cbe Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Wed, 16 Jul 2025 11:39:08 +0300 Subject: [PATCH 15/18] feat: network headers impl --- .../java/ly/count/sdk/java/internal/Transport.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java index c158e4fb6..b016a4c15 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java @@ -149,6 +149,18 @@ HttpURLConnection connection(final Request request) throws IOException { https.setSSLSocketFactory(sslContext.getSocketFactory()); } + if (config.getCustomNetworkRequestHeaders() != null) { + //if there are custom header values, add them + L.v("[Transport] connection, Adding [" + config.getCustomNetworkRequestHeaders() + "] custom header fields"); + for (Map.Entry entry : config.getCustomNetworkRequestHeaders().entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (key != null && value != null && !key.isEmpty()) { + connection.addRequestProperty(key, value); + } + } + } + if (!usingGET) { OutputStream output = null; PrintWriter writer = null; From 58265886ec0d6b1eb672e052c3f3b500ac8a6711 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Wed, 16 Jul 2025 11:45:01 +0300 Subject: [PATCH 16/18] feat: new minor --- .idea/modules/sdk-java/countly-sdk-java.sdk-java.iml | 2 +- .idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml | 2 +- .idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml | 2 +- CHANGELOG.md | 4 ++++ build.gradle | 2 +- gradle.properties | 2 +- sdk-java/src/main/java/ly/count/sdk/java/Config.java | 2 +- .../src/test/java/ly/count/sdk/java/internal/TestUtils.java | 2 +- 8 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.iml b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.iml index cd854dd06..3a892994f 100644 --- a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.iml +++ b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml index e0acadea5..cad257110 100644 --- a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml +++ b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml index fef2e76f8..353a48789 100644 --- a/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml +++ b/.idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml @@ -1,5 +1,5 @@ - + diff --git a/CHANGELOG.md b/CHANGELOG.md index af507a368..1b98b56a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 24.1.2 + +* Added e new configuration function "addCustomNetworkRequestHeaders(Map)" to add custom request headers to each request. + ## 24.1.1 * Added a new function "setID(newDeviceId)" for managing device id changes according to the device ID Type. diff --git a/build.gradle b/build.gradle index 836bacca2..ba448809b 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ buildscript { } allprojects { - ext.CLY_VERSION = "24.1.1" + ext.CLY_VERSION = "24.1.2" ext.POWERMOCK_VERSION = "1.7.4" tasks.withType(Javadoc) { diff --git a/gradle.properties b/gradle.properties index ea49db4c2..72dc63d0b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,7 @@ # org.gradle.parallel=true # RELEASE FIELD SECTION -VERSION_NAME=24.1.1 +VERSION_NAME=24.1.2 GROUP=ly.count.sdk POM_URL=https://github.com/Countly/countly-sdk-java diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Config.java b/sdk-java/src/main/java/ly/count/sdk/java/Config.java index 36f0feaec..e94ef032a 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Config.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Config.java @@ -68,7 +68,7 @@ public class Config { /** * Countly SDK version to be sent in HTTP requests */ - protected String sdkVersion = "24.1.1"; + protected String sdkVersion = "24.1.2"; /** * Countly SDK version to be sent in HTTP requests diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java index b87d31402..91576583e 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java @@ -39,7 +39,7 @@ public class TestUtils { static String SERVER_APP_KEY = "COUNTLY_APP_KEY"; static String DEVICE_ID = "some_random_test_device_id"; static String SDK_NAME = "java-native"; - static String SDK_VERSION = "24.1.1"; + static String SDK_VERSION = "24.1.2"; static String APPLICATION_VERSION = "1.0"; public static final String[] eKeys = new String[] { "eventKey1", "eventKey2", "eventKey3", "eventKey4", "eventKey5", "eventKey6", "eventKey7" }; From a05310642663cc711cbd5c9d62c05575260566d7 Mon Sep 17 00:00:00 2001 From: turtledreams <62231246+turtledreams@users.noreply.github.com> Date: Wed, 16 Jul 2025 19:35:12 +0900 Subject: [PATCH 17/18] Dependency change --- build.gradle | 4 ++-- gradle.properties | 3 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- sdk-java/build.gradle | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index ba448809b..2e124ec0b 100644 --- a/build.gradle +++ b/build.gradle @@ -10,9 +10,9 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:4.1.3' + classpath 'com.android.tools.build:gradle:8.1.4' classpath 'com.github.dcendents:android-maven-plugin:1.2' - classpath 'com.google.gms:google-services:4.3.0' + classpath 'com.google.gms:google-services:4.4.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle.properties b/gradle.properties index 72dc63d0b..0bca7cb81 100644 --- a/gradle.properties +++ b/gradle.properties @@ -31,4 +31,5 @@ POM_LICENCE_DIST=repo POM_DEVELOPER_NAME=Countly # Publishing properties -SONATYPE_AUTOMATIC_RELEASE=true +SONATYPE_HOST=CENTRAL_PORTAL +RELEASE_SIGNING_ENABLED=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index be52383ef..fae08049a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/sdk-java/build.gradle b/sdk-java/build.gradle index 0ecf75088..60f23abd1 100644 --- a/sdk-java/build.gradle +++ b/sdk-java/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'java-library' -apply plugin: 'maven' +// apply plugin: 'maven' buildscript { @@ -8,7 +8,7 @@ buildscript { //mavenLocal() } dependencies { - classpath 'com.vanniktech:gradle-maven-publish-plugin:0.18.0' //for publishing + classpath 'com.vanniktech:gradle-maven-publish-plugin:0.28.0' //for publishing } } From 01b97b045a3142633180c196157c4e4e83518c96 Mon Sep 17 00:00:00 2001 From: turtledreams <62231246+turtledreams@users.noreply.github.com> Date: Thu, 17 Jul 2025 15:25:50 +0900 Subject: [PATCH 18/18] Update CHANGELOG.md --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b98b56a8..9fc419c2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 24.1.2 +* !! Major Breaking Change !! Minimum JDK support is 19 for this minor. -* Added e new configuration function "addCustomNetworkRequestHeaders(Map)" to add custom request headers to each request. +* Migrated from Sonatype OSSRH. +* Added a new configuration function "addCustomNetworkRequestHeaders(Map)" to add custom request headers to each request. ## 24.1.1