Skip to content
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

feat: Add support for fallback-action #93

Merged
merged 11 commits into from
Dec 6, 2019
Merged

Conversation

dennis-menge
Copy link
Contributor

@dennis-menge dennis-menge commented Nov 12, 2019

Today it is possible to define a fallback value which the isEnabled will return if the feature toggle is not defined.

We want to also allow the user to send in a fallbackFunction instead of a fallback value (which will take precedence over fallback value).

The fallback function should get to arguments injected: toggleName and the enhanced unleashContext. The function is implemented by the caller and should return a boolean value.

Example on how it would work:
isEnabled("someToggle", context, (toggleName, eContext) -> false)

@dennis-menge dennis-menge changed the title WIP: relates to #89: to Added first implementation (draft) of fallbackAction WIP: relates to #89: Added first implementation (draft) of fallbackAction Nov 12, 2019
@@ -15,6 +15,10 @@ default boolean isEnabled(String toggleName, UnleashContext context, boolean def
return isEnabled(toggleName, defaultSetting);
}

boolean isEnabled(final String toggleName, boolean defaultSetting, final FallbackAction fallbackAction);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of defining a new interface we could actually use one of the functional interfaces: BiFunction<String, UnleashContext, Boolean> instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, completely forgot about these, I will change that accordingly.

fallbackAction.apply(toggleName, contextProvider.getContext());
}

return isEnabled(featureToggle, contextProvider.getContext(), defaultSetting);
Copy link
Member

@ivarconr ivarconr Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather invert it and have this function being the master and have the other isEnabled calls send in a proper fallback-action.

@coveralls
Copy link

coveralls commented Nov 12, 2019

Coverage Status

Coverage decreased (-0.6%) to 93.06% when pulling e0eb435 on dennis-menge:master into d26b67a on Unleash:master.

return isEnabled(toggleName, contextProvider.getContext(), defaultSetting, fallbackAction);
}

public boolean isEnabled(final String toggleName, UnleashContext context, boolean defaultSetting, final BiFunction<String, UnleashContext, Boolean> fallbackAction) {
FeatureToggle featureToggle = toggleRepository.getToggle(toggleName);
boolean enabled = isEnabled(featureToggle, context, defaultSetting);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it would be better if we modify the private isEnabled-method (line 99) to take FallbackAction as last input and have all public isEnabled-methods call this one. There are some reasons for this:

  • Avoid duplication of logic.
  • ensure that FallbackAction gets the enhanced context injected.

This change would require existing isEnabled-methods to also send in a fallback function, this can be achieved via a lambda that just returns the fallbackValue injected to the method (or false)

return isEnabled(toggleName, false, fallbackAction);
}

boolean isEnabled(final String toggleName, boolean defaultSetting, final BiFunction<String, UnleashContext, Boolean> fallbackAction);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By not providing fallback for new interface methods we will break existing implementations of the interface. This is probably ok, but needs to be at least a minor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a default implementation like for the other methods

…h implementation, added default implementation in Unleash interface to avoid breaking existing implementation
@ivarconr
Copy link
Member

ivarconr commented Nov 13, 2019

This is really closing in to something good now 🚀.

I have limited time today, but hope to be able to do a proper validation tomorrow!

Feel free to also join us on slack for more in depth discussions:

return isEnabled(toggleName, false, fallbackAction);
}

default boolean isEnabled(String toggleName, UnleashContext context, boolean defaultSetting, BiFunction<String, UnleashContext, Boolean> fallbackAction) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is not needed. It does not make sense to allow both defaultSetting and a fallbackAction.

Should not be possible to define both a fallback action and
a defaultSetting at the same time.
@ivarconr
Copy link
Member

Hi again @dennis-menge. I did a few adjustment to this PR. Could you look it over and see if iy make sense?

e96a173

Use mocked functions and verify that the fallBack action
is actually called with correct arguments.
@dennis-menge
Copy link
Contributor Author

dennis-menge commented Nov 17, 2019

Hi again @dennis-menge. I did a few adjustment to this PR. Could you look it over and see if iy make sense?

e96a173

Hi Ivar, looks nice, I misunderstood the whole time that defaultSetting and fallbackAction should be provided at the same time with fallbackAction taking precedence, which obviously makes no sense.

Thank you!

@dennis-menge dennis-menge changed the title WIP: relates to #89: Added first implementation (draft) of fallbackAction relates to #89: Added implementation of fallbackAction Nov 17, 2019
@ivarconr ivarconr changed the title relates to #89: Added implementation of fallbackAction feat: Add support for fallback-action Nov 19, 2019
@ivarconr ivarconr merged commit e420ae9 into Unleash:master Dec 6, 2019
ivarconr pushed a commit that referenced this pull request Feb 20, 2020
* closes #89: to Added first implementation (draft) of fallbackAction

* Migrated to BiFunction for definition of fallback action, refactored methods according to feedback, added tests

* changed one test case to reflect correct implementation

* Added default implementation for isEnabled(String, BiFunction)

* Incorporated feedback, changed logical method layout in DefaultUnleash implementation, added default implementation in Unleash interface to avoid breaking existing implementation

* fix: fallbackAction and defaultSetting

Should not be possible to define both a fallback action and
a defaultSetting at the same time.

* fix: Improve fallbackAction unit-tests

Use mocked functions and verify that the fallBack action
is actually called with correct arguments.

* fix: remove final arguments in interface

* fix: simplify FakeUnleash for fallbackAction

* fix: formatting

* fix: counting at right place
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants