public void TestMetricsPublisherReset() { // precondition: HystrixMetricsPublisherFactory class is not loaded. Calling HystrixPlugins.reset() here should be good enough to run this with other tests. // set first custom publisher IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("key"); IHystrixMetricsPublisherCommand firstCommand = new HystrixMetricsPublisherCommandDefault(key, null, null, null, null); HystrixMetricsPublisher firstPublisher = new CustomPublisher(firstCommand); HystrixPlugins.RegisterMetricsPublisher(firstPublisher); // ensure that first custom publisher is used IHystrixMetricsPublisherCommand cmd = HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForCommand(key, null, null, null, null); Assert.True(firstCommand == cmd); // reset, then change to second custom publisher HystrixPlugins.Reset(); IHystrixMetricsPublisherCommand secondCommand = new HystrixMetricsPublisherCommandDefault(key, null, null, null, null); HystrixMetricsPublisher secondPublisher = new CustomPublisher(secondCommand); HystrixPlugins.RegisterMetricsPublisher(secondPublisher); // ensure that second custom publisher is used cmd = HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForCommand(key, null, null, null, null); Assert.True(firstCommand != cmd); Assert.True(secondCommand == cmd); }
internal IHystrixMetricsPublisherCommand GetPublisherForCommand(IHystrixCommandKey commandKey, IHystrixCommandGroupKey commandOwner, HystrixCommandMetrics metrics, IHystrixCircuitBreaker circuitBreaker, IHystrixCommandOptions properties) { return(commandPublishers.GetOrAddEx(commandKey.Name, (k) => { IHystrixMetricsPublisherCommand newPublisher = HystrixPlugins.MetricsPublisher.GetMetricsPublisherForCommand(commandKey, commandOwner, metrics, circuitBreaker, properties); newPublisher.Initialize(); return newPublisher; })); }
public CustomPublisher(IHystrixMetricsPublisherCommand commandToReturn) { this.commandToReturn = commandToReturn; }