From ccea626d0319ba3c78eb24cf5dd0775d5586f036 Mon Sep 17 00:00:00 2001 From: Bilal Al Date: Fri, 13 Dec 2024 21:30:53 -0800 Subject: [PATCH] enabled posting impressionCount in debug mode --- .../io/split/client/SplitFactoryImpl.java | 3 +-- .../impressions/HttpImpressionsSender.java | 5 ----- .../impressions/ImpressionsManagerImpl.java | 2 ++ .../client/SplitClientIntegrationTest.java | 10 ++++++++- .../HttpImpressionsSenderTest.java | 22 ------------------- 5 files changed, 12 insertions(+), 30 deletions(-) diff --git a/client/src/main/java/io/split/client/SplitFactoryImpl.java b/client/src/main/java/io/split/client/SplitFactoryImpl.java index 2791d457..848b50e8 100644 --- a/client/src/main/java/io/split/client/SplitFactoryImpl.java +++ b/client/src/main/java/io/split/client/SplitFactoryImpl.java @@ -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()) { diff --git a/client/src/main/java/io/split/client/impressions/HttpImpressionsSender.java b/client/src/main/java/io/split/client/impressions/HttpImpressionsSender.java index 35c0f57f..7c346a90 100644 --- a/client/src/main/java/io/split/client/impressions/HttpImpressionsSender.java +++ b/client/src/main/java/io/split/client/impressions/HttpImpressionsSender.java @@ -91,11 +91,6 @@ public void postImpressionsBulk(List impressions) { @Override public void postCounters(HashMap 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> additionalHeaders = new HashMap<>(); diff --git a/client/src/main/java/io/split/client/impressions/ImpressionsManagerImpl.java b/client/src/main/java/io/split/client/impressions/ImpressionsManagerImpl.java index 95ed5694..1602a9be 100644 --- a/client/src/main/java/io/split/client/impressions/ImpressionsManagerImpl.java +++ b/client/src/main/java/io/split/client/impressions/ImpressionsManagerImpl.java @@ -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, diff --git a/client/src/test/java/io/split/client/SplitClientIntegrationTest.java b/client/src/test/java/io/split/client/SplitClientIntegrationTest.java index 1f7078e8..f44ac534 100644 --- a/client/src/test/java/io/split/client/SplitClientIntegrationTest.java +++ b/client/src/test/java/io/split/client/SplitClientIntegrationTest.java @@ -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; @@ -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 diff --git a/client/src/test/java/io/split/client/impressions/HttpImpressionsSenderTest.java b/client/src/test/java/io/split/client/impressions/HttpImpressionsSenderTest.java index 18a4141c..604f7a90 100644 --- a/client/src/test/java/io/split/client/impressions/HttpImpressionsSenderTest.java +++ b/client/src/test/java/io/split/client/impressions/HttpImpressionsSenderTest.java @@ -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 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 {