-
Notifications
You must be signed in to change notification settings - Fork 7
FT calculator #803
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
Merged
Merged
FT calculator #803
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
22a920e
FallbackTreatment model
gthea b512aac
Fallback config
gthea a0bd7f3
Remove unnecessary toString()
gthea 8f50a35
Sanitizer
gthea 3325b73
FT calculator
gthea e42ead7
Merge branch 'FME-8434-fallback_baseline' into FME-9625-calculator
gthea 5f46e45
Fallback treatment label prefix
gthea 3126631
Fix javadoc
gthea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/io/split/android/client/fallback/FallbackTreatmentsCalculator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package io.split.android.client.fallback; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
|
|
||
| /** | ||
| * Resolves a fallback treatment for a given flag name. | ||
| * Returns null if no fallback applies (caller should use control). | ||
| */ | ||
| public interface FallbackTreatmentsCalculator { | ||
|
|
||
| /** | ||
| * Resolve a fallback for a given flag name. | ||
| * | ||
| * @param flagName non-null flag name | ||
| * @return a fallback treatment if configured, otherwise "control" | ||
| */ | ||
| @NonNull | ||
| FallbackTreatment resolve(@NonNull String flagName); | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/main/java/io/split/android/client/fallback/FallbackTreatmentsCalculatorImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package io.split.android.client.fallback; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public final class FallbackTreatmentsCalculatorImpl implements FallbackTreatmentsCalculator { | ||
|
|
||
| @NonNull | ||
| private final FallbackConfiguration mConfig; | ||
|
|
||
| public FallbackTreatmentsCalculatorImpl(@NonNull FallbackConfiguration config) { | ||
| mConfig = config; | ||
| } | ||
|
|
||
| @NonNull | ||
| @Override | ||
| public FallbackTreatment resolve(@NonNull String flagName) { | ||
| Map<String, FallbackTreatment> byFlag = mConfig.getByFlag(); | ||
| if (byFlag != null) { | ||
| FallbackTreatment flagTreatment = byFlag.get(flagName); | ||
| if (flagTreatment != null) { | ||
| return flagTreatment; | ||
| } | ||
| } | ||
| FallbackTreatment global = mConfig.getGlobal(); | ||
| if (global != null) { | ||
| return global; | ||
| } | ||
| return FallbackTreatment.CONTROL; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/test/java/io/split/android/client/fallback/FallbackTreatmentsCalculatorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package io.split.android.client.fallback; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class FallbackTreatmentsCalculatorTest { | ||
|
|
||
| @Test | ||
| public void flagLevelOverrideTakesPrecedence() { | ||
| FallbackTreatment global = new FallbackTreatment("off", "{\"g\":true}"); | ||
| FallbackTreatment byFlag = new FallbackTreatment("on", "{\"f\":true}"); | ||
| Map<String, FallbackTreatment> map = new HashMap<>(); | ||
| map.put("my_flag", byFlag); | ||
| FallbackConfiguration config = FallbackConfiguration.builder() | ||
| .global(global) | ||
| .byFlag(map) | ||
| .build(); | ||
|
|
||
| FallbackTreatmentsCalculator calculator = new FallbackTreatmentsCalculatorImpl(config); | ||
| FallbackTreatment resolvedExisting = calculator.resolve("my_flag"); | ||
| FallbackTreatment resolvedOther = calculator.resolve("other_flag"); | ||
|
|
||
| assertNotNull(resolvedExisting); | ||
| assertEquals(byFlag, resolvedExisting); | ||
| assertNotNull(resolvedOther); | ||
| assertEquals(global, resolvedOther); | ||
| } | ||
|
|
||
| @Test | ||
| public void globalFallbackIsReturnedWhenNoFlagOverride() { | ||
| FallbackTreatment global = new FallbackTreatment("off"); | ||
| FallbackConfiguration config = FallbackConfiguration.builder() | ||
| .global(global) | ||
| .byFlag(Collections.emptyMap()) | ||
| .build(); | ||
|
|
||
| FallbackTreatmentsCalculator calculator = new FallbackTreatmentsCalculatorImpl(config); | ||
| FallbackTreatment resolved = calculator.resolve("any_flag"); | ||
|
|
||
| assertNotNull(resolved); | ||
| assertEquals(global, resolved); | ||
| } | ||
|
|
||
| @Test | ||
| public void flagLevelFallbackIsReturnedWhenConfigured() { | ||
| FallbackTreatment byFlag = new FallbackTreatment("on"); | ||
| Map<String, FallbackTreatment> map = new HashMap<>(); | ||
| map.put("flagA", byFlag); | ||
| FallbackConfiguration config = FallbackConfiguration.builder() | ||
| .byFlag(map) | ||
| .build(); | ||
|
|
||
| FallbackTreatmentsCalculator calculator = new FallbackTreatmentsCalculatorImpl(config); | ||
| FallbackTreatment resolved = calculator.resolve("flagA"); | ||
|
|
||
| assertNotNull(resolved); | ||
| assertEquals(byFlag, resolved); | ||
| } | ||
|
|
||
| @Test | ||
| public void returnsControlWhenNoFallbackConfigured() { | ||
| FallbackConfiguration config = FallbackConfiguration.builder() | ||
| .build(); | ||
|
|
||
| FallbackTreatmentsCalculator calculator = new FallbackTreatmentsCalculatorImpl(config); | ||
| FallbackTreatment resolved = calculator.resolve("nope"); | ||
|
|
||
| assertNotNull(resolved); | ||
| assertEquals(FallbackTreatment.CONTROL, resolved); | ||
| } | ||
|
|
||
| @Test | ||
| public void nonexistentFlagFallsBackToGlobal() { | ||
| FallbackTreatment global = new FallbackTreatment("off"); | ||
| Map<String, FallbackTreatment> map = new HashMap<>(); | ||
| map.put("flagA", new FallbackTreatment("on")); | ||
| FallbackConfiguration config = FallbackConfiguration.builder() | ||
| .global(global) | ||
| .byFlag(map) | ||
| .build(); | ||
|
|
||
| FallbackTreatmentsCalculator calculator = new FallbackTreatmentsCalculatorImpl(config); | ||
| FallbackTreatment resolved = calculator.resolve("flagB"); | ||
|
|
||
| assertNotNull(resolved); | ||
| assertEquals(global, resolved); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this method private/ just for testing?