From 867048e4b5499fa7135f0024d4b9fc85f146e903 Mon Sep 17 00:00:00 2001 From: Ty Potter Date: Thu, 19 Dec 2024 23:44:14 -0700 Subject: [PATCH 1/3] fix: allow offline init with unobfuscated config --- eppo/build.gradle | 2 +- .../cloud/eppo/android/EppoClientTest.java | 40 +++++++++++++++++++ .../java/cloud/eppo/android/EppoClient.java | 4 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/eppo/build.gradle b/eppo/build.gradle index 3b647c2..315be49 100644 --- a/eppo/build.gradle +++ b/eppo/build.gradle @@ -7,7 +7,7 @@ plugins { } group = "cloud.eppo" -version = "4.3.4-SNAPSHOT" +version = "4.3.5-SNAPSHOT" android { buildFeatures.buildConfig true diff --git a/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java b/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java index 1d9ffdc..383a901 100644 --- a/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java +++ b/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java @@ -369,6 +369,46 @@ private void runTestCases() { } } + @Test + public void testOfflineInit() throws IOException { + testOfflineInit("flags-v1.json"); + } + + @Test + public void testObfuscatedOfflineInit() throws IOException { + testOfflineInit("flags-v1-obfuscated.json"); + } + + public void testOfflineInit(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 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 diff --git a/eppo/src/main/java/cloud/eppo/android/EppoClient.java b/eppo/src/main/java/cloud/eppo/android/EppoClient.java index d45b81f..f98e05a 100644 --- a/eppo/src/main/java/cloud/eppo/android/EppoClient.java +++ b/eppo/src/main/java/cloud/eppo/android/EppoClient.java @@ -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 initialFlagConfigResponse) { this.initialConfiguration = - initialFlagConfigResponse.thenApply(ic -> Configuration.builder(ic, true).build()); + initialFlagConfigResponse.thenApply(ic -> new Configuration.Builder(ic).build()); return this; } From 6f901acd5dd302856ccc9cff15ed110f0c57dfa4 Mon Sep 17 00:00:00 2001 From: Ty Potter Date: Thu, 19 Dec 2024 23:54:46 -0700 Subject: [PATCH 2/3] rename method --- .../androidTest/java/cloud/eppo/android/EppoClientTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java b/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java index 383a901..4d761c0 100644 --- a/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java +++ b/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java @@ -371,15 +371,15 @@ private void runTestCases() { @Test public void testOfflineInit() throws IOException { - testOfflineInit("flags-v1.json"); + testOfflineInitFromFile("flags-v1.json"); } @Test public void testObfuscatedOfflineInit() throws IOException { - testOfflineInit("flags-v1-obfuscated.json"); + testOfflineInitFromFile("flags-v1-obfuscated.json"); } - public void testOfflineInit(String filepath) throws IOException { + public void testOfflineInitFromFile(String filepath) throws IOException { AssetManager assets = ApplicationProvider.getApplicationContext().getAssets(); InputStream stream = assets.open(filepath); From dcf4a3fcc8cbce3964b2ce3dfb308fedc9b054a7 Mon Sep 17 00:00:00 2001 From: Ty Potter Date: Fri, 20 Dec 2024 07:55:52 -0700 Subject: [PATCH 3/3] bump version --- eppo/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eppo/build.gradle b/eppo/build.gradle index 315be49..4210055 100644 --- a/eppo/build.gradle +++ b/eppo/build.gradle @@ -7,7 +7,7 @@ plugins { } group = "cloud.eppo" -version = "4.3.5-SNAPSHOT" +version = "4.3.5" android { buildFeatures.buildConfig true