circuitbox 1.1.1 → 2.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +60 -122
- data/lib/circuitbox.rb +15 -52
- data/lib/circuitbox/circuit_breaker.rb +131 -141
- data/lib/circuitbox/circuit_breaker/logger_messages.rb +31 -0
- data/lib/circuitbox/configuration.rb +53 -0
- data/lib/circuitbox/errors/error.rb +1 -2
- data/lib/circuitbox/errors/open_circuit_error.rb +0 -1
- data/lib/circuitbox/errors/service_failure_error.rb +2 -1
- data/lib/circuitbox/excon_middleware.rb +15 -24
- data/lib/circuitbox/faraday_middleware.rb +35 -61
- data/lib/circuitbox/memory_store.rb +76 -0
- data/lib/circuitbox/memory_store/compactor.rb +35 -0
- data/lib/circuitbox/memory_store/container.rb +28 -0
- data/lib/circuitbox/memory_store/monotonic_time.rb +11 -0
- data/lib/circuitbox/notifier/active_support.rb +19 -0
- data/lib/circuitbox/notifier/null.rb +11 -0
- data/lib/circuitbox/timer/monotonic.rb +17 -0
- data/lib/circuitbox/timer/null.rb +9 -0
- data/lib/circuitbox/timer/simple.rb +13 -0
- data/lib/circuitbox/version.rb +1 -1
- metadata +78 -150
- data/.gitignore +0 -20
- data/.ruby-version +0 -1
- data/.travis.yml +0 -9
- data/Gemfile +0 -6
- data/Rakefile +0 -30
- data/benchmark/circuit_store_benchmark.rb +0 -114
- data/circuitbox.gemspec +0 -48
- data/lib/circuitbox/notifier.rb +0 -34
- data/test/circuit_breaker_test.rb +0 -436
- data/test/circuitbox_test.rb +0 -45
- data/test/excon_middleware_test.rb +0 -131
- data/test/faraday_middleware_test.rb +0 -175
- data/test/integration/circuitbox_cross_process_open_test.rb +0 -56
- data/test/integration/faraday_middleware_test.rb +0 -78
- data/test/integration_helper.rb +0 -48
- data/test/notifier_test.rb +0 -21
- data/test/service_failure_error_test.rb +0 -23
- data/test/test_helper.rb +0 -15
data/test/integration_helper.rb
DELETED
@@ -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
|
-
|
data/test/notifier_test.rb
DELETED
@@ -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
|
data/test/test_helper.rb
DELETED
@@ -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
|