Skip to content

Commit

Permalink
chore(format): spotless apply
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswk committed Dec 7, 2023
1 parent f64bc6b commit dde0dde
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 34 deletions.
20 changes: 15 additions & 5 deletions src/main/java/io/getunleash/DefaultUnleash.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,16 @@ private FeatureEvaluationResult getFeatureEvaluationResult(

/**
* Uses the old, statistically broken Variant seed for finding the correct variant
*
* @deprecated
* @param toggleName Name of the toggle
* @param context The UnleashContext
* @param fallbackAction What to do if we fail to find the toggle
* @param defaultVariant If we can't resolve a variant, what are we returning
* @return A wrapper containing whether the feature was enabled as well which Variant was selected
* @return A wrapper containing whether the feature was enabled as well which Variant was
* selected
*/
private FeatureEvaluationResult deprecatedGetFeatureEvaluationResult(
private FeatureEvaluationResult deprecatedGetFeatureEvaluationResult(
String toggleName,
UnleashContext context,
BiPredicate<String, UnleashContext> fallbackAction,
Expand All @@ -244,7 +246,9 @@ private FeatureEvaluationResult deprecatedGetFeatureEvaluationResult(
return new FeatureEvaluationResult(false, defaultVariant);
} else if (featureToggle.getStrategies().isEmpty()) {
return new FeatureEvaluationResult(
true, VariantUtil.selectDeprecatedVariantHashingAlgo(featureToggle, context, defaultVariant));
true,
VariantUtil.selectDeprecatedVariantHashingAlgo(
featureToggle, context, defaultVariant));
} else {
// Dependent toggles, no point in evaluating child strategies if our dependencies are
// not satisfied
Expand Down Expand Up @@ -388,6 +392,7 @@ public Variant getVariant(String toggleName, Variant defaultValue) {

/**
* Uses the old, statistically broken Variant seed for finding the correct variant
*
* @deprecated
* @param toggleName
* @param context
Expand All @@ -400,21 +405,24 @@ public Variant deprecatedGetVariant(String toggleName, UnleashContext context) {

/**
* Uses the old, statistically broken Variant seed for finding the correct variant
*
* @deprecated
* @param toggleName
* @param context
* @param defaultValue
* @return
*/
@Override
public Variant deprecatedGetVariant(String toggleName, UnleashContext context, Variant defaultValue) {
public Variant deprecatedGetVariant(
String toggleName, UnleashContext context, Variant defaultValue) {
return deprecatedGetVariant(toggleName, context, defaultValue, false);
}

private Variant deprecatedGetVariant(
String toggleName, UnleashContext context, Variant defaultValue, boolean isParent) {
FeatureEvaluationResult result =
deprecatedGetFeatureEvaluationResult(toggleName, context, (n, c) -> false, defaultValue);
deprecatedGetFeatureEvaluationResult(
toggleName, context, (n, c) -> false, defaultValue);
Variant variant = result.getVariant();
if (!isParent) {
metricService.countVariant(toggleName, variant.getName());
Expand All @@ -428,6 +436,7 @@ private Variant deprecatedGetVariant(

/**
* Uses the old, statistically broken Variant seed for finding the correct variant
*
* @deprecated
* @param toggleName
* @return
Expand All @@ -439,6 +448,7 @@ public Variant deprecatedGetVariant(String toggleName) {

/**
* Uses the old, statistically broken Variant seed for finding the correct variant
*
* @deprecated
* @param toggleName
* @param defaultValue
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/getunleash/FakeUnleash.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public Variant deprecatedGetVariant(String toggleName, UnleashContext context) {
}

@Override
public Variant deprecatedGetVariant(String toggleName, UnleashContext context, Variant defaultValue) {
public Variant deprecatedGetVariant(
String toggleName, UnleashContext context, Variant defaultValue) {
return null;
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/getunleash/strategy/Strategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ default FeatureEvaluationResult getResult(
enabled ? VariantUtil.selectVariant(parameters, variants, unleashContext) : null);
}


/**
* Uses the old pre 9.0.0 way of hashing for finding the Variant to return
*
* @deprecated
* @param parameters
* @param unleashContext
Expand All @@ -44,7 +44,10 @@ default FeatureEvaluationResult getDeprecatedHashingAlgoResult(
boolean enabled = isEnabled(parameters, unleashContext, constraints);
return new FeatureEvaluationResult(
enabled,
enabled ? VariantUtil.selectDeprecatedVariantHashingAlgo(parameters, variants, unleashContext) : null);
enabled
? VariantUtil.selectDeprecatedVariantHashingAlgo(
parameters, variants, unleashContext)
: null);
}

default boolean isEnabled(Map<String, String> parameters, UnleashContext unleashContext) {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/io/getunleash/variant/VariantUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public static Variant selectVariant(

/**
* Uses the old pre 9.0.0 way of hashing for finding the Variant to return
*
* @deprecated
* @param parameters
* @param variants
Expand Down Expand Up @@ -186,24 +187,24 @@ public static Variant selectVariant(

/**
* Uses the old pre 9.0.0 way of hashing for finding the Variant to return
*
* @deprecated
* @param featureToggle
* @param context
* @param defaultVariant
* @return
*/
public static @Nullable Variant selectDeprecatedVariantHashingAlgo(
FeatureToggle featureToggle, UnleashContext context, Variant defaultVariant
) {
FeatureToggle featureToggle, UnleashContext context, Variant defaultVariant) {
if (featureToggle == null) {
return defaultVariant;
}

Variant variant =
selectDeprecatedVariantHashingAlgo(
Collections.singletonMap("groupId", featureToggle.getName()),
featureToggle.getVariants(),
context);
selectDeprecatedVariantHashingAlgo(
Collections.singletonMap("groupId", featureToggle.getName()),
featureToggle.getVariants(),
context);

return variant != null ? variant : defaultVariant;
}
Expand Down
13 changes: 6 additions & 7 deletions src/test/java/io/getunleash/UnleashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,6 @@ public void get_default_variant_without_context() {
assertThat(result.isEnabled()).isTrue();
}



@Test
public void get_first_variant_with_context_provider() {

Expand Down Expand Up @@ -490,7 +488,8 @@ public void get_second_variant_with_context_provider_and_deprecated_algorithm()
params.put("userIds", "123, 5, 121");
ActivationStrategy strategy = new ActivationStrategy("userWithId", params);
FeatureToggle featureToggle =
new FeatureToggle("test", true, asList(strategy), getTestVariantsForDeprecatedHash());
new FeatureToggle(
"test", true, asList(strategy), getTestVariantsForDeprecatedHash());

when(toggleRepository.getToggle("test")).thenReturn(featureToggle);

Expand All @@ -506,7 +505,6 @@ public void get_second_variant_with_context_provider_and_deprecated_algorithm()
assertThat(newHash.getName()).isEqualTo("to");
assertThat(newHash.getPayload().map(Payload::getValue).get()).isEqualTo("to");
assertThat(newHash.isEnabled()).isTrue();

}

@Test
Expand Down Expand Up @@ -640,8 +638,9 @@ private List<VariantDefinition> getTestVariants() {

private List<VariantDefinition> getTestVariantsForDeprecatedHash() {
return asList(
new VariantDefinition("en", 65, new Payload("string", "en"), Collections.emptyList()),
new VariantDefinition("to", 35, new Payload("string", "to"), Collections.emptyList())
);
new VariantDefinition(
"en", 65, new Payload("string", "en"), Collections.emptyList()),
new VariantDefinition(
"to", 35, new Payload("string", "to"), Collections.emptyList()));
}
}
26 changes: 13 additions & 13 deletions src/test/java/io/getunleash/variant/VariantUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,27 +391,27 @@ public void feature_variants_variant_d_client_spec_tests() {
public void feature_variants_variant_d_client_spec_tests_with_deprecated_seed() {
List<VariantDefinition> variants = new ArrayList<>();
variants.add(
new VariantDefinition(
"variant1", 1, new Payload("string", "val1"), Collections.emptyList()));
new VariantDefinition(
"variant1", 1, new Payload("string", "val1"), Collections.emptyList()));
variants.add(
new VariantDefinition(
"variant2", 49, new Payload("string", "val2"), Collections.emptyList()));
new VariantDefinition(
"variant2", 49, new Payload("string", "val2"), Collections.emptyList()));
variants.add(
new VariantDefinition(
"variant3", 50, new Payload("string", "val3"), Collections.emptyList()));
new VariantDefinition(
"variant3", 50, new Payload("string", "val3"), Collections.emptyList()));
FeatureToggle toggle =
new FeatureToggle("Feature.Variants.D", true, Collections.emptyList(), variants);
new FeatureToggle("Feature.Variants.D", true, Collections.emptyList(), variants);
Variant variantUser712 =
VariantUtil.selectDeprecatedVariantHashingAlgo(
toggle, UnleashContext.builder().userId("712").build(), DISABLED_VARIANT);
VariantUtil.selectDeprecatedVariantHashingAlgo(
toggle, UnleashContext.builder().userId("712").build(), DISABLED_VARIANT);
assertThat(variantUser712.getName()).isEqualTo("variant3");
Variant variantUser525 =
VariantUtil.selectDeprecatedVariantHashingAlgo(
toggle, UnleashContext.builder().userId("525").build(), DISABLED_VARIANT);
VariantUtil.selectDeprecatedVariantHashingAlgo(
toggle, UnleashContext.builder().userId("525").build(), DISABLED_VARIANT);
assertThat(variantUser525.getName()).isEqualTo("variant3");
Variant variantUser537 =
VariantUtil.selectDeprecatedVariantHashingAlgo(
toggle, UnleashContext.builder().userId("537").build(), DISABLED_VARIANT);
VariantUtil.selectDeprecatedVariantHashingAlgo(
toggle, UnleashContext.builder().userId("537").build(), DISABLED_VARIANT);
assertThat(variantUser537.getName()).isEqualTo("variant2");
}

Expand Down

0 comments on commit dde0dde

Please sign in to comment.