Skip to content

Commit 6004c70

Browse files
committed
don't block on init
1 parent e1560d6 commit 6004c70

File tree

3 files changed

+7
-51
lines changed

3 files changed

+7
-51
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,10 @@ public EppoClient buildAndInit() {
197197
pollingIntervalMs,
198198
pollingIntervalMs / DEFAULT_JITTER_INTERVAL_RATIO);
199199

200-
fetchConfigurationsTask.scheduleNext();
201-
202-
// Kick off the first fetch, respecting graceful mode.
203-
try {
204-
instance.loadConfiguration();
205-
} catch (RuntimeException e) {
206-
log.error("Encountered Exception while loading configuration", e);
207-
if (!isGracefulMode) {
208-
throw e;
209-
}
210-
}
200+
// Kick off the first fetch
201+
// Graceful mode is implicit here because `FetchConfigurationsTask` catches and logs errors
202+
// without rethrowing.
203+
fetchConfigurationsTask.run();
211204

212205
return instance;
213206
}

src/main/java/cloud/eppo/FetchConfigurationsTask.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public void run() {
2828
} catch (Exception e) {
2929
log.error("[Eppo SDK] Error fetching experiment configuration", e);
3030
}
31-
scheduleNext();
32-
}
33-
34-
public void scheduleNext() {
3531

3632
long delay = this.intervalInMillis - (long) (Math.random() * this.jitterInMillis);
3733
FetchConfigurationsTask nextTask =

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

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,8 @@ public void testPolling() {
239239
verify(httpClientSpy, times(2)).get(anyString());
240240
}
241241

242-
@Test
243-
public void testGracefulInitializationFailure() {
244-
// Set up bad HTTP response
245-
mockHttpError();
246-
247-
// Initialize and no exception should be thrown.
248-
assertDoesNotThrow(() -> initFailingGracefulClient(true));
249-
}
242+
// NOTE: Graceful mode during init is intrinsically true since the call is non-blocking and
243+
// exceptions are caught without rethrowing in `FetchConfigurationsTask`
250244

251245
@Test
252246
public void testClientMakesDefaultAssignmentsAfterFailingToInitialize() {
@@ -256,40 +250,13 @@ public void testClientMakesDefaultAssignmentsAfterFailingToInitialize() {
256250
// Initialize and no exception should be thrown.
257251
try {
258252
EppoClient eppoClient = initFailingGracefulClient(true);
253+
Thread.sleep(25); // Sleep to allow the async config fetch call to happen (and fail)
259254
assertEquals("default", eppoClient.getStringAssignment("experiment1", "subject1", "default"));
260255
} catch (Exception e) {
261256
fail("Unexpected exception: " + e);
262257
}
263258
}
264259

265-
@Test
266-
public void testClientMakesDefaultAssignmentsAfterFailingToInitializeNonGracefulMode() {
267-
// Set up bad HTTP response
268-
mockHttpError();
269-
270-
// Initialize and the exception should be thrown.
271-
try {
272-
initFailingGracefulClient(false);
273-
fail("Exception should have been thrown");
274-
} catch (RuntimeException e) {
275-
// Expected
276-
assertEquals("Intentional Error", e.getMessage());
277-
} finally {
278-
assertEquals(
279-
"default",
280-
EppoClient.getInstance().getStringAssignment("experiment1", "subject1", "default"));
281-
}
282-
}
283-
284-
@Test
285-
public void testNonGracefulInitializationFailure() {
286-
// Set up bad HTTP response
287-
mockHttpError();
288-
289-
// Initialize and assert exception thrown
290-
assertThrows(Exception.class, () -> initFailingGracefulClient(false));
291-
}
292-
293260
public static void mockHttpError() {
294261
// Create a mock instance of EppoHttpClient
295262
EppoHttpClient mockHttpClient = mock(EppoHttpClient.class);

0 commit comments

Comments
 (0)