-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support mapping a client to a given provider. (#388)
* Support mapping a client to a given provider. Signed-off-by: Justin Abrahms <[email protected]> * Add a few javadocs. Signed-off-by: Justin Abrahms <[email protected]> * Special case the null client name Signed-off-by: Justin Abrahms <[email protected]> * Add some missing test cases. Signed-off-by: Justin Abrahms <[email protected]> * Moving to an object map unwraps the values. Signed-off-by: Justin Abrahms <[email protected]> * Fix equality test. Signed-off-by: Justin Abrahms <[email protected]> * Carry targeting key when copying over null object. Signed-off-by: Justin Abrahms <[email protected]> * Test provider name, not object equality. Signed-off-by: Justin Abrahms <[email protected]> * Client-based getProvider is now an overload; Use read lock, not write lock. Signed-off-by: Justin Abrahms <[email protected]> * Update src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java Co-authored-by: Lars Opitz <[email protected]> Signed-off-by: Justin Abrahms <[email protected]> * Simplify locking logic around providers. There's no such thing as "API without a provider set" anymore. We now default to NoOpProvider in the API (not client). Signed-off-by: Justin Abrahms <[email protected]> * Add a few missing tests Signed-off-by: Justin Abrahms <[email protected]> --------- Signed-off-by: Justin Abrahms <[email protected]> Co-authored-by: Lars Opitz <[email protected]> Co-authored-by: Michael Beemer <[email protected]>
- Loading branch information
1 parent
1af8e96
commit d4c43d7
Showing
10 changed files
with
113 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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 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 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
23 changes: 23 additions & 0 deletions
23
src/test/java/dev/openfeature/sdk/ClientProviderMappingTest.java
This file contains 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,23 @@ | ||
package dev.openfeature.sdk; | ||
|
||
import io.cucumber.java.eo.Do; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class ClientProviderMappingTest { | ||
@Test | ||
void clientProviderTest() { | ||
OpenFeatureAPI api = OpenFeatureAPI.getInstance(); | ||
|
||
api.setProvider("client1", new DoSomethingProvider()); | ||
api.setProvider("client2", new NoOpProvider()); | ||
|
||
Client c1 = api.getClient("client1"); | ||
Client c2 = api.getClient("client2"); | ||
|
||
assertTrue(c1.getBooleanValue("test", false)); | ||
assertFalse(c2.getBooleanValue("test", false)); | ||
} | ||
} |
This file contains 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 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 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 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 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,26 @@ | ||
package dev.openfeature.sdk; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class OpenFeatureAPITest { | ||
@Test | ||
void namedProviderTest() { | ||
OpenFeatureAPI api = OpenFeatureAPI.getInstance(); | ||
FeatureProvider provider = new NoOpProvider(); | ||
api.setProvider("namedProviderTest", provider); | ||
assertEquals(provider.getMetadata().getName(), api.getProviderMetadata("namedProviderTest").getName()); | ||
} | ||
|
||
@Test void settingDefaultProviderToNullErrors() { | ||
OpenFeatureAPI api = OpenFeatureAPI.getInstance(); | ||
assertThrows(IllegalArgumentException.class, () -> api.setProvider(null)); | ||
} | ||
|
||
@Test void settingNamedClientProviderToNullErrors() { | ||
OpenFeatureAPI api = OpenFeatureAPI.getInstance(); | ||
assertThrows(IllegalArgumentException.class, () -> api.setProvider("client-name", null)); | ||
} | ||
} |
This file contains 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