I would like to programmatically make the circuit breaker open for a specific group. I thought I could do this by setting the configuration in the team in the group to force open it and run this command. However, this does not work. Is it possible? Should I take a different approach? Here the test I tried fails in the second call to assertEquals.
import com.netflix.hystrix.HystrixCommand; import com.netflix.hystrix.HystrixCommandGroupKey; import com.netflix.hystrix.HystrixCommandProperties; import org.junit.Test; import static org.junit.Assert.assertEquals; public class ForceCircuitBreakerCommandTest { @Test public void testForceOpen(){ assertEquals(Boolean.TRUE, new FakeCommand().execute()); new OpenCircuitBreakerCommand().execute(); assertEquals(Boolean.FALSE, new FakeCommand().execute()); } private class FakeCommand extends HystrixCommand<Boolean> { public FakeCommand(){ super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("TestGroup"))); } @Override public Boolean run(){return Boolean.TRUE;} @Override public Boolean getFallback() {return Boolean.FALSE;} } private class OpenCircuitBreakerCommand extends HystrixCommand<Boolean> { public OpenCircuitBreakerCommand(){ super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("TestGroup")) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withCircuitBreakerForceOpen(true))); } @Override public Boolean run(){return Boolean.TRUE;} @Override public Boolean getFallback() {return Boolean.FALSE;} } }
source share