circuitbox 1.0.3 → 2.0.0.pre3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +68 -122
  3. data/lib/circuitbox.rb +12 -56
  4. data/lib/circuitbox/circuit_breaker.rb +133 -154
  5. data/lib/circuitbox/circuit_breaker/logger_messages.rb +31 -0
  6. data/lib/circuitbox/configuration.rb +55 -0
  7. data/lib/circuitbox/errors/error.rb +1 -2
  8. data/lib/circuitbox/errors/open_circuit_error.rb +0 -1
  9. data/lib/circuitbox/errors/service_failure_error.rb +2 -1
  10. data/lib/circuitbox/excon_middleware.rb +15 -24
  11. data/lib/circuitbox/faraday_middleware.rb +38 -61
  12. data/lib/circuitbox/memory_store.rb +84 -0
  13. data/lib/circuitbox/memory_store/container.rb +28 -0
  14. data/lib/circuitbox/memory_store/monotonic_time.rb +11 -0
  15. data/lib/circuitbox/notifier/active_support.rb +19 -0
  16. data/lib/circuitbox/notifier/null.rb +11 -0
  17. data/lib/circuitbox/timer/monotonic.rb +17 -0
  18. data/lib/circuitbox/timer/null.rb +9 -0
  19. data/lib/circuitbox/timer/simple.rb +13 -0
  20. data/lib/circuitbox/version.rb +1 -1
  21. metadata +81 -149
  22. data/.gitignore +0 -20
  23. data/.ruby-version +0 -1
  24. data/.travis.yml +0 -8
  25. data/Gemfile +0 -6
  26. data/Rakefile +0 -18
  27. data/benchmark/circuit_store_benchmark.rb +0 -114
  28. data/circuitbox.gemspec +0 -38
  29. data/lib/circuitbox/memcache_store.rb +0 -31
  30. data/lib/circuitbox/notifier.rb +0 -34
  31. data/test/circuit_breaker_test.rb +0 -449
  32. data/test/circuitbox_test.rb +0 -54
  33. data/test/excon_middleware_test.rb +0 -131
  34. data/test/faraday_middleware_test.rb +0 -175
  35. data/test/integration/circuitbox_cross_process_open_test.rb +0 -56
  36. data/test/integration/faraday_middleware_test.rb +0 -78
  37. data/test/integration_helper.rb +0 -48
  38. data/test/notifier_test.rb +0 -21
  39. data/test/service_failure_error_test.rb +0 -30
  40. data/test/test_helper.rb +0 -15
@@ -1,48 +0,0 @@
1
- require "test_helper"
2
- require "faraday"
3
- require "circuitbox/faraday_middleware"
4
- require "rack"
5
-
6
- class FakeServer
7
- def self.instance
8
- @@instance ||= FakeServer.new
9
- # if the FakeServer is used kill all of them after the tests are done
10
- Minitest.after_run { FakeServer.shutdown }
11
- @@instance
12
- end
13
-
14
- def initialize
15
- @servers = []
16
- end
17
-
18
- def self.create(port, result)
19
- FakeServer.instance.create(port, result)
20
- end
21
-
22
- def self.shutdown
23
- FakeServer.instance.shutdown
24
- end
25
-
26
- def shutdown
27
- @servers.map { |server| server.exit }
28
- @servers = []
29
- end
30
-
31
- def create(port, result)
32
- @servers << Thread.new do
33
- Rack::Handler::WEBrick.run(Proc.new { |env| result },
34
- Port: port,
35
- AccessLog: [],
36
- Logger: WEBrick::Log.new(DEV_NULL))
37
- end
38
- sleep 0.5 # wait for the server to spin up
39
- end
40
- end
41
-
42
- module IntegrationHelpers
43
- def open_circuit(c = connection)
44
- volume_threshold = Circuitbox::CircuitBreaker::DEFAULTS[:volume_threshold]
45
- (volume_threshold + 1).times { c.get(failure_url) }
46
- end
47
- end
48
-
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
- require 'circuitbox/notifier'
3
- require 'active_support/notifications'
4
-
5
- describe Circuitbox::Notifier do
6
- it "[notify] sends an ActiveSupport::Notification" do
7
- ActiveSupport::Notifications.expects(:instrument).with("circuit_open", circuit: 'yammer:12')
8
- Circuitbox::Notifier.new(:yammer, 12).notify(:open)
9
- end
10
-
11
- it "[notify_warning] sends an ActiveSupport::Notification" do
12
- ActiveSupport::Notifications.expects(:instrument).with("circuit_warning", { circuit: 'yammer:12', message: 'hello'})
13
- Circuitbox::Notifier.new(:yammer, 12).notify_warning('hello')
14
- end
15
-
16
- it '[gauge] sends an ActiveSupport::Notifier' do
17
- ActiveSupport::Notifications.expects(:instrument).with("circuit_gauge", { circuit: 'yammer:12', gauge: 'ratio', value: 12})
18
- Circuitbox::Notifier.new(:yammer, 12).metric_gauge(:ratio, 12)
19
-
20
- end
21
- end
@@ -1,30 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Circuitbox::ServiceFailureError do
4
- class SomeOtherError < StandardError; end;
5
-
6
- attr_reader :error
7
-
8
- before do
9
- begin
10
- raise SomeOtherError, "some other error"
11
- rescue => ex
12
- @error = ex
13
- end
14
- end
15
-
16
- describe '#to_s' do
17
- it 'includes message for wrapped exception' do
18
- ex = Circuitbox::ServiceFailureError.new('test', error)
19
- assert_equal "Circuitbox::ServiceFailureError wrapped: #{error}", ex.to_s
20
- end
21
- end
22
-
23
- describe '#backtrace' do
24
- it 'keeps the original exception backtrace' do
25
- ex = Circuitbox::ServiceFailureError.new('test', error)
26
- assert_equal error.backtrace, ex.backtrace
27
- end
28
- end
29
-
30
- end
@@ -1,15 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'mocha/mini_test'
3
- require 'timecop'
4
- require 'gimme'
5
- require 'circuitbox'
6
-
7
- DEV_NULL = (RUBY_PLATFORM =~ /mswin|mingw/ ? "NUL" : "/dev/null")
8
-
9
- class Circuitbox
10
- class CircuitBreaker
11
- def logger
12
- @_dev_null_logger ||= Logger.new(DEV_NULL)
13
- end
14
- end
15
- end