title: Hystrix Circuit Breaker won't open?
body: <p>I'm trying to learn how to use Hystrix. I've created this class below:</p>
  
  <pre><code>public class CommandReturnAllExceptFive extends HystrixCommand&lt;Integer&gt; {
      public static final Integer SLEEP_TIME = 5000;
  
      private Integer x;
  
      public CommandReturnAllExceptFive(Integer x) {
          super(getHystrixConfiguration());
          this.x = x;
          System.out.println("Is circuit breaker open? " + (this.circuitBreaker.isOpen() ? "yes" : "no"));
          System.out.println("Requests so far: "+(this.metrics.getRollingCount(HystrixEventType.FAILURE)));
      }
  
      public void setX(Integer x) {
          this.x = x;
      }
  
      private static HystrixCommand.Setter getHystrixConfiguration() {
          HystrixCommandProperties.Setter properties
                  = HystrixCommandProperties.Setter()
                  .withCircuitBreakerSleepWindowInMilliseconds(SLEEP_TIME)
                  .withCircuitBreakerEnabled(true)
                  .withCircuitBreakerRequestVolumeThreshold(1)
                  .withCircuitBreakerErrorThresholdPercentage(1)
                  .withMetricsRollingStatisticalWindowBuckets(1)
                  .withMetricsRollingStatisticalWindowBuckets(1);
          HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("ReturnAllExceptFive");
          return HystrixCommand.Setter.withGroupKey(groupKey).andCommandPropertiesDefaults(properties);
      }
      protected Integer run() throws Exception {
          if (x == 5) {
              throw new Exception();
          }
  
          return x;
      }
  }
  </code></pre>
  
  <p>with the following unit test:</p>
  
  <pre><code>   @Test
      public void testCommandReturnAllExceptFive_doesStallBeforeCallingAgain() {
          boolean exceptionIsThrown = false;
          try {
              CommandReturnAllExceptFive returnAllExceptFive = new CommandReturnAllExceptFive(5);
              returnAllExceptFive.execute();
          } catch (Exception ex) {
              exceptionIsThrown = true;
          }
          assertThat(exceptionIsThrown, is(true));
  
          long timeNow = System.currentTimeMillis();
  
          boolean callIsSuccessful = false;
          while (!callIsSuccessful) {
              try {
                  CommandReturnAllExceptFive returnAllExceptFive = new CommandReturnAllExceptFive(1);
                  returnAllExceptFive.execute();
                  callIsSuccessful = true;
              } catch (Exception ex) {
  
              }
          }
          long timeAfter = System.currentTimeMillis();
  
          long timeToSuccess = timeAfter - timeNow;
          System.out.println("timeNow: "+timeNow+"\ntimeAfter: "+timeAfter);
          //assertThat(timeToSuccess &gt;= CommandReturnAllExceptFive.SLEEP_TIME, is(true));
      }
  </code></pre>
  
  <p>which is basically verifying that the call fails at 5, and that it does stall for the specified period of time after a successful execution. The debugging statements indicate that the circuit is never closed, but it should be closed after the first call since that one throws an exception, hence indicating failure. Can anyone help me out here?</p>