Giter Site home page Giter Site logo

Comments (10)

chhsiao90 avatar chhsiao90 commented on August 19, 2024

Maybe try breaker.initialize() before use it.
And I notice that the CircuitBreakerProvider in the referenced issue that seams solved this problem too.

break.open()
break.close()

But I think there is some other better way then throw NPE here.

  • give the CircuitBreaker close state whenever a new CircuitBreaker create
  • throw IllegalStateException when CircuitBreaker not initialized

from failsafe.

chhsiao90 avatar chhsiao90 commented on August 19, 2024

Maybe try breaker.initialize() before use it.

Sorry, I hadn't noticed that this method is in package scope...
Currently, call close after open is the only way to use the CircuitBreaker in a standalone way

from failsafe.

danpersa avatar danpersa commented on August 19, 2024

yes, that's the workaround I used.

from failsafe.

jhalterman avatar jhalterman commented on August 19, 2024

Thanks for filing. The appropriate workaround for now:

CircuitBreaker breaker = new CircuitBreaker();
breaker.close();

from failsafe.

chhsiao90 avatar chhsiao90 commented on August 19, 2024

Hi @jhalterman

Currently, call breaker.close() just after constructor cannot work,
because breaker.close() will call transitionTo that will determine that the new state is same as previous state, so it would not change the state to closed and still remain the state be null.

I had some modification on this.
Please see 2400b2e24f128ca5d9291daf11d95fe048782f7e

  • Allow close() call just after construct
  • Add unit test on CircuitBreaker
    Because the document said that it's recommended to used CircuitBreaker in standalone way,
    so I think only test on how CircuitBreak be config seams not enough, so I had some additional test on it
  • Removed unused if (state != null) because the state will always not be null
  • Throw IllegalStateException while state is not in a consist state

The commit still not ready for PR.
Though the test is pass, but I should make sure that there is no side effect was bring in.
And I will need more time to add more test on CircuitBreaker.

from failsafe.

jhalterman avatar jhalterman commented on August 19, 2024

Hi @chhsiao90

I was actually working on this too... I think what I'd like is for CircuitBreaker to default to closed state. With the current code, we can't just close() the circuit after construction though because it still needs to be configured (ex: withSuccessThreshold) since the configuration is used by the ClosedState. This is too restrictive. Once I fix this, later today, I'll push my changes. I'd like to still pickup your test cases though since those look good, if you want to submit them afterwords.

from failsafe.

chhsiao90 avatar chhsiao90 commented on August 19, 2024

Got it, I will help about the unit test after you!

from failsafe.

danpersa avatar danpersa commented on August 19, 2024

I like the idea with having the default state to closed.

from failsafe.

chhsiao90 avatar chhsiao90 commented on August 19, 2024

Hi @jhalterman

I just find that how CircuitBreaker change d unit test had bean wrote at the state test, like OpenStateTest.
And it seems good enough for this situation.

from failsafe.

jhalterman avatar jhalterman commented on August 19, 2024

CircuitBreaker now defaults to closed and can be reconfigured (via withSuccessThreshold, withFailureThreshold) at any time. Any executions that were recorded from a prior configuration will be carried over.

from failsafe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.