javacircuit-breakerresilience4j

Resilience4j Circuit Breaker property to force open


I can see that I can programmatically set the state to force open like so using the following code: CircuitBreaker Forced Open State

But is there a way to set a property to set the state to this immediately when the application starts, so it can be used with tests?


Solution

  • Update: Nowadays there is methods to transition

    https://github.com/resilience4j/resilience4j/blob/d6a1833251e0a35fe4d9ca9c31bdf19784c99e2b/resilience4j-circuitbreaker/src/main/java/io/github/resilience4j/circuitbreaker/CircuitBreaker.java#L158

         * Transitions the state machine to CLOSED state.
         *
         * Should only be used, when you want to force a state transition. State transition are normally done internally.
         */
        void transitionToClosedState();
    
        /**
         * Transitions the state machine to OPEN state.
         *
         * Should only be used, when you want to force a state transition. State transition are normally done internally.
         */
        void transitionToOpenState();
    
        /**
         * Transitions the state machine to HALF_OPEN state.
         *
         * Should only be used, when you want to force a state transition. State transition are normally done internally.
         */
        void transitionToHalfOpenState();
    
        /**
         * Transitions the state machine to a DISABLED state, stopping state transition, metrics and event publishing.
         *
         * Should only be used, when you want to disable the circuit breaker allowing all calls to pass.
         * To recover from this state you must force a new state transition
         */
        void transitionToDisabledState();```