Skip to content

Commit af4eea5

Browse files
authored
feat: update to latest common for new methods, major bump (#104)
* chore: use latest common * breaking change: Removed EppoClient.stopPolling * major bump to v5.0.0-SNAPSHOT * move polling to base client * add a test for getConfiguration
1 parent 5963d77 commit af4eea5

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ java {
1111
}
1212

1313
group = 'cloud.eppo'
14-
version = '4.0.1-SNAPSHOT'
14+
version = '5.0.0-SNAPSHOT'
1515
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
1616

1717
import org.apache.tools.ant.filters.ReplaceTokens
@@ -30,7 +30,7 @@ repositories {
3030
}
3131

3232
dependencies {
33-
api 'cloud.eppo:sdk-common-jvm:3.6.0'
33+
api 'cloud.eppo:sdk-common-jvm:3.8.0'
3434

3535
implementation 'com.github.zafarkhaja:java-semver:0.10.2'
3636
implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.2'

src/main/java/cloud/eppo/EppoClient.java

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import cloud.eppo.cache.LRUInMemoryAssignmentCache;
66
import cloud.eppo.logging.AssignmentLogger;
77
import cloud.eppo.logging.BanditLogger;
8-
import java.util.Timer;
98
import java.util.concurrent.TimeUnit;
109
import org.jetbrains.annotations.Nullable;
1110
import org.slf4j.Logger;
@@ -26,7 +25,6 @@ public class EppoClient extends BaseEppoClient {
2625
private static final long DEFAULT_JITTER_INTERVAL_RATIO = 10;
2726

2827
private static EppoClient instance;
29-
private static Timer pollTimer;
3028

3129
public static EppoClient getInstance() {
3230
if (instance == null) {
@@ -62,13 +60,6 @@ private EppoClient(
6260
banditAssignmentCache);
6361
}
6462

65-
/** Stops the client from polling Eppo for updated flag and bandit configurations */
66-
public static void stopPolling() {
67-
if (pollTimer != null) {
68-
pollTimer.cancel();
69-
}
70-
}
71-
7263
/** Builder pattern to initialize the EppoClient singleton */
7364
public static class Builder {
7465
private String apiKey;
@@ -163,6 +154,8 @@ public EppoClient buildAndInit() {
163154
String sdkVersion = appDetails.getVersion();
164155

165156
if (instance != null) {
157+
// Stop any active polling.
158+
instance.stopPolling();
166159
if (forceReinitialize) {
167160
log.warn(
168161
"Eppo SDK is already initialized, reinitializing since forceReinitialize is true");
@@ -185,22 +178,13 @@ public EppoClient buildAndInit() {
185178
assignmentCache,
186179
banditAssignmentCache);
187180

188-
// Stop any active polling
189-
stopPolling();
190-
191-
// Set up polling for experiment configurations
192-
pollTimer = new Timer(true);
193-
FetchConfigurationsTask fetchConfigurationsTask =
194-
new FetchConfigurationsTask(
195-
() -> instance.loadConfiguration(),
196-
pollTimer,
197-
pollingIntervalMs,
198-
pollingIntervalMs / DEFAULT_JITTER_INTERVAL_RATIO);
199-
200-
// Kick off the first fetch
201-
// Graceful mode is implicit here because `FetchConfigurationsTask` catches and logs errors
202-
// without rethrowing.
203-
fetchConfigurationsTask.run();
181+
// Fetch first configuration
182+
instance.loadConfiguration();
183+
184+
// start polling, if enabled.
185+
if (pollingIntervalMs > 0) {
186+
instance.startPolling(pollingIntervalMs, pollingIntervalMs / DEFAULT_JITTER_INTERVAL_RATIO);
187+
}
204188

205189
return instance;
206190
}

src/test/java/cloud/eppo/EppoClientTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
import cloud.eppo.api.Attributes;
1212
import cloud.eppo.api.BanditActions;
1313
import cloud.eppo.api.BanditResult;
14+
import cloud.eppo.api.Configuration;
1415
import cloud.eppo.helpers.AssignmentTestCase;
1516
import cloud.eppo.helpers.BanditTestCase;
1617
import cloud.eppo.helpers.TestUtils;
1718
import cloud.eppo.logging.Assignment;
1819
import cloud.eppo.logging.AssignmentLogger;
1920
import cloud.eppo.logging.BanditAssignment;
2021
import cloud.eppo.logging.BanditLogger;
22+
import cloud.eppo.ufc.dto.VariationType;
2123
import com.github.tomakehurst.wiremock.WireMockServer;
2224
import com.github.tomakehurst.wiremock.client.WireMock;
2325
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
@@ -91,7 +93,11 @@ private static String readConfig(String jsonToReturnFilePath) {
9193
@AfterEach
9294
public void cleanUp() {
9395
TestUtils.setBaseClientHttpClientOverrideField(null);
94-
EppoClient.stopPolling();
96+
try {
97+
EppoClient.getInstance().stopPolling();
98+
} catch (IllegalStateException ex) {
99+
// pass: Indicates that the singleton Eppo Client has not yet been initialized.
100+
}
95101
}
96102

97103
@AfterAll
@@ -232,7 +238,7 @@ public void testPolling() {
232238
// Now, the method should have been called twice
233239
verify(httpClientSpy, times(2)).get(anyString());
234240

235-
EppoClient.stopPolling();
241+
EppoClient.getInstance().stopPolling();
236242
sleepUninterruptedly(25);
237243

238244
// No more calls since stopped
@@ -257,6 +263,15 @@ public void testClientMakesDefaultAssignmentsAfterFailingToInitialize() {
257263
}
258264
}
259265

266+
@Test
267+
public void testGetConfiguration() {
268+
EppoClient eppoClient = initClient(DUMMY_FLAG_API_KEY);
269+
Configuration configuration = eppoClient.getConfiguration();
270+
assertNotNull(configuration);
271+
assertNotNull(configuration.getFlag("numeric_flag"));
272+
assertEquals(VariationType.NUMERIC, configuration.getFlagType("numeric_flag"));
273+
}
274+
260275
public static void mockHttpError() {
261276
// Create a mock instance of EppoHttpClient
262277
EppoHttpClient mockHttpClient = mock(EppoHttpClient.class);

0 commit comments

Comments
 (0)