Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
labels: mergeable
---
_Eppo Internal_
[//]: # (Link to the issue or doc corresponding to this chunk of work)
🎟️ Fixes: #__issue__
📜 Design Doc (if applicable)

## Motivation and Context
[//]: # (Why is this change required? What problem does it solve?)

## Description
[//]: # (Describe your changes in detail)

## How has this been documented?
[//]: # (Please describe how you documented the developer impact of your changes; link to PRs or issues)

## How has this been tested?
[//]: # (Please describe in detail how you tested your changes)


[//]: # (OPTIONAL)
[//]: # (Add one or multiple labels: enhancement, refactoring, bugfix)
24 changes: 16 additions & 8 deletions src/main/java/cloud/eppo/EppoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cloud.eppo.logging.AssignmentLogger;
import cloud.eppo.logging.BanditLogger;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -34,7 +35,7 @@ public static EppoClient getInstance() {
}

private EppoClient(
String apiKey,
String sdkKey,
String sdkName,
String sdkVersion,
@Nullable String baseUrl,
Expand All @@ -44,7 +45,7 @@ private EppoClient(
@Nullable IAssignmentCache assignmentCache,
@Nullable IAssignmentCache banditAssignmentCache) {
super(
apiKey,
sdkKey,
sdkName,
sdkVersion,
null,
Expand All @@ -60,9 +61,18 @@ private EppoClient(
banditAssignmentCache);
}

/**
* Creates a new EppoClient Builder object with the specified SDK Key.
*
* @param sdkKey (see <a href="https://docs.geteppo.com/sdks/sdk-keys/">SDK Keys</a>)
*/
public static Builder builder(@NotNull String sdkKey) {
return new Builder(sdkKey);
}

/** Builder pattern to initialize the EppoClient singleton */
public static class Builder {
private String apiKey;
private final String sdkKey;
private AssignmentLogger assignmentLogger;
private BanditLogger banditLogger;
private boolean isGracefulMode = DEFAULT_IS_GRACEFUL_MODE;
Expand All @@ -76,10 +86,8 @@ public static class Builder {
private IAssignmentCache banditAssignmentCache =
new ExpiringInMemoryAssignmentCache(10, TimeUnit.MINUTES);

/** Sets the API Key--created within the eppo application--to use. This is required. */
public Builder apiKey(String apiKey) {
this.apiKey = apiKey;
return this;
private Builder(@NotNull String sdkKey) {
this.sdkKey = sdkKey;
}

/**
Expand Down Expand Up @@ -168,7 +176,7 @@ public EppoClient buildAndInit() {

instance =
new EppoClient(
apiKey,
sdkKey,
sdkName,
sdkVersion,
apiBaseUrl,
Expand Down
13 changes: 5 additions & 8 deletions src/test/java/cloud/eppo/EppoClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void testErrorGracefulModeOff() {
@Test
public void testReinitializeWithoutForcing() {
EppoClient firstInstance = initClient(DUMMY_FLAG_API_KEY);
EppoClient secondInstance = new EppoClient.Builder().apiKey(DUMMY_FLAG_API_KEY).buildAndInit();
EppoClient secondInstance = EppoClient.builder(DUMMY_FLAG_API_KEY).buildAndInit();

assertSame(firstInstance, secondInstance);
}
Expand All @@ -212,7 +212,7 @@ public void testReinitializeWithoutForcing() {
public void testReinitializeWitForcing() {
EppoClient firstInstance = initClient(DUMMY_FLAG_API_KEY);
EppoClient secondInstance =
new EppoClient.Builder().apiKey(DUMMY_FLAG_API_KEY).forceReinitialize(true).buildAndInit();
EppoClient.builder(DUMMY_FLAG_API_KEY).forceReinitialize(true).buildAndInit();

assertNotSame(firstInstance, secondInstance);
}
Expand All @@ -223,8 +223,7 @@ public void testPolling() {
EppoHttpClient httpClientSpy = spy(httpClient);
TestUtils.setBaseClientHttpClientOverrideField(httpClientSpy);

new EppoClient.Builder()
.apiKey(DUMMY_FLAG_API_KEY)
EppoClient.builder(DUMMY_FLAG_API_KEY)
.pollingIntervalMs(20)
.forceReinitialize(true)
.buildAndInit();
Expand Down Expand Up @@ -300,8 +299,7 @@ private EppoClient initClient(String apiKey) {
mockAssignmentLogger = mock(AssignmentLogger.class);
mockBanditLogger = mock(BanditLogger.class);

return new EppoClient.Builder()
.apiKey(apiKey)
return EppoClient.builder(apiKey)
.apiBaseUrl(Constants.appendApiPathToHost(TEST_HOST))
.assignmentLogger(mockAssignmentLogger)
.banditLogger(mockBanditLogger)
Expand All @@ -314,8 +312,7 @@ private EppoClient initFailingGracefulClient(boolean isGracefulMode) {
mockAssignmentLogger = mock(AssignmentLogger.class);
mockBanditLogger = mock(BanditLogger.class);

return new EppoClient.Builder()
.apiKey(DUMMY_FLAG_API_KEY)
return EppoClient.builder(DUMMY_FLAG_API_KEY)
.apiBaseUrl("blag")
.assignmentLogger(mockAssignmentLogger)
.banditLogger(mockBanditLogger)
Expand Down