Skip to content

Commit ccea626

Browse files
author
Bilal Al
committed
enabled posting impressionCount in debug mode
1 parent 249ab03 commit ccea626

File tree

5 files changed

+12
-30
lines changed

5 files changed

+12
-30
lines changed

client/src/main/java/io/split/client/SplitFactoryImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,10 @@ private ImpressionsManagerImpl buildImpressionsManager(SplitClientConfig config,
630630
.collect(Collectors.toCollection(() -> impressionListeners));
631631
}
632632
ProcessImpressionStrategy processImpressionStrategy = null;
633-
ImpressionCounter counter = null;
633+
ImpressionCounter counter = new ImpressionCounter();
634634
ImpressionListener listener = !impressionListeners.isEmpty()
635635
? new ImpressionListener.FederatedImpressionListener(impressionListeners)
636636
: null;
637-
counter = new ImpressionCounter();
638637
ProcessImpressionNone processImpressionNone = new ProcessImpressionNone(listener != null, _uniqueKeysTracker, counter);
639638

640639
switch (config.impressionsMode()) {

client/src/main/java/io/split/client/impressions/HttpImpressionsSender.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ public void postImpressionsBulk(List<TestImpressions> impressions) {
9191
@Override
9292
public void postCounters(HashMap<ImpressionCounter.Key, Integer> raw) {
9393
long initTime = System.currentTimeMillis();
94-
if (_mode.equals(ImpressionsManager.Mode.DEBUG)) {
95-
_logger.warn("Attempted to submit counters in impressions debugging mode. Ignoring");
96-
return;
97-
}
98-
9994
try {
10095

10196
Map<String, List<String>> additionalHeaders = new HashMap<>();

client/src/main/java/io/split/client/impressions/ImpressionsManagerImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public void start(){
112112
break;
113113
case DEBUG:
114114
_scheduler.scheduleAtFixedRate(this::sendImpressions, BULK_INITIAL_DELAY_SECONDS, _impressionsRefreshRate, TimeUnit.SECONDS);
115+
_scheduler.scheduleAtFixedRate(this::sendImpressionCounters, COUNT_INITIAL_DELAY_SECONDS, COUNT_REFRESH_RATE_SECONDS,
116+
TimeUnit.SECONDS);
115117
break;
116118
case NONE:
117119
_scheduler.scheduleAtFixedRate(this::sendImpressionCounters, COUNT_INITIAL_DELAY_SECONDS, COUNT_REFRESH_RATE_SECONDS,

client/src/test/java/io/split/client/SplitClientIntegrationTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ public MockResponse dispatch(RecordedRequest request) {
907907
Assert.assertEquals("off", client.getTreatment("user3", "impression_toggle_off", null));
908908
Thread.sleep(1000);
909909
client.destroy();
910-
boolean check1 = false, check2 = false;
910+
boolean check1 = false, check2 = false, check3 = false;
911911
for (int i=0; i < allRequests.size(); i++ ) {
912912
if (allRequests.get(i).getPath().equals("/api/testImpressions/bulk") ) {
913913
check1 = true;
@@ -923,10 +923,18 @@ public MockResponse dispatch(RecordedRequest request) {
923923
Assert.assertFalse(body.contains("impression_toggle_on"));
924924
Assert.assertTrue(body.contains("impression_toggle_off"));
925925
}
926+
if (allRequests.get(i).getPath().equals("/api/testImpressions/count")) {
927+
check3 = true;
928+
String body = allRequests.get(i).getBody().readUtf8();
929+
Assert.assertFalse(body.contains("without_impression_toggle"));
930+
Assert.assertFalse(body.contains("impression_toggle_on"));
931+
Assert.assertTrue(body.contains("impression_toggle_off"));
932+
}
926933
}
927934
server.shutdown();
928935
Assert.assertTrue(check1);
929936
Assert.assertTrue(check2);
937+
Assert.assertTrue(check3);
930938
}
931939

932940
@Test

client/src/test/java/io/split/client/impressions/HttpImpressionsSenderTest.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,28 +125,6 @@ public void testImpressionCountsEndpointOptimized() throws URISyntaxException, I
125125
new ImpressionCount.CountPerFeature("test2", 0, 5)));
126126
}
127127

128-
@Test
129-
public void testImpressionCountsEndpointDebug() throws URISyntaxException, IOException, IllegalAccessException,
130-
NoSuchMethodException, InvocationTargetException {
131-
URI rootTarget = URI.create("https://kubernetesturl.com/split");
132-
133-
// Setup response mock
134-
CloseableHttpClient httpClient = TestHelper.mockHttpClient("", HttpStatus.SC_OK);
135-
SplitHttpClient splitHtpClient = SplitHttpClientImpl.create(httpClient, new RequestDecorator(null), "qwerty",
136-
metadata());
137-
138-
// Send counters
139-
HttpImpressionsSender sender = HttpImpressionsSender.create(splitHtpClient, rootTarget,
140-
ImpressionsManager.Mode.DEBUG, TELEMETRY_STORAGE);
141-
HashMap<ImpressionCounter.Key, Integer> toSend = new HashMap<>();
142-
toSend.put(new ImpressionCounter.Key("test1", 0), 4);
143-
toSend.put(new ImpressionCounter.Key("test2", 0), 5);
144-
sender.postCounters(toSend);
145-
146-
// Assert that the HTTP client was not called
147-
verify(httpClient, Mockito.never()).execute(Mockito.any());
148-
}
149-
150128
@Test
151129
public void testImpressionBulksEndpoint() throws URISyntaxException, IOException, IllegalAccessException,
152130
NoSuchMethodException, InvocationTargetException {

0 commit comments

Comments
 (0)