Skip to content

Commit

Permalink
enabled posting impressionCount in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilal Al committed Dec 14, 2024
1 parent 249ab03 commit ccea626
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 30 deletions.
3 changes: 1 addition & 2 deletions client/src/main/java/io/split/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,10 @@ private ImpressionsManagerImpl buildImpressionsManager(SplitClientConfig config,
.collect(Collectors.toCollection(() -> impressionListeners));
}
ProcessImpressionStrategy processImpressionStrategy = null;
ImpressionCounter counter = null;
ImpressionCounter counter = new ImpressionCounter();
ImpressionListener listener = !impressionListeners.isEmpty()
? new ImpressionListener.FederatedImpressionListener(impressionListeners)
: null;
counter = new ImpressionCounter();
ProcessImpressionNone processImpressionNone = new ProcessImpressionNone(listener != null, _uniqueKeysTracker, counter);

switch (config.impressionsMode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ public void postImpressionsBulk(List<TestImpressions> impressions) {
@Override
public void postCounters(HashMap<ImpressionCounter.Key, Integer> raw) {
long initTime = System.currentTimeMillis();
if (_mode.equals(ImpressionsManager.Mode.DEBUG)) {
_logger.warn("Attempted to submit counters in impressions debugging mode. Ignoring");
return;
}

try {

Map<String, List<String>> additionalHeaders = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public void start(){
break;
case DEBUG:
_scheduler.scheduleAtFixedRate(this::sendImpressions, BULK_INITIAL_DELAY_SECONDS, _impressionsRefreshRate, TimeUnit.SECONDS);
_scheduler.scheduleAtFixedRate(this::sendImpressionCounters, COUNT_INITIAL_DELAY_SECONDS, COUNT_REFRESH_RATE_SECONDS,
TimeUnit.SECONDS);
break;
case NONE:
_scheduler.scheduleAtFixedRate(this::sendImpressionCounters, COUNT_INITIAL_DELAY_SECONDS, COUNT_REFRESH_RATE_SECONDS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ public MockResponse dispatch(RecordedRequest request) {
Assert.assertEquals("off", client.getTreatment("user3", "impression_toggle_off", null));
Thread.sleep(1000);
client.destroy();
boolean check1 = false, check2 = false;
boolean check1 = false, check2 = false, check3 = false;
for (int i=0; i < allRequests.size(); i++ ) {
if (allRequests.get(i).getPath().equals("/api/testImpressions/bulk") ) {
check1 = true;
Expand All @@ -923,10 +923,18 @@ public MockResponse dispatch(RecordedRequest request) {
Assert.assertFalse(body.contains("impression_toggle_on"));
Assert.assertTrue(body.contains("impression_toggle_off"));
}
if (allRequests.get(i).getPath().equals("/api/testImpressions/count")) {
check3 = true;
String body = allRequests.get(i).getBody().readUtf8();
Assert.assertFalse(body.contains("without_impression_toggle"));
Assert.assertFalse(body.contains("impression_toggle_on"));
Assert.assertTrue(body.contains("impression_toggle_off"));
}
}
server.shutdown();
Assert.assertTrue(check1);
Assert.assertTrue(check2);
Assert.assertTrue(check3);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,6 @@ public void testImpressionCountsEndpointOptimized() throws URISyntaxException, I
new ImpressionCount.CountPerFeature("test2", 0, 5)));
}

@Test
public void testImpressionCountsEndpointDebug() throws URISyntaxException, IOException, IllegalAccessException,
NoSuchMethodException, InvocationTargetException {
URI rootTarget = URI.create("https://kubernetesturl.com/split");

// Setup response mock
CloseableHttpClient httpClient = TestHelper.mockHttpClient("", HttpStatus.SC_OK);
SplitHttpClient splitHtpClient = SplitHttpClientImpl.create(httpClient, new RequestDecorator(null), "qwerty",
metadata());

// Send counters
HttpImpressionsSender sender = HttpImpressionsSender.create(splitHtpClient, rootTarget,
ImpressionsManager.Mode.DEBUG, TELEMETRY_STORAGE);
HashMap<ImpressionCounter.Key, Integer> toSend = new HashMap<>();
toSend.put(new ImpressionCounter.Key("test1", 0), 4);
toSend.put(new ImpressionCounter.Key("test2", 0), 5);
sender.postCounters(toSend);

// Assert that the HTTP client was not called
verify(httpClient, Mockito.never()).execute(Mockito.any());
}

@Test
public void testImpressionBulksEndpoint() throws URISyntaxException, IOException, IllegalAccessException,
NoSuchMethodException, InvocationTargetException {
Expand Down

0 comments on commit ccea626

Please sign in to comment.