Skip to content

Commit

Permalink
fix: allow offline init with unobfuscated config (#143)
Browse files Browse the repository at this point in the history
* fix: allow offline init with unobfuscated config
* bump version
  • Loading branch information
typotter authored Dec 20, 2024
1 parent e46e838 commit ffd6204
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
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"

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");
}

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);
}

@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());
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

0 comments on commit ffd6204

Please sign in to comment.