From 894d98ac3b3f8b6f78b9fda1fd39500c52430cb4 Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Tue, 5 Sep 2023 17:12:07 -0300 Subject: [PATCH 1/3] New treatment methods telemetry --- .../telemetry/model/MethodExceptions.java | 44 +++++++++++++++++++ .../telemetry/model/MethodLatencies.java | 44 +++++++++++++++++++ .../storage/InMemoryTelemetryStorage.java | 20 ++++++++- .../client/SplitClientImplFlagSetsTest.java | 43 ++++++++++++++++++ .../TelemetryStatsBodySerializerTest.java | 10 ++++- .../storage/InMemoryTelemetryStorageTest.java | 36 +++++++++++++++ 6 files changed, 194 insertions(+), 3 deletions(-) create mode 100644 src/test/java/io/split/android/client/SplitClientImplFlagSetsTest.java diff --git a/src/main/java/io/split/android/client/telemetry/model/MethodExceptions.java b/src/main/java/io/split/android/client/telemetry/model/MethodExceptions.java index 2a580e2c5..ff87dedab 100644 --- a/src/main/java/io/split/android/client/telemetry/model/MethodExceptions.java +++ b/src/main/java/io/split/android/client/telemetry/model/MethodExceptions.java @@ -16,6 +16,18 @@ public class MethodExceptions { @SerializedName("tcs") private long treatmentsWithConfig; + @SerializedName("tf") + private long treatmentsByFlagSet; + + @SerializedName("tfs") + private long treatmentsByFlagSets; + + @SerializedName("tfc") + private long treatmentsWithConfigByFlagSet; + + @SerializedName("tfcs") + private long treatmentsWithConfigByFlagSets; + @SerializedName("tr") private long track; @@ -51,6 +63,38 @@ public void setTreatmentsWithConfig(long treatmentsWithConfig) { this.treatmentsWithConfig = treatmentsWithConfig; } + public void setTreatmentsByFlagSet(long treatmentsByFlagSet) { + this.treatmentsByFlagSet = treatmentsByFlagSet; + } + + public long getTreatmentsByFlagSet() { + return treatmentsByFlagSet; + } + + public void setTreatmentsByFlagSets(long treatmentsByFlagSets) { + this.treatmentsByFlagSets = treatmentsByFlagSets; + } + + public long getTreatmentsByFlagSets() { + return treatmentsByFlagSets; + } + + public void setTreatmentsWithConfigByFlagSet(long treatmentsWithConfigByFlagSet) { + this.treatmentsWithConfigByFlagSet = treatmentsWithConfigByFlagSet; + } + + public long getTreatmentsWithConfigByFlagSet() { + return treatmentsWithConfigByFlagSet; + } + + public void setTreatmentsWithConfigByFlagSets(long treatmentsWithConfigByFlagSets) { + this.treatmentsWithConfigByFlagSets = treatmentsWithConfigByFlagSets; + } + + public long getTreatmentsWithConfigByFlagSets() { + return treatmentsWithConfigByFlagSets; + } + public long getTrack() { return track; } diff --git a/src/main/java/io/split/android/client/telemetry/model/MethodLatencies.java b/src/main/java/io/split/android/client/telemetry/model/MethodLatencies.java index df631118e..3c9d95391 100644 --- a/src/main/java/io/split/android/client/telemetry/model/MethodLatencies.java +++ b/src/main/java/io/split/android/client/telemetry/model/MethodLatencies.java @@ -18,6 +18,18 @@ public class MethodLatencies { @SerializedName("tcs") private List treatmentsWithConfig; + @SerializedName("tf") + private List treatmentsByFlagSet; + + @SerializedName("tfs") + private List treatmentsByFlagSets; + + @SerializedName("tfc") + private List treatmentsWithConfigByFlagSet; + + @SerializedName("tfcs") + private List treatmentsWithConfigByFlagSets; + @SerializedName("tr") private List track; @@ -53,6 +65,38 @@ public void setTreatmentsWithConfig(List treatmentsWithConfig) { this.treatmentsWithConfig = treatmentsWithConfig; } + public void setTreatmentsByFlagSet(List treatmentsByFlagSet) { + this.treatmentsByFlagSet = treatmentsByFlagSet; + } + + public List getTreatmentsByFlagSet() { + return treatmentsByFlagSet; + } + + public void setTreatmentsByFlagSets(List treatmentsByFlagSets) { + this.treatmentsByFlagSets = treatmentsByFlagSets; + } + + public List getTreatmentsByFlagSets() { + return treatmentsByFlagSets; + } + + public void setTreatmentsWithConfigByFlagSet(List treatmentsWithConfigByFlagSet) { + this.treatmentsWithConfigByFlagSet = treatmentsWithConfigByFlagSet; + } + + public List getTreatmentsWithConfigByFlagSet() { + return treatmentsWithConfigByFlagSet; + } + + public void setTreatmentsWithConfigByFlagSets(List treatmentsWithConfigByFlagSets) { + this.treatmentsWithConfigByFlagSets = treatmentsWithConfigByFlagSets; + } + + public List getTreatmentsWithConfigByFlagSets() { + return treatmentsWithConfigByFlagSets; + } + public List getTrack() { return track; } diff --git a/src/main/java/io/split/android/client/telemetry/storage/InMemoryTelemetryStorage.java b/src/main/java/io/split/android/client/telemetry/storage/InMemoryTelemetryStorage.java index 5f22b414c..8a237a741 100644 --- a/src/main/java/io/split/android/client/telemetry/storage/InMemoryTelemetryStorage.java +++ b/src/main/java/io/split/android/client/telemetry/storage/InMemoryTelemetryStorage.java @@ -73,6 +73,10 @@ public MethodExceptions popExceptions() { methodExceptions.setTreatmentWithConfig(methodExceptionsCounter.get(Method.TREATMENT_WITH_CONFIG).getAndSet(0L)); methodExceptions.setTreatmentsWithConfig(methodExceptionsCounter.get(Method.TREATMENTS_WITH_CONFIG).getAndSet(0L)); methodExceptions.setTrack(methodExceptionsCounter.get(Method.TRACK).getAndSet(0L)); + methodExceptions.setTreatmentsByFlagSet(methodExceptionsCounter.get(Method.TREATMENTS_BY_FLAG_SET).getAndSet(0L)); + methodExceptions.setTreatmentsByFlagSets(methodExceptionsCounter.get(Method.TREATMENTS_BY_FLAG_SETS).getAndSet(0L)); + methodExceptions.setTreatmentsWithConfigByFlagSet(methodExceptionsCounter.get(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET).getAndSet(0L)); + methodExceptions.setTreatmentsWithConfigByFlagSets(methodExceptionsCounter.get(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS).getAndSet(0L)); return methodExceptions; } @@ -86,6 +90,10 @@ public MethodLatencies popLatencies() { latencies.setTreatments(popLatencies(Method.TREATMENTS)); latencies.setTreatmentWithConfig(popLatencies(Method.TREATMENT_WITH_CONFIG)); latencies.setTreatmentsWithConfig(popLatencies(Method.TREATMENTS_WITH_CONFIG)); + latencies.setTreatmentsByFlagSet(popLatencies(Method.TREATMENTS_BY_FLAG_SET)); + latencies.setTreatmentsByFlagSets(popLatencies(Method.TREATMENTS_BY_FLAG_SETS)); + latencies.setTreatmentsWithConfigByFlagSet(popLatencies(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET)); + latencies.setTreatmentsWithConfigByFlagSets(popLatencies(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS)); latencies.setTrack(popLatencies(Method.TRACK)); return latencies; @@ -354,7 +362,7 @@ public void recordUpdatesFromSSE(UpdatesFromSSEEnum sseUpdate) { private void initializeProperties() { initializeMethodExceptionsCounter(); - initializeHttpLatenciesCounter(); + initializeMethodLatenciesCounter(); initializeFactoryCounters(); initializeImpressionsData(); initializeEventsData(); @@ -365,12 +373,16 @@ private void initializeProperties() { initializeUpdatesFromSSE(); } - private void initializeHttpLatenciesCounter() { + private void initializeMethodLatenciesCounter() { methodLatencies.put(Method.TREATMENT, new BinarySearchLatencyTracker()); methodLatencies.put(Method.TREATMENTS, new BinarySearchLatencyTracker()); methodLatencies.put(Method.TREATMENT_WITH_CONFIG, new BinarySearchLatencyTracker()); methodLatencies.put(Method.TREATMENTS_WITH_CONFIG, new BinarySearchLatencyTracker()); methodLatencies.put(Method.TRACK, new BinarySearchLatencyTracker()); + methodLatencies.put(Method.TREATMENTS_BY_FLAG_SET, new BinarySearchLatencyTracker()); + methodLatencies.put(Method.TREATMENTS_BY_FLAG_SETS, new BinarySearchLatencyTracker()); + methodLatencies.put(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET, new BinarySearchLatencyTracker()); + methodLatencies.put(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, new BinarySearchLatencyTracker()); } private void initializeMethodExceptionsCounter() { @@ -379,6 +391,10 @@ private void initializeMethodExceptionsCounter() { methodExceptionsCounter.put(Method.TREATMENT_WITH_CONFIG, new AtomicLong()); methodExceptionsCounter.put(Method.TREATMENTS_WITH_CONFIG, new AtomicLong()); methodExceptionsCounter.put(Method.TRACK, new AtomicLong()); + methodExceptionsCounter.put(Method.TREATMENTS_BY_FLAG_SET, new AtomicLong()); + methodExceptionsCounter.put(Method.TREATMENTS_BY_FLAG_SETS, new AtomicLong()); + methodExceptionsCounter.put(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET, new AtomicLong()); + methodExceptionsCounter.put(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, new AtomicLong()); } private void initializeFactoryCounters() { diff --git a/src/test/java/io/split/android/client/SplitClientImplFlagSetsTest.java b/src/test/java/io/split/android/client/SplitClientImplFlagSetsTest.java new file mode 100644 index 000000000..a3f621553 --- /dev/null +++ b/src/test/java/io/split/android/client/SplitClientImplFlagSetsTest.java @@ -0,0 +1,43 @@ +package io.split.android.client; + +import static org.mockito.Mockito.verify; + +import org.junit.Test; + +import java.util.Collections; +import java.util.Map; + +public class SplitClientImplFlagSetsTest extends SplitClientImplBaseTest { + + @Test + public void getTreatmentsByFlagSetDelegatesToTreatmentManager() { + Map attributes = Collections.singletonMap("key", "value"); + splitClient.getTreatmentsByFlagSet("set", attributes); + + verify(treatmentManager).getTreatmentsByFlagSet("set", attributes, false); + } + + @Test + public void getTreatmentsByFlagSetsDelegatesToTreatmentManager() { + Map attributes = Collections.singletonMap("key", "value"); + splitClient.getTreatmentsByFlagSets(Collections.singletonList("set"), attributes); + + verify(treatmentManager).getTreatmentsByFlagSets(Collections.singletonList("set"), attributes, false); + } + + @Test + public void getTreatmentsWithConfigByFlagSetDelegatesToTreatmentManager() { + Map attributes = Collections.singletonMap("key", "value"); + splitClient.getTreatmentsWithConfigByFlagSet("set", attributes); + + verify(treatmentManager).getTreatmentsWithConfigByFlagSet("set", attributes, false); + } + + @Test + public void getTreatmentsWithConfigByFlagSetsDelegatesToTreatmentManager() { + Map attributes = Collections.singletonMap("key", "value"); + splitClient.getTreatmentsWithConfigByFlagSets(Collections.singletonList("set"), attributes); + + verify(treatmentManager).getTreatmentsWithConfigByFlagSets(Collections.singletonList("set"), attributes, false); + } +} diff --git a/src/test/java/io/split/android/client/telemetry/TelemetryStatsBodySerializerTest.java b/src/test/java/io/split/android/client/telemetry/TelemetryStatsBodySerializerTest.java index a0dc2bdbe..b363cc2e4 100644 --- a/src/test/java/io/split/android/client/telemetry/TelemetryStatsBodySerializerTest.java +++ b/src/test/java/io/split/android/client/telemetry/TelemetryStatsBodySerializerTest.java @@ -30,7 +30,7 @@ public void setUp() { public void jsonIsBuiltAsExpected() { String serializedStats = telemetryStatsBodySerializer.serialize(getMockStats()); - assertEquals("{\"lS\":{\"sp\":1000,\"ms\":2000,\"im\":3000,\"ic\":4000,\"ev\":5000,\"te\":6000,\"to\":7000},\"mL\":{\"t\":[0,0,2,0],\"ts\":[0,0,3,0],\"tc\":[0,0,5,0],\"tcs\":[0,0,4,0],\"tr\":[0,0,1,0]},\"mE\":{\"t\":2,\"ts\":3,\"tc\":5,\"tcs\":4,\"tr\":1},\"hE\":{},\"hL\":{\"sp\":[0,0,3,0],\"ms\":[0,0,5,0],\"im\":[0,0,1,0],\"ic\":[0,0,4,0],\"ev\":[0,0,2,0],\"te\":[1,0,0,0],\"to\":[0,0,6,0]},\"tR\":4,\"aR\":5,\"iQ\":2,\"iDe\":5,\"iDr\":4,\"spC\":456,\"seC\":4,\"skC\":1,\"sL\":2000,\"eQ\":4,\"eD\":2,\"sE\":[{\"e\":0,\"t\":5000},{\"e\":20,\"d\":4,\"t\":2000}],\"t\":[\"tag1\",\"tag2\"],\"ufs\":{\"sp\":4,\"ms\":8}}", serializedStats); + assertEquals("{\"lS\":{\"sp\":1000,\"ms\":2000,\"im\":3000,\"ic\":4000,\"ev\":5000,\"te\":6000,\"to\":7000},\"mL\":{\"t\":[0,0,2,0],\"ts\":[0,0,3,0],\"tc\":[0,0,5,0],\"tcs\":[0,0,4,0],\"tf\":[1,0,0,0],\"tfs\":[2,0,0,0],\"tfc\":[3,0,0,0],\"tfcs\":[4,0,0,0],\"tr\":[0,0,1,0]},\"mE\":{\"t\":2,\"ts\":3,\"tc\":5,\"tcs\":4,\"tf\":10,\"tfs\":20,\"tfc\":30,\"tfcs\":40,\"tr\":1},\"hE\":{},\"hL\":{\"sp\":[0,0,3,0],\"ms\":[0,0,5,0],\"im\":[0,0,1,0],\"ic\":[0,0,4,0],\"ev\":[0,0,2,0],\"te\":[1,0,0,0],\"to\":[0,0,6,0]},\"tR\":4,\"aR\":5,\"iQ\":2,\"iDe\":5,\"iDr\":4,\"spC\":456,\"seC\":4,\"skC\":1,\"sL\":2000,\"eQ\":4,\"eD\":2,\"sE\":[{\"e\":0,\"t\":5000},{\"e\":20,\"d\":4,\"t\":2000}],\"t\":[\"tag1\",\"tag2\"],\"ufs\":{\"sp\":4,\"ms\":8}}", serializedStats); } private Stats getMockStats() { @@ -54,6 +54,10 @@ private Stats getMockStats() { methodLatencies.setTreatments(Arrays.asList(0L, 0L, 3L, 0L)); methodLatencies.setTreatmentsWithConfig(Arrays.asList(0L, 0L, 4L, 0L)); methodLatencies.setTreatmentWithConfig(Arrays.asList(0L, 0L, 5L, 0L)); + methodLatencies.setTreatmentsByFlagSet(Arrays.asList(1L, 0L, 0L, 0L)); + methodLatencies.setTreatmentsByFlagSets(Arrays.asList(2L, 0L, 0L, 0L)); + methodLatencies.setTreatmentsWithConfigByFlagSet(Arrays.asList(3L, 0L, 0L, 0L)); + methodLatencies.setTreatmentsWithConfigByFlagSets(Arrays.asList(4L, 0L, 0L, 0L)); MethodExceptions methodExceptions = new MethodExceptions(); methodExceptions.setTrack(1); @@ -61,6 +65,10 @@ private Stats getMockStats() { methodExceptions.setTreatments(3); methodExceptions.setTreatmentsWithConfig(4); methodExceptions.setTreatmentWithConfig(5); + methodExceptions.setTreatmentsByFlagSet(10); + methodExceptions.setTreatmentsByFlagSets(20); + methodExceptions.setTreatmentsWithConfigByFlagSet(30); + methodExceptions.setTreatmentsWithConfigByFlagSets(40); stats.setHttpLatencies(httpLatencies); stats.setAuthRejections(5); diff --git a/src/test/java/io/split/android/client/telemetry/storage/InMemoryTelemetryStorageTest.java b/src/test/java/io/split/android/client/telemetry/storage/InMemoryTelemetryStorageTest.java index 97c6adbe5..4227802af 100644 --- a/src/test/java/io/split/android/client/telemetry/storage/InMemoryTelemetryStorageTest.java +++ b/src/test/java/io/split/android/client/telemetry/storage/InMemoryTelemetryStorageTest.java @@ -50,6 +50,10 @@ public void popExceptionsReturnsCorrectlyBuiltMethodExceptions() { telemetryStorage.recordException(Method.TREATMENTS); telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG); telemetryStorage.recordException(Method.TREATMENT_WITH_CONFIG); + telemetryStorage.recordException(Method.TREATMENTS_BY_FLAG_SET); + telemetryStorage.recordException(Method.TREATMENTS_BY_FLAG_SETS); + telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET); + telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS); MethodExceptions methodExceptions = telemetryStorage.popExceptions(); @@ -58,6 +62,10 @@ public void popExceptionsReturnsCorrectlyBuiltMethodExceptions() { assertEquals(1, methodExceptions.getTreatments()); assertEquals(1, methodExceptions.getTreatmentsWithConfig()); assertEquals(1, methodExceptions.getTreatmentWithConfig()); + assertEquals(1, methodExceptions.getTreatmentsByFlagSet()); + assertEquals(1, methodExceptions.getTreatmentsByFlagSets()); + assertEquals(1, methodExceptions.getTreatmentsWithConfigByFlagSet()); + assertEquals(1, methodExceptions.getTreatmentsWithConfigByFlagSets()); } @Test @@ -68,6 +76,10 @@ public void popExceptionsEmptiesCounters() { telemetryStorage.recordException(Method.TREATMENTS); telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG); telemetryStorage.recordException(Method.TREATMENT_WITH_CONFIG); + telemetryStorage.recordException(Method.TREATMENTS_BY_FLAG_SET); + telemetryStorage.recordException(Method.TREATMENTS_BY_FLAG_SETS); + telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET); + telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS); telemetryStorage.popExceptions(); @@ -78,6 +90,10 @@ public void popExceptionsEmptiesCounters() { assertEquals(0, secondPop.getTreatments()); assertEquals(0, secondPop.getTreatmentsWithConfig()); assertEquals(0, secondPop.getTreatmentWithConfig()); + assertEquals(0, secondPop.getTreatmentsByFlagSet()); + assertEquals(0, secondPop.getTreatmentsByFlagSets()); + assertEquals(0, secondPop.getTreatmentsWithConfigByFlagSet()); + assertEquals(0, secondPop.getTreatmentsWithConfigByFlagSets()); } @Test @@ -89,6 +105,10 @@ public void popLatenciesReturnsCorrectlyBuiltObject() { telemetryStorage.recordLatency(Method.TREATMENTS, 200); telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG, 10); telemetryStorage.recordLatency(Method.TREATMENT_WITH_CONFIG, 2000); + telemetryStorage.recordLatency(Method.TREATMENTS_BY_FLAG_SET, 15); + telemetryStorage.recordLatency(Method.TREATMENTS_BY_FLAG_SETS, 14); + telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET, 15); + telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, 14); MethodLatencies methodLatencies = telemetryStorage.popLatencies(); @@ -97,12 +117,20 @@ public void popLatenciesReturnsCorrectlyBuiltObject() { assertFalse(methodLatencies.getTreatments().stream().allMatch(l -> l == 0)); assertFalse(methodLatencies.getTreatmentsWithConfig().stream().allMatch(l -> l == 0)); assertFalse(methodLatencies.getTreatmentWithConfig().stream().allMatch(l -> l == 0)); + assertFalse(methodLatencies.getTreatmentsByFlagSet().stream().allMatch(l -> l == 0)); + assertFalse(methodLatencies.getTreatmentsByFlagSets().stream().allMatch(l -> l == 0)); + assertFalse(methodLatencies.getTreatmentsWithConfigByFlagSet().stream().allMatch(l -> l == 0)); + assertFalse(methodLatencies.getTreatmentsWithConfigByFlagSets().stream().allMatch(l -> l == 0)); assertEquals(1, (long) methodLatencies.getTreatment().get(15)); assertEquals(1, (long) methodLatencies.getTreatments().get(14)); assertEquals(1, (long) methodLatencies.getTreatmentWithConfig().get(19)); assertEquals(1, (long) methodLatencies.getTreatmentsWithConfig().get(6)); assertEquals(1, (long) methodLatencies.getTrack().get(14)); + assertEquals(1, (long) methodLatencies.getTreatmentsByFlagSet().get(7)); + assertEquals(1, (long) methodLatencies.getTreatmentsByFlagSets().get(7)); + assertEquals(1, (long) methodLatencies.getTreatmentsWithConfigByFlagSet().get(7)); + assertEquals(1, (long) methodLatencies.getTreatmentsWithConfigByFlagSets().get(7)); } @Test @@ -113,6 +141,10 @@ public void secondLatenciesPopHasArraysSetIn0() { telemetryStorage.recordLatency(Method.TREATMENTS, 200); telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG, 10); telemetryStorage.recordLatency(Method.TREATMENT_WITH_CONFIG, 2000); + telemetryStorage.recordLatency(Method.TREATMENTS_BY_FLAG_SET, 15); + telemetryStorage.recordLatency(Method.TREATMENTS_BY_FLAG_SETS, 14); + telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET, 15); + telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, 14); telemetryStorage.popLatencies(); @@ -123,6 +155,10 @@ public void secondLatenciesPopHasArraysSetIn0() { assertTrue(methodLatencies.getTreatments().stream().allMatch(l -> l == 0)); assertTrue(methodLatencies.getTreatmentsWithConfig().stream().allMatch(l -> l == 0)); assertTrue(methodLatencies.getTreatmentWithConfig().stream().allMatch(l -> l == 0)); + assertTrue(methodLatencies.getTreatmentsByFlagSet().stream().allMatch(l -> l == 0)); + assertTrue(methodLatencies.getTreatmentsByFlagSets().stream().allMatch(l -> l == 0)); + assertTrue(methodLatencies.getTreatmentsWithConfigByFlagSet().stream().allMatch(l -> l == 0)); + assertTrue(methodLatencies.getTreatmentsWithConfigByFlagSets().stream().allMatch(l -> l == 0)); } @Test From b6592e605c85a1a5f2eb6b216587400a7e864dfb Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Tue, 5 Sep 2023 17:16:42 -0300 Subject: [PATCH 2/3] More treatment manager tests; --- .../TreatmentManagerWithFlagSetsTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java b/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java index 90539b17b..42281896f 100644 --- a/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java +++ b/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java @@ -439,4 +439,40 @@ public void getTreatmentsWithConfigByFlagSetsRecordsTelemetry() { verify(mTelemetryStorageProducer).recordLatency(eq(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS), anyLong()); } + + @Test + public void getTreatmentsByFlagSetExceptionIsRecordedInTelemetry() { + when(mSplitsStorage.getNamesByFlagSets(any())).thenThrow(new RuntimeException("test")); + + mTreatmentManager.getTreatmentsByFlagSet("set_1", null, false); + + verify(mTelemetryStorageProducer).recordException(eq(Method.TREATMENTS_BY_FLAG_SET)); + } + + @Test + public void getTreatmentsByFlagSetsExceptionIsRecordedInTelemetry() { + when(mSplitsStorage.getNamesByFlagSets(any())).thenThrow(new RuntimeException("test")); + + mTreatmentManager.getTreatmentsByFlagSets(Arrays.asList("set_1", "set_2"), null, false); + + verify(mTelemetryStorageProducer).recordException(eq(Method.TREATMENTS_BY_FLAG_SETS)); + } + + @Test + public void getTreatmentsWithConfigByFlagSetExceptionIsRecordedInTelemetry() { + when(mSplitsStorage.getNamesByFlagSets(any())).thenThrow(new RuntimeException("test")); + + mTreatmentManager.getTreatmentsWithConfigByFlagSet("set_1", null, false); + + verify(mTelemetryStorageProducer).recordException(eq(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET)); + } + + @Test + public void getTreatmentsWithConfigByFlagSetsExceptionIsRecordedInTelemetry() { + when(mSplitsStorage.getNamesByFlagSets(any())).thenThrow(new RuntimeException("test")); + + mTreatmentManager.getTreatmentsWithConfigByFlagSets(Arrays.asList("set_1", "set_2"), null, false); + + verify(mTelemetryStorageProducer).recordException(eq(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS)); + } } From a41f7db1fc16e387573f72f2d21e798d7719f7b7 Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Tue, 5 Sep 2023 17:36:20 -0300 Subject: [PATCH 3/3] Fix json key --- .../android/client/telemetry/model/MethodExceptions.java | 4 ++-- .../split/android/client/telemetry/model/MethodLatencies.java | 4 ++-- .../client/telemetry/TelemetryStatsBodySerializerTest.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/split/android/client/telemetry/model/MethodExceptions.java b/src/main/java/io/split/android/client/telemetry/model/MethodExceptions.java index ff87dedab..0a936f565 100644 --- a/src/main/java/io/split/android/client/telemetry/model/MethodExceptions.java +++ b/src/main/java/io/split/android/client/telemetry/model/MethodExceptions.java @@ -22,10 +22,10 @@ public class MethodExceptions { @SerializedName("tfs") private long treatmentsByFlagSets; - @SerializedName("tfc") + @SerializedName("tcf") private long treatmentsWithConfigByFlagSet; - @SerializedName("tfcs") + @SerializedName("tcfs") private long treatmentsWithConfigByFlagSets; @SerializedName("tr") diff --git a/src/main/java/io/split/android/client/telemetry/model/MethodLatencies.java b/src/main/java/io/split/android/client/telemetry/model/MethodLatencies.java index 3c9d95391..15cc73fe8 100644 --- a/src/main/java/io/split/android/client/telemetry/model/MethodLatencies.java +++ b/src/main/java/io/split/android/client/telemetry/model/MethodLatencies.java @@ -24,10 +24,10 @@ public class MethodLatencies { @SerializedName("tfs") private List treatmentsByFlagSets; - @SerializedName("tfc") + @SerializedName("tcf") private List treatmentsWithConfigByFlagSet; - @SerializedName("tfcs") + @SerializedName("tcfs") private List treatmentsWithConfigByFlagSets; @SerializedName("tr") diff --git a/src/test/java/io/split/android/client/telemetry/TelemetryStatsBodySerializerTest.java b/src/test/java/io/split/android/client/telemetry/TelemetryStatsBodySerializerTest.java index b363cc2e4..1a6ec1cd4 100644 --- a/src/test/java/io/split/android/client/telemetry/TelemetryStatsBodySerializerTest.java +++ b/src/test/java/io/split/android/client/telemetry/TelemetryStatsBodySerializerTest.java @@ -30,7 +30,7 @@ public void setUp() { public void jsonIsBuiltAsExpected() { String serializedStats = telemetryStatsBodySerializer.serialize(getMockStats()); - assertEquals("{\"lS\":{\"sp\":1000,\"ms\":2000,\"im\":3000,\"ic\":4000,\"ev\":5000,\"te\":6000,\"to\":7000},\"mL\":{\"t\":[0,0,2,0],\"ts\":[0,0,3,0],\"tc\":[0,0,5,0],\"tcs\":[0,0,4,0],\"tf\":[1,0,0,0],\"tfs\":[2,0,0,0],\"tfc\":[3,0,0,0],\"tfcs\":[4,0,0,0],\"tr\":[0,0,1,0]},\"mE\":{\"t\":2,\"ts\":3,\"tc\":5,\"tcs\":4,\"tf\":10,\"tfs\":20,\"tfc\":30,\"tfcs\":40,\"tr\":1},\"hE\":{},\"hL\":{\"sp\":[0,0,3,0],\"ms\":[0,0,5,0],\"im\":[0,0,1,0],\"ic\":[0,0,4,0],\"ev\":[0,0,2,0],\"te\":[1,0,0,0],\"to\":[0,0,6,0]},\"tR\":4,\"aR\":5,\"iQ\":2,\"iDe\":5,\"iDr\":4,\"spC\":456,\"seC\":4,\"skC\":1,\"sL\":2000,\"eQ\":4,\"eD\":2,\"sE\":[{\"e\":0,\"t\":5000},{\"e\":20,\"d\":4,\"t\":2000}],\"t\":[\"tag1\",\"tag2\"],\"ufs\":{\"sp\":4,\"ms\":8}}", serializedStats); + assertEquals("{\"lS\":{\"sp\":1000,\"ms\":2000,\"im\":3000,\"ic\":4000,\"ev\":5000,\"te\":6000,\"to\":7000},\"mL\":{\"t\":[0,0,2,0],\"ts\":[0,0,3,0],\"tc\":[0,0,5,0],\"tcs\":[0,0,4,0],\"tf\":[1,0,0,0],\"tfs\":[2,0,0,0],\"tcf\":[3,0,0,0],\"tcfs\":[4,0,0,0],\"tr\":[0,0,1,0]},\"mE\":{\"t\":2,\"ts\":3,\"tc\":5,\"tcs\":4,\"tf\":10,\"tfs\":20,\"tcf\":30,\"tcfs\":40,\"tr\":1},\"hE\":{},\"hL\":{\"sp\":[0,0,3,0],\"ms\":[0,0,5,0],\"im\":[0,0,1,0],\"ic\":[0,0,4,0],\"ev\":[0,0,2,0],\"te\":[1,0,0,0],\"to\":[0,0,6,0]},\"tR\":4,\"aR\":5,\"iQ\":2,\"iDe\":5,\"iDr\":4,\"spC\":456,\"seC\":4,\"skC\":1,\"sL\":2000,\"eQ\":4,\"eD\":2,\"sE\":[{\"e\":0,\"t\":5000},{\"e\":20,\"d\":4,\"t\":2000}],\"t\":[\"tag1\",\"tag2\"],\"ufs\":{\"sp\":4,\"ms\":8}}", serializedStats); } private Stats getMockStats() {