8000 [FSSDK-8739] refact: Implements a warning log for polling interval le… · optimizely/java-sdk@65b3f43 · GitHub
[go: up one dir, main page]

Skip to content

Commit 65b3f43

Browse files
authored
[FSSDK-8739] refact: Implements a warning log for polling interval less than 30s (#528)
* Added warning upon setting polling time period below 30 ms * Updated test and changed expecting time to lower than 30 seconds
1 parent f5528d5 commit 65b3f43

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

core-api/src/main/java/com/optimizely/ab/config/PollingProjectConfigManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ public PollingProjectConfigManager(long period, TimeUnit timeUnit, long blocking
7575
this.blockingTimeoutPeriod = blockingTimeoutPeriod;
7676
this.blockingTimeoutUnit = blockingTimeoutUnit;
7777
this.notificationCenter = notificationCenter;
78-
78+
if (TimeUnit.SECONDS.convert(period, this.timeUnit) < 30) {
79+
logger.warn("Polling intervals below 30 seconds are not recommended.");
80+
}
7981
final ThreadFactory threadFactory = Executors.defaultThreadFactory();
8082
this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(runnable -> {
8183
Thread thread = threadFactory.newThread(runnable);

core-api/src/test/java/com/optimizely/ab/config/PollingProjectConfigManagerTest.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
*/
1717
package com.optimizely.ab.config;
1818

19+
import ch.qos.logback.classic.Level;
20+
import com.optimizely.ab.internal.LogbackVerifier;
1921
import com.optimizely.ab.internal.NotificationRegistry;
2022
import com.optimizely.ab.notification.NotificationCenter;
2123
import com.optimizely.ab.notification.UpdateConfigNotification;
22-
import org.junit.After;
23-
import org.junit.Before;
24-
import org.junit.Ignore;
25-
import org.junit.Test;
24+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
25+
import org.junit.*;
26+
import org.junit.rules.ExpectedException;
27+
import org.junit.rules.RuleChain;
2628

2729
import java.util.concurrent.CompletableFuture;
2830
import java.util.concurrent.CountDownLatch;
@@ -41,6 +43,13 @@ public class PollingProjectConfigManagerTest {
4143
private static final TimeUnit POLLING_UNIT = TimeUnit.MILLISECONDS;
4244
private static final int PROJECT_CONFIG_DELAY = 100;
4345

46+
public ExpectedException thrown = ExpectedException.none();
47+
public LogbackVerifier logbackVerifier = new LogbackVerifier();
48+
49+
@Rule
50+
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
51+
public RuleChain ruleChain = RuleChain.outerRule(thrown)
52+
.around(logbackVerifier);
4453
private TestProjectConfigManager testProjectConfigManager;
4554
private ProjectConfig projectConfig;
4655

@@ -228,6 +237,13 @@ public void testUpdateConfigNotificationGetsTriggered() throws InterruptedExcept
228237
assertTrue(countDownLatch.await(500, TimeUnit.MILLISECONDS));
229238
}
230239

240+
@Test
241+
public void testSettingUpLowerPollingPeriodResultsInWarning() throws InterruptedException {
242+
long pollingPeriod = 29;
243+
new TestProjectConfigManager(projectConfig, pollingPeriod, TimeUnit.SECONDS, pollingPeriod / 2, TimeUnit.SECONDS, new NotificationCenter());
244+
logbackVerifier.expectMessage(Level.WARN, "Polling intervals below 30 seconds are not recommended.");
245+
}
246+
231247
@Test
232248
public void testUpdateConfigNotificationDoesNotResultInDeadlock() throws Exception {
233249
NotificationCenter notificationCenter = new NotificationCenter();
@@ -257,7 +273,11 @@ private TestProjectConfigManager(ProjectConfig projectConfig) {
257273
}
258274

259275
private TestProjectConfigManager(ProjectConfig projectConfig, long blockPeriod, NotificationCenter notificationCenter) {
260-
super(POLLING_PERIOD, POLLING_UNIT, blockPeriod, POLLING_UNIT, notificationCenter);
276+
this(projectConfig, POLLING_PERIOD, POLLING_UNIT, blockPeriod, POLLING_UNIT, notificationCenter);
277+
}
278+
279+
private TestProjectConfigManager(ProjectConfig projectConfig, long pollingPeriod, TimeUnit pollingUnit, long blockPeriod, TimeUnit blockingUnit, NotificationCenter notificationCenter) {
280+
super(pollingPeriod, pollingUnit, blockPeriod, blockingUnit, notificationCenter);
261281
this.projectConfig = projectConfig;
262282
}
263283

0 commit comments

Comments
 (0)
0