Remove flag eval options from provider API

This commit is contained in:
Justin Abrahms 2022-08-29 10:50:54 -07:00
parent 52c97309d2
commit 4ec5258d95
No known key found for this signature in database
GPG Key ID: 599E2E12011DC474
8 changed files with 45 additions and 55 deletions

View File

@ -13,18 +13,13 @@ public interface FeatureProvider {
return new ArrayList<>();
}
ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options);
ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx);
ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options);
ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx);
ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options);
ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx);
ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options);
ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx);
ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue,
EvaluationContext invocationContext, FlagEvaluationOptions options);
ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue, EvaluationContext ctx);
}

View File

@ -21,8 +21,7 @@ public class NoOpProvider implements FeatureProvider {
}
@Override
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx) {
return ProviderEvaluation.<Boolean>builder()
.value(defaultValue)
.variant(PASSED_IN_DEFAULT)
@ -31,8 +30,7 @@ public class NoOpProvider implements FeatureProvider {
}
@Override
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx) {
return ProviderEvaluation.<String>builder()
.value(defaultValue)
.variant(PASSED_IN_DEFAULT)
@ -41,8 +39,7 @@ public class NoOpProvider implements FeatureProvider {
}
@Override
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx) {
return ProviderEvaluation.<Integer>builder()
.value(defaultValue)
.variant(PASSED_IN_DEFAULT)
@ -51,8 +48,7 @@ public class NoOpProvider implements FeatureProvider {
}
@Override
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx) {
return ProviderEvaluation.<Double>builder()
.value(defaultValue)
.variant(PASSED_IN_DEFAULT)
@ -62,8 +58,7 @@ public class NoOpProvider implements FeatureProvider {
@Override
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue,
EvaluationContext invocationContext,
FlagEvaluationOptions options) {
EvaluationContext invocationContext) {
return ProviderEvaluation.<Structure>builder()
.value(defaultValue)
.variant(PASSED_IN_DEFAULT)

View File

@ -115,15 +115,15 @@ public class OpenFeatureClient implements Client {
) {
switch (type) {
case BOOLEAN:
return provider.getBooleanEvaluation(key, (Boolean) defaultValue, invocationContext, options);
return provider.getBooleanEvaluation(key, (Boolean) defaultValue, invocationContext);
case STRING:
return provider.getStringEvaluation(key, (String) defaultValue, invocationContext, options);
return provider.getStringEvaluation(key, (String) defaultValue, invocationContext);
case INTEGER:
return provider.getIntegerEvaluation(key, (Integer) defaultValue, invocationContext, options);
return provider.getIntegerEvaluation(key, (Integer) defaultValue, invocationContext);
case DOUBLE:
return provider.getDoubleEvaluation(key, (Double) defaultValue, invocationContext, options);
return provider.getDoubleEvaluation(key, (Double) defaultValue, invocationContext);
case OBJECT:
return provider.getObjectEvaluation(key, (Structure) defaultValue, invocationContext, options);
return provider.getObjectEvaluation(key, (Structure) defaultValue, invocationContext);
default:
throw new GeneralError("Unknown flag type");
}

View File

@ -13,27 +13,27 @@ public class AlwaysBrokenProvider implements FeatureProvider {
}
@Override
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx) {
throw new NotImplementedException("BORK");
}
@Override
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx) {
throw new NotImplementedException("BORK");
}
@Override
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx) {
throw new NotImplementedException("BORK");
}
@Override
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx) {
throw new NotImplementedException("BORK");
}
@Override
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue, EvaluationContext invocationContext) {
throw new NotImplementedException("BORK");
}
}

View File

@ -14,21 +14,21 @@ public class DoSomethingProvider implements FeatureProvider {
}
@Override
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx) {
savedContext = ctx;
return ProviderEvaluation.<Boolean>builder()
.value(!defaultValue).build();
}
@Override
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx) {
return ProviderEvaluation.<String>builder()
.value(new StringBuilder(defaultValue).reverse().toString())
.build();
}
@Override
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx) {
savedContext = ctx;
return ProviderEvaluation.<Integer>builder()
.value(defaultValue * 100)
@ -36,7 +36,7 @@ public class DoSomethingProvider implements FeatureProvider {
}
@Override
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx) {
savedContext = ctx;
return ProviderEvaluation.<Double>builder()
.value(defaultValue * 100)
@ -44,7 +44,7 @@ public class DoSomethingProvider implements FeatureProvider {
}
@Override
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue, EvaluationContext invocationContext) {
savedContext = invocationContext;
return ProviderEvaluation.<Structure>builder()
.value(null)

View File

@ -382,7 +382,7 @@ public class HookSpecTest implements HookFixtures {
@Test void flag_eval_hook_order() {
Hook hook = mockBooleanHook();
FeatureProvider provider = mock(FeatureProvider.class);
when(provider.getBooleanEvaluation(any(), any(), any(), any()))
when(provider.getBooleanEvaluation(any(), any(), any()))
.thenReturn(ProviderEvaluation.<Boolean>builder()
.value(true)
.build());
@ -395,7 +395,7 @@ public class HookSpecTest implements HookFixtures {
FlagEvaluationOptions.builder().hook(hook).build());
order.verify(hook).before(any(), any());
order.verify(provider).getBooleanEvaluation(any(), any(), any(), any());
order.verify(provider).getBooleanEvaluation(any(), any(), any());
order.verify(hook).after(any(), any(), any());
order.verify(hook).finallyAfter(any(), any());
}
@ -484,7 +484,7 @@ public class HookSpecTest implements HookFixtures {
when(hook.before(any(), any())).thenReturn(Optional.of(hookCtx));
FeatureProvider provider = mock(FeatureProvider.class);
when(provider.getBooleanEvaluation(any(), any(), any(), any())).thenReturn(ProviderEvaluation.<Boolean>builder()
when(provider.getBooleanEvaluation(any(), any(), any())).thenReturn(ProviderEvaluation.<Boolean>builder()
.value(true)
.build());
@ -497,7 +497,7 @@ public class HookSpecTest implements HookFixtures {
.build());
ArgumentCaptor<EvaluationContext> captor = ArgumentCaptor.forClass(EvaluationContext.class);
verify(provider).getBooleanEvaluation(any(), any(), captor.capture(), any());
verify(provider).getBooleanEvaluation(any(), any(), captor.capture());
EvaluationContext ec = captor.getValue();
assertEquals("works", ec.getValue("test").asString());
assertEquals("exists", ec.getValue("another").asString());

View File

@ -7,33 +7,33 @@ import org.junit.jupiter.api.Test;
public class NoOpProviderTest {
@Test void bool() {
NoOpProvider p = new NoOpProvider();
ProviderEvaluation<Boolean> eval = p.getBooleanEvaluation("key", true, null, null);
ProviderEvaluation<Boolean> eval = p.getBooleanEvaluation("key", true, null);
assertEquals(true, eval.getValue());
}
@Test void str() {
NoOpProvider p = new NoOpProvider();
ProviderEvaluation<String> eval = p.getStringEvaluation("key", "works", null, null);
ProviderEvaluation<String> eval = p.getStringEvaluation("key", "works", null);
assertEquals("works", eval.getValue());
}
@Test void integer() {
NoOpProvider p = new NoOpProvider();
ProviderEvaluation<Integer> eval = p.getIntegerEvaluation("key", 4, null, null);
ProviderEvaluation<Integer> eval = p.getIntegerEvaluation("key", 4, null);
assertEquals(4, eval.getValue());
}
@Test void noOpdouble() {
NoOpProvider p = new NoOpProvider();
ProviderEvaluation<Double> eval = p.getDoubleEvaluation("key", 0.4, null, null);
ProviderEvaluation<Double> eval = p.getDoubleEvaluation("key", 0.4, null);
assertEquals(0.4, eval.getValue());
}
@Test void structure() {
NoOpProvider p = new NoOpProvider();
Structure s = new Structure();
ProviderEvaluation<Structure> eval = p.getObjectEvaluation("key", s, null, null);
ProviderEvaluation<Structure> eval = p.getObjectEvaluation("key", s, null);
assertEquals(s, eval.getValue());
}
}

View File

@ -24,19 +24,19 @@ public class ProviderSpecTest {
@Specification(number="2.9.1", text="The flag resolution structure SHOULD accept a generic " +
"argument (or use an equivalent language feature) which indicates the type of the wrapped value field.")
@Test void flag_value_set() {
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext());
assertNotNull(int_result.getValue());
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new EvaluationContext());
assertNotNull(double_result.getValue());
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext(), FlagEvaluationOptions.builder().build());
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext());
assertNotNull(string_result.getValue());
ProviderEvaluation<Boolean> boolean_result = p.getBooleanEvaluation("key", false, new EvaluationContext(), FlagEvaluationOptions.builder().build());
ProviderEvaluation<Boolean> boolean_result = p.getBooleanEvaluation("key", false, new EvaluationContext());
assertNotNull(boolean_result.getValue());
ProviderEvaluation<Structure> object_result = p.getObjectEvaluation("key", new Structure(), new EvaluationContext(), FlagEvaluationOptions.builder().build());
ProviderEvaluation<Structure> object_result = p.getObjectEvaluation("key", new Structure(), new EvaluationContext());
assertNotNull(object_result.getValue());
}
@ -44,14 +44,14 @@ public class ProviderSpecTest {
@Specification(number="2.6", text="The provider SHOULD populate the flag resolution structure's " +
"reason field with a string indicating the semantic reason for the returned flag value.")
@Test void has_reason() {
ProviderEvaluation<Boolean> result = p.getBooleanEvaluation("key", false, new EvaluationContext(), FlagEvaluationOptions.builder().build());
ProviderEvaluation<Boolean> result = p.getBooleanEvaluation("key", false, new EvaluationContext());
assertEquals(Reason.DEFAULT, result.getReason());
}
@Specification(number="2.7", text="In cases of normal execution, the provider MUST NOT populate " +
"the flag resolution structure's error code field, or otherwise must populate it with a null or falsy value.")
@Test void no_error_code_by_default() {
ProviderEvaluation<Boolean> result = p.getBooleanEvaluation("key", false, new EvaluationContext(), FlagEvaluationOptions.builder().build());
ProviderEvaluation<Boolean> result = p.getBooleanEvaluation("key", false, new EvaluationContext());
assertNull(result.getErrorCode());
}
@ -63,16 +63,16 @@ public class ProviderSpecTest {
@Specification(number="2.5", text="In cases of normal execution, the provider SHOULD populate the " +
"flag resolution structure's variant field with a string identifier corresponding to the returned flag value.")
@Test void variant_set() {
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext());
assertNotNull(int_result.getReason());
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new EvaluationContext());
assertNotNull(double_result.getReason());
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext(), FlagEvaluationOptions.builder().build());
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext());
assertNotNull(string_result.getReason());
ProviderEvaluation<Boolean> boolean_result = p.getBooleanEvaluation("key", false, new EvaluationContext(), FlagEvaluationOptions.builder().build());
ProviderEvaluation<Boolean> boolean_result = p.getBooleanEvaluation("key", false, new EvaluationContext());
assertNotNull(boolean_result.getReason());
}