Skip to content

Commit

Permalink
adjustments from self-review of PR
Browse files Browse the repository at this point in the history
  • Loading branch information
aarsilv committed May 22, 2024
1 parent 395eca5 commit 1a4a048
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public ConfigurationRequestor(ConfigurationStore configurationStore, EppoHttpCli
}

public void load(InitializationCallback callback) {
// We have two at-bats to load the configuration; track their success
AtomicBoolean cacheLoadInProgress = new AtomicBoolean(false);
// We have two at-bats to load the configuration: loading from cache and fetching
// The below variables help them keep track of each other's progress
AtomicBoolean cacheLoadInProgress = new AtomicBoolean(true);
AtomicReference<String> fetchErrorMessage = new AtomicReference<>(null);
// We only want to fire the callback off once; track whether or not we have yet
// We only want to fire the callback off once; so track whether or not we have yet
AtomicBoolean callbackCalled = new AtomicBoolean(false);
configurationStore.loadFromCache(new CacheLoadCallback() {
@Override
Expand Down Expand Up @@ -61,7 +62,7 @@ public void onSuccess(Reader response) {
} catch (JsonSyntaxException | JsonIOException e) {
fetchErrorMessage.set(e.getMessage());
Log.e(TAG, "Error loading configuration response", e);
// If cache loading in progress, defer to it's outcome for firing the success or failure callback
// Below includes a check for cache loading in progress, as if so, we'll defer to it's outcome for firing the success or failure callback
if (callback != null && !cacheLoadInProgress.get() && callbackCalled.compareAndSet(false, true)) {
Log.d(TAG, "Failed to initialize from cache or by fetching");
callback.onError("Cache and fetch failed "+e.getMessage());
Expand Down
1 change: 0 additions & 1 deletion eppo/src/main/java/cloud/eppo/android/RuleEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,4 @@ private static String castAttributeForListComparison(EppoValue attributeValue) {
throw new IllegalArgumentException("Unknown EppoValue type for casting for list comparison: "+attributeValue);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static OperatorType fromString(String value) {
if (type.value.equals(value)
|| getMD5Hex(type.value).equals(value)
|| getMD5Hex(type.value).equals(value)
// gson deserializes enums using their names so check it to in case we are reading from cache
// gson deserializes enums using their names so check that too in case we are reading from cache
|| type.name().equals(value)
|| getMD5Hex(type.name()).equals(value)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import java.lang.reflect.Type;
import java.util.Date;

/**
* This adapter for Date allows gson to serialize to UTC ISO 8601 (vs. its default of local timezone)
*/
public class DateAdapter implements JsonSerializer<Date> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ public void testAllocationStartAndEndAt() {
public void testObfuscated() {
// Note: this is NOT a comprehensive test of obfuscation (many operators and value types are
// excluded, as are startAt and endAt)
// Much more is covered by EppoClientTest

Map<String, Variation> variations = createVariations("a", "b");
List<Split> firstAllocationSplits = createSplits("b");
Expand Down

0 comments on commit 1a4a048

Please sign in to comment.