circuitbox 1.1.0 → 2.0.0.pre4

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 (38) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +56 -187
  3. data/lib/circuitbox.rb +14 -57
  4. data/lib/circuitbox/circuit_breaker.rb +137 -161
  5. data/lib/circuitbox/circuit_breaker/logger_messages.rb +31 -0
  6. data/lib/circuitbox/configuration.rb +51 -0
  7. data/lib/circuitbox/errors/error.rb +3 -2
  8. data/lib/circuitbox/errors/open_circuit_error.rb +3 -1
  9. data/lib/circuitbox/errors/service_failure_error.rb +5 -1
  10. data/lib/circuitbox/excon_middleware.rb +23 -30
  11. data/lib/circuitbox/faraday_middleware.rb +43 -63
  12. data/lib/circuitbox/memory_store.rb +85 -0
  13. data/lib/circuitbox/memory_store/container.rb +30 -0
  14. data/lib/circuitbox/memory_store/monotonic_time.rb +13 -0
  15. data/lib/circuitbox/notifier/active_support.rb +19 -0
  16. data/lib/circuitbox/notifier/null.rb +13 -0
  17. data/lib/circuitbox/timer.rb +51 -0
  18. data/lib/circuitbox/version.rb +3 -1
  19. metadata +106 -118
  20. data/.gitignore +0 -20
  21. data/.ruby-version +0 -1
  22. data/.travis.yml +0 -9
  23. data/Gemfile +0 -6
  24. data/Rakefile +0 -18
  25. data/benchmark/circuit_store_benchmark.rb +0 -114
  26. data/circuitbox.gemspec +0 -48
  27. data/lib/circuitbox/memcache_store.rb +0 -31
  28. data/lib/circuitbox/notifier.rb +0 -34
  29. data/test/circuit_breaker_test.rb +0 -428
  30. data/test/circuitbox_test.rb +0 -45
  31. data/test/excon_middleware_test.rb +0 -131
  32. data/test/faraday_middleware_test.rb +0 -175
  33. data/test/integration/circuitbox_cross_process_open_test.rb +0 -56
  34. data/test/integration/faraday_middleware_test.rb +0 -78
  35. data/test/integration_helper.rb +0 -48
  36. data/test/notifier_test.rb +0 -21
  37. data/test/service_failure_error_test.rb +0 -23
  38. 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
-
6
- class NotifierTest < Minitest::Test
7
- def test_sends_notification_on_notify
8
- ActiveSupport::Notifications.expects(:instrument).with("circuit_open", circuit: 'yammer:12')
9
- Circuitbox::Notifier.new(:yammer, 12).notify(:open)
10
- end
11
-
12
- def test_sends_warning_notificaiton_notify_warning
13
- ActiveSupport::Notifications.expects(:instrument).with("circuit_warning", { circuit: 'yammer:12', message: 'hello'})
14
- Circuitbox::Notifier.new(:yammer, 12).notify_warning('hello')
15
- end
16
-
17
- def test_sends_metric_as_notification
18
- ActiveSupport::Notifications.expects(:instrument).with("circuit_gauge", { circuit: 'yammer:12', gauge: 'ratio', value: 12})
19
- Circuitbox::Notifier.new(:yammer, 12).metric_gauge(:ratio, 12)
20
- end
21
- end
@@ -1,23 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ServiceFailureErrorTest < Minitest::Test
4
- class SomeOtherError < StandardError; end;
5
-
6
- attr_reader :error
7
-
8
- def setup
9
- raise SomeOtherError, "some other error"
10
- rescue => ex
11
- @error = ex
12
- end
13
-
14
- def test_includes_the_message_of_the_wrapped_exception
15
- ex = Circuitbox::ServiceFailureError.new('test', error)
16
- assert_equal "Circuitbox::ServiceFailureError wrapped: #{error}", ex.to_s
17
- end
18
-
19
- def test_keeps_the_original_backtrace
20
- ex = Circuitbox::ServiceFailureError.new('test', error)
21
- assert_equal error.backtrace, ex.backtrace
22
- end
23
- 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