-
Notifications
You must be signed in to change notification settings - Fork 51
fix: int/float auto-conversion #472
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c09679e
FIX: float to int conversion and testing
DBlanchard88 6a43772
FIX: float to int conversion and testing
DBlanchard88 cf4aadb
formatting
DBlanchard88 04ac649
Merge branch 'main' into fix/floatbug
DBlanchard88 f2ce59f
Update providers/flagd/src/main/java/dev/openfeature/contrib/provider…
DBlanchard88 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,16 +47,17 @@ public void eventHandling() throws Throwable { | |
final BlockingQueue<StorageState> sender = new LinkedBlockingQueue<>(5); | ||
final BlockingQueue<ProviderState> receiver = new LinkedBlockingQueue<>(5); | ||
|
||
InProcessResolver inProcessResolver = | ||
getInProcessResolverWth(new MockStorage(new HashMap<>(), sender), providerState -> { | ||
InProcessResolver inProcessResolver = getInProcessResolverWth(new MockStorage(new HashMap<>(), sender), | ||
providerState -> { | ||
receiver.offer(providerState); | ||
}); | ||
|
||
// when - init and emit events | ||
Thread initThread = new Thread(() -> { | ||
try { | ||
inProcessResolver.init(); | ||
} catch (Exception e) {} | ||
} catch (Exception e) { | ||
} | ||
}); | ||
initThread.start(); | ||
if (!sender.offer(StorageState.OK, 100, TimeUnit.MILLISECONDS)) { | ||
|
@@ -86,8 +87,8 @@ public void simpleBooleanResolving() throws Exception { | |
}); | ||
|
||
// when | ||
ProviderEvaluation<Boolean> providerEvaluation = | ||
inProcessResolver.booleanEvaluation("booleanFlag", false, new ImmutableContext()); | ||
ProviderEvaluation<Boolean> providerEvaluation = inProcessResolver.booleanEvaluation("booleanFlag", false, | ||
new ImmutableContext()); | ||
|
||
// then | ||
assertEquals(true, providerEvaluation.getValue()); | ||
|
@@ -105,15 +106,53 @@ public void simpleDoubleResolving() throws Exception { | |
}); | ||
|
||
// when | ||
ProviderEvaluation<Double> providerEvaluation = | ||
inProcessResolver.doubleEvaluation("doubleFlag", 0d, new ImmutableContext()); | ||
ProviderEvaluation<Double> providerEvaluation = inProcessResolver.doubleEvaluation("doubleFlag", 0d, | ||
new ImmutableContext()); | ||
|
||
// then | ||
assertEquals(3.141d, providerEvaluation.getValue()); | ||
assertEquals("one", providerEvaluation.getVariant()); | ||
assertEquals(Reason.STATIC.toString(), providerEvaluation.getReason()); | ||
} | ||
|
||
@Test | ||
toddbaert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public void fetchIntegerAsDouble() throws Exception { | ||
// given | ||
final Map<String, FeatureFlag> flagMap = new HashMap<>(); | ||
flagMap.put("doubleFlag", DOUBLE_FLAG); | ||
|
||
InProcessResolver inProcessResolver = getInProcessResolverWth(new MockStorage(flagMap), providerState -> { | ||
}); | ||
|
||
// when | ||
ProviderEvaluation<Integer> providerEvaluation = inProcessResolver.integerEvaluation("doubleFlag", 0, | ||
new ImmutableContext()); | ||
|
||
// then | ||
assertEquals(3, providerEvaluation.getValue()); | ||
assertEquals("one", providerEvaluation.getVariant()); | ||
assertEquals(Reason.STATIC.toString(), providerEvaluation.getReason()); | ||
} | ||
|
||
@Test | ||
public void fetchDoubleAsInt() throws Exception { | ||
// given | ||
final Map<String, FeatureFlag> flagMap = new HashMap<>(); | ||
flagMap.put("integerFlag", INT_FLAG); | ||
|
||
InProcessResolver inProcessResolver = getInProcessResolverWth(new MockStorage(flagMap), providerState -> { | ||
}); | ||
|
||
// when | ||
ProviderEvaluation<Double> providerEvaluation = inProcessResolver.doubleEvaluation("integerFlag", 0d, | ||
new ImmutableContext()); | ||
|
||
// then | ||
assertEquals(1d, providerEvaluation.getValue()); | ||
assertEquals("one", providerEvaluation.getVariant()); | ||
assertEquals(Reason.STATIC.toString(), providerEvaluation.getReason()); | ||
} | ||
|
||
@Test | ||
public void simpleIntResolving() throws Exception { | ||
// given | ||
|
@@ -124,8 +163,8 @@ public void simpleIntResolving() throws Exception { | |
}); | ||
|
||
// when | ||
ProviderEvaluation<Integer> providerEvaluation = | ||
inProcessResolver.integerEvaluation("integerFlag", 0, new ImmutableContext()); | ||
ProviderEvaluation<Integer> providerEvaluation = inProcessResolver.integerEvaluation("integerFlag", 0, | ||
new ImmutableContext()); | ||
|
||
// then | ||
assertEquals(1, providerEvaluation.getValue()); | ||
|
@@ -147,8 +186,8 @@ public void simpleObjectResolving() throws Exception { | |
typeDefault.put("date", "01.01.1990"); | ||
|
||
// when | ||
ProviderEvaluation<Value> providerEvaluation = | ||
inProcessResolver.objectEvaluation("objectFlag", Value.objectToValue(typeDefault), new ImmutableContext()); | ||
ProviderEvaluation<Value> providerEvaluation = inProcessResolver.objectEvaluation("objectFlag", | ||
Value.objectToValue(typeDefault), new ImmutableContext()); | ||
|
||
// then | ||
Value value = providerEvaluation.getValue(); | ||
|
@@ -230,9 +269,8 @@ public void targetingMatchedEvaluationFlag() throws Exception { | |
}); | ||
|
||
// when | ||
ProviderEvaluation<String> providerEvaluation = | ||
inProcessResolver.stringEvaluation("stringFlag", "loopAlg", | ||
new MutableContext().add("email", "[email protected]")); | ||
ProviderEvaluation<String> providerEvaluation = inProcessResolver.stringEvaluation("stringFlag", "loopAlg", | ||
new MutableContext().add("email", "[email protected]")); | ||
|
||
// then | ||
assertEquals("binetAlg", providerEvaluation.getValue()); | ||
|
@@ -250,9 +288,8 @@ public void targetingUnmatchedEvaluationFlag() throws Exception { | |
}); | ||
|
||
// when | ||
ProviderEvaluation<String> providerEvaluation = | ||
inProcessResolver.stringEvaluation("stringFlag", "loopAlg", | ||
new MutableContext().add("email", "[email protected]")); | ||
ProviderEvaluation<String> providerEvaluation = inProcessResolver.stringEvaluation("stringFlag", "loopAlg", | ||
new MutableContext().add("email", "[email protected]")); | ||
|
||
// then | ||
assertEquals("loopAlg", providerEvaluation.getValue()); | ||
|
@@ -275,13 +312,13 @@ public void targetingErrorEvaluationFlag() throws Exception { | |
}); | ||
} | ||
|
||
|
||
private InProcessResolver getInProcessResolverWth(final MockStorage storage, Consumer<ProviderState> stateConsumer) | ||
throws NoSuchFieldException, IllegalAccessException { | ||
Field flagStore = InProcessResolver.class.getDeclaredField("flagStore"); | ||
flagStore.setAccessible(true); | ||
|
||
InProcessResolver resolver = new InProcessResolver(FlagdOptions.builder().deadline(1000).build(), stateConsumer); | ||
InProcessResolver resolver = new InProcessResolver(FlagdOptions.builder().deadline(1000).build(), | ||
stateConsumer); | ||
flagStore.set(resolver, storage); | ||
|
||
return resolver; | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.