You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is that HystrixMetricsPublisherFactory caches the reference to HystrixMetricsPublisher.
Also it's not possible to really reset it because HystrixMetricsPublisherFactory.INSTANCE must not be null and creating HystrixMetricsPublisherFactory instance calls HystrixPlugins.getMetricsPublisher() which sets metrics publisher to default implementation.
One way to fix it would be to remove HystrixMetricsPublisherFactory.strategy and always call HystrixPlugins.getInstance().getMetricsPublisher() instead.
Test case reproducing this issue:
packagecom.netflix.hystrix.strategy.metrics;
importstaticorg.junit.Assert.assertNotSame;
importstaticorg.junit.Assert.assertSame;
importorg.junit.Test;
importcom.netflix.hystrix.HystrixCircuitBreaker;
importcom.netflix.hystrix.HystrixCommandGroupKey;
importcom.netflix.hystrix.HystrixCommandKey;
importcom.netflix.hystrix.HystrixCommandMetrics;
importcom.netflix.hystrix.HystrixCommandProperties;
importcom.netflix.hystrix.strategy.HystrixPlugins;
publicclassFactoryResetTest {
staticclassCustomPublisherextendsHystrixMetricsPublisher{
privateHystrixMetricsPublisherCommandcommandToReturn;
publicCustomPublisher(HystrixMetricsPublisherCommandcommandToReturn){
this.commandToReturn = commandToReturn;
}
@OverridepublicHystrixMetricsPublisherCommandgetMetricsPublisherForCommand(HystrixCommandKeycommandKey,
HystrixCommandGroupKeycommandGroupKey, HystrixCommandMetricsmetrics, HystrixCircuitBreakercircuitBreaker,
HystrixCommandPropertiesproperties) {
returncommandToReturn;
}
}
@TestpublicvoidtestMetricsPublisherReset() {
// precondition: HystrixMetricsPublisherFactory class is not loaded. Calling HystrixPlugins.reset() here should be good enough to run this with other tests. // set first custom publisherHystrixCommandKeykey = HystrixCommandKey.Factory.asKey("key");
HystrixMetricsPublisherCommandfirstCommand = newHystrixMetricsPublisherCommandDefault(key, null, null, null, null);
HystrixPlugins.getInstance().registerMetricsPublisher(newCustomPublisher(firstCommand));
// ensure that first custom publisher is used HystrixMetricsPublisherCommandcmd = HystrixMetricsPublisherFactory.createOrRetrievePublisherForCommand(key, null, null, null, null);
assertSame(firstCommand, cmd);
// reset, then change to second custom publisherHystrixPlugins.reset();
HystrixMetricsPublisherCommandsecondCommand = newHystrixMetricsPublisherCommandDefault(key, null, null, null, null);
HystrixPlugins.getInstance().registerMetricsPublisher(newCustomPublisher(secondCommand));
// ensure that second custom publisher is used cmd = HystrixMetricsPublisherFactory.createOrRetrievePublisherForCommand(key, null, null, null, null);
assertNotSame(firstCommand, cmd);
assertSame(secondCommand, cmd);
}
}
The text was updated successfully, but these errors were encountered:
…ly for openjdk 7 in Travis(java 8 worked fine in Travis). Need to update some related dependencies to stable version (not RC) as they included this change Netflix/Hystrix#455
The problem is that HystrixMetricsPublisherFactory caches the reference to HystrixMetricsPublisher.
Also it's not possible to really reset it because HystrixMetricsPublisherFactory.INSTANCE must not be null and creating HystrixMetricsPublisherFactory instance calls HystrixPlugins.getMetricsPublisher() which sets metrics publisher to default implementation.
One way to fix it would be to remove HystrixMetricsPublisherFactory.strategy and always call HystrixPlugins.getInstance().getMetricsPublisher() instead.
Test case reproducing this issue:
The text was updated successfully, but these errors were encountered: