コード例 #1
0
  @Before
  public void init() {
    for (HystrixCommandMetrics metricsInstance : HystrixCommandMetrics.getInstances()) {
      metricsInstance.resetStream();
    }

    HystrixCommandMetrics.reset();
    HystrixCircuitBreaker.Factory.reset();
    Hystrix.reset();
  }
コード例 #2
0
 // ignoring since this never ends ... useful for testing
 // https://github.com/Netflix/Hystrix/issues/236
 @Ignore
 @Test
 public void testSuccessClosesCircuitWhenBusy() throws InterruptedException {
   HystrixPlugins.getInstance().registerCommandExecutionHook(new MyHystrixCommandExecutionHook());
   try {
     performLoad(200, 0, 40);
     performLoad(250, 100, 40);
     performLoad(600, 0, 40);
   } finally {
     Hystrix.reset();
   }
 }
コード例 #3
0
  private static void runLoopTest() throws InterruptedException {
    final int commandsToRun = 50000;
    for (int number = 0; number < commandsToRun; number++) {
      try {
        ExampleCollapserCmd collapser = new ExampleCollapserCmd(number);
        Observable<Boolean> observable = collapser.toObservable();
        observable.subscribe(
            new Observer<Boolean>() {
              @Override
              public void onCompleted() {}

              @Override
              public void onError(Throwable e) {
                commandErrors.incrementAndGet();
              }

              @Override
              public void onNext(Boolean result) {
                if (result) {
                  commandSuccesses.incrementAndGet();
                } else {
                  commandErrors.incrementAndGet();
                }
              }
            });
      } catch (Exception e) {
        LOG.debug("Exception = ", e);
      }

      Thread.sleep(1);
    }

    while (getTotalWaitingCommands() > 0) {
      CLOG.info("Waiting for Hystrix pool to finish all jobs");
      Thread.sleep(500);
    }

    CLOG.info("Successful command runs = {}", commandSuccesses.get());
    CLOG.info("Failure command runs = {}", commandErrors.get());

    // For good measure.  Occassionally hystrix threads won't clean up.
    Hystrix.reset();
  }