Is there an easy way to unregister a plugin from HystrixPlugins?

Skip to first unread message

Matt Brown

Jul 25, 2013, 4:26:52 PM7/25/13
I have a unit test which relies on some code that needs for a custom properties strategy to be registered with HystrixPlugins.getInstance().registerPropertiesStrategy().

However, if I have a second unit test which also needs to register the properties strategy with the HystrixPlugins instance, then it fails because the field can only be set in the HystrixPlugins singleton once:

    public void registerPropertiesStrategy(HystrixPropertiesStrategy impl) {
        if (!propertiesFactory.compareAndSet(null, impl)) {
            throw new IllegalStateException("Another strategy was already registered.");

Is there a way I am missing to reset the plugin's references? 

Ben Christensen

Jul 25, 2013, 4:41:04 PM7/25/13
to Matt Brown,
You can reset the state of Hystrix using Hystrix.reset() which is intended for testing and clean shutdown. 

Ben Christensen
You received this message because you are subscribed to the Google Groups "HystrixOSS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Aug 13, 2013, 4:17:29 PM8/13/13
to, Matt Brown
Actually, correction, Hystrix.reset() does not unregister plugins.

Andrew Blick

Apr 11, 2014, 6:02:05 PM4/11/14
to, Matt Brown
I'm also stuck on a similar problem. I registered a ConcurrencyStrategy in a unity test, and need a way to clear it so that when integration tests run, it has a clean state. I'm currently getting "Another strategy was already registered". I tried using Hystrix.reset() and also found that it does not reset the plugins. I then tried copying the code in HystrixPlugins.UnitTest.reset() (I'm working in Groovy, so I can access the private class and fields), but that didn't work either.

Andrew Blick

Apr 11, 2014, 6:54:14 PM4/11/14
to, Matt Brown
Turns our the HystrixPlugins.UnitTest.reset() method just misses one of the plugins. The following seems to fully reset Hystrix state:


In Java, I imagine that something similar can be achieved via the reflection API.


Aug 14, 2018, 9:36:31 AM8/14/18
to HystrixOSS
however, i think the key about the registered strategy is probably HystrixConcurrencyStrategyDefault.class. In HystrixPlugins.class, when we want to get one strategy.
* Retrieve instance of {@link HystrixConcurrencyStrategy} to use based on order of precedence as defined in {@link HystrixPlugins} class header.
* <p>
* Override default by using {@link #registerConcurrencyStrategy(HystrixConcurrencyStrategy)} or setting property (via Archaius): <code>hystrix.plugin.HystrixConcurrencyStrategy.implementation</code> with the
* full classname to load.
* @return {@link HystrixConcurrencyStrategy} implementation to use
public HystrixConcurrencyStrategy getConcurrencyStrategy() {
if (concurrencyStrategy.get() == null) {
// check for an implementation from Archaius first
Object impl = getPluginImplementation(HystrixConcurrencyStrategy.class);
if (impl == null) {
// nothing set via Archaius so initialize with default
concurrencyStrategy.compareAndSet(null, HystrixConcurrencyStrategyDefault.getInstance());
// we don't return from here but call get() again in case of thread-race so the winner will always get returned
} else {
// we received an implementation from Archaius so use it
concurrencyStrategy.compareAndSet(null, (HystrixConcurrencyStrategy) impl);
return concurrencyStrategy.get();
It will get you a HystrixConcurrencyStrategyDefault.

在 2013年7月26日星期五 UTC+8上午4:26:52,Matt Brown写道:
Reply all
Reply to author
0 new messages