Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow offline init with unobfuscated config #143

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion eppo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "cloud.eppo"
version = "4.3.4-SNAPSHOT"
version = "4.3.5-SNAPSHOT"
typotter marked this conversation as resolved.
Show resolved Hide resolved

android {
buildFeatures.buildConfig true
Expand Down
40 changes: 40 additions & 0 deletions eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,46 @@ private void runTestCases() {
}
}

@Test
public void testOfflineInit() throws IOException {
testOfflineInitFromFile("flags-v1.json");
}

@Test
public void testObfuscatedOfflineInit() throws IOException {
testOfflineInitFromFile("flags-v1-obfuscated.json");
}
typotter marked this conversation as resolved.
Show resolved Hide resolved

public void testOfflineInitFromFile(String filepath) throws IOException {
AssetManager assets = ApplicationProvider.getApplicationContext().getAssets();

InputStream stream = assets.open(filepath);
int size = stream.available();
byte[] buffer = new byte[size];
int numBytes = stream.read(buffer);
stream.close();

CompletableFuture<Void> futureClient =
new EppoClient.Builder("DUMMYKEY", ApplicationProvider.getApplicationContext())
.isGracefulMode(false)
.offlineMode(true)
.assignmentLogger(mockAssignmentLogger)
.forceReinitialize(true)
.initialConfiguration(buffer)
.buildAndInitAsync()
.thenAccept(client -> Log.i(TAG, "Test client async buildAndInit completed."));

Double result =
futureClient
.thenApply(
clVoid -> {
return EppoClient.getInstance().getDoubleAssignment("numeric_flag", "bob", 99.0);
})
.join();

assertEquals(3.14, result, 0.1);
typotter marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void testCachedConfigurations() {
// First initialize successfully
Expand Down
4 changes: 2 additions & 2 deletions eppo/src/main/java/cloud/eppo/android/EppoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ public Builder assignmentCache(IAssignmentCache assignmentCache) {
public Builder initialConfiguration(byte[] initialFlagConfigResponse) {
this.initialConfiguration =
CompletableFuture.completedFuture(
Configuration.builder(initialFlagConfigResponse, true).build());
new Configuration.Builder(initialFlagConfigResponse).build());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! By omitting it will parse the flag response and then check the format field 🚀

return this;
}

public Builder initialConfiguration(CompletableFuture<byte[]> initialFlagConfigResponse) {
this.initialConfiguration =
initialFlagConfigResponse.thenApply(ic -> Configuration.builder(ic, true).build());
initialFlagConfigResponse.thenApply(ic -> new Configuration.Builder(ic).build());
return this;
}

Expand Down
Loading