我想以编程方式强制断路器为特定组打开。我想我可以通过在组中的命令上设置配置以强制打开并运行该命令来做到这一点。但是,这似乎不起作用。这可能吗?我应该采取不同的方法吗?这是我在第二次 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;}
}
}