@Override public Boolean getValue() { return circuitBreaker.isOpen(); } });
/** * Whether the 'circuit-breaker' is open meaning that <code>execute()</code> will immediately return * the <code>getFallback()</code> response and not attempt a HystrixCommand execution. * * 4 columns are ForcedOpen | ForcedClosed | CircuitBreaker open due to health ||| Expected Result * * T | T | T ||| OPEN (true) * T | T | F ||| OPEN (true) * T | F | T ||| OPEN (true) * T | F | F ||| OPEN (true) * F | T | T ||| CLOSED (false) * F | T | F ||| CLOSED (false) * F | F | T ||| OPEN (true) * F | F | F ||| CLOSED (false) * * @return boolean */ public boolean isCircuitBreakerOpen() { return properties.circuitBreakerForceOpen().get() || (!properties.circuitBreakerForceClosed().get() && circuitBreaker.isOpen()); }
/** * Test that if all 'marks' are timeouts that it will trip the circuit. */ @Test public void testTripCircuitOnTimeouts() { String key = "cmd-D"; try { HystrixCommand<Boolean> cmd1 = new TimeoutCommand(key); HystrixCircuitBreaker cb = cmd1.circuitBreaker; // this should start as allowing requests assertTrue(cb.allowRequest()); assertFalse(cb.isOpen()); // success with high latency cmd1.execute(); HystrixCommand<Boolean> cmd2 = new TimeoutCommand(key); cmd2.execute(); HystrixCommand<Boolean> cmd3 = new TimeoutCommand(key); cmd3.execute(); HystrixCommand<Boolean> cmd4 = new TimeoutCommand(key); cmd4.execute(); // everything has been a timeout so we should not allow any requests Thread.sleep(100); assertFalse(cb.allowRequest()); assertTrue(cb.isOpen()); } catch (Exception e) { e.printStackTrace(); fail("Error occurred: " + e.getMessage()); } }
assertFalse(cb.isOpen()); System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString()); System.out.println("CircuitBreaker state 1 : " + cmd1.getMetrics().getHealthCounts()); assertTrue(cb.isOpen()); assertTrue(cb.isOpen()); assertTrue(cb.allowRequest()); assertFalse(cb.isOpen());
@Override public Boolean getValue() { return circuitBreaker.isOpen(); } });
@Override public Number call() { return HystrixPrometheusMetricsPublisherCommand.this.booleanToNumber(circuitBreaker.isOpen()); } });
@Override public Boolean getValue() { return circuitBreaker.isOpen(); } });
@Override public Boolean value() { return circuitBreaker.isOpen(); } });
@Override public void initialize() { logger.info("JboneHystrixMetricsPublisherCommand initialize start"); logger.info("commandKey: {}",commandKey); logger.info("commandGroupKey: {}",commandGroupKey); logger.info("metrics: {}",metrics.getHealthCounts()); logger.info("circuitBreaker: {}",circuitBreaker.isOpen()); logger.info("properties: {}",properties); logger.info("JboneHystrixMetricsPublisherCommand initialize end."); } }
@Override public int getIsCircuitBreakerOpen() { return Optional.ofNullable(HystrixCircuitBreaker.Factory.getInstance(key)) .map(cb -> cb.isOpen() ? 1 : 0) .orElse(1); }
@Override public void onProcessedError(SimpleCommand command, Exception exception) { runSafely(() -> { HystrixCircuitBreaker cb = command.getCircuitBreaker(); if (cb != null && cb.isOpen() && !isCircuitBreakerOpenBeforeExceptionProcessing) { counterInc(metricsPrefix + MetricNames.CB_OPENED_TOTAL); } if (exception != null && TimeoutException.class.equals(exception.getClass())) { counterInc(metricsPrefix + MetricNames.TIMEOUT_CALLS_TIMED_OUT_TOTAL); } }); }
/** * Whether the 'circuit-breaker' is open meaning that <code>execute()</code> will immediately return * the <code>getFallback()</code> response and not attempt a HystrixCommand execution. * * 4 columns are ForcedOpen | ForcedClosed | CircuitBreaker open due to health ||| Expected Result * * T | T | T ||| OPEN (true) * T | T | F ||| OPEN (true) * T | F | T ||| OPEN (true) * T | F | F ||| OPEN (true) * F | T | T ||| CLOSED (false) * F | T | F ||| CLOSED (false) * F | F | T ||| OPEN (true) * F | F | F ||| CLOSED (false) * * @return boolean */ public boolean isCircuitBreakerOpen() { return properties.circuitBreakerForceOpen().get() || (!properties.circuitBreakerForceClosed().get() && circuitBreaker.isOpen()); }