perkss
perkss

Reputation: 1067

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?

Upvotes: 2

Views: 3707

Answers (2)

MohammadMH
MohammadMH

Reputation: 99

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();```

Upvotes: 0

Robert Winkler
Robert Winkler

Reputation: 1907

No, at the moment there is no way to set it via a property. But it's simple in tests. Do you use any framework like Spring Boot? If you use Spring Boot, you can inject the CircuitBreakerRegistry into your test. Retrieve the CircuitBreaker instance and transition to OPEN, before running the test.

Upvotes: 5

Related Questions