class Toxiproxy::ProxyCollection
ProxyCollection
represents a set of proxies. This allows to easily perform actions on every proxy in the collection.
Unfortunately, it doesn't implement all of Enumerable because there's no way to subclass an Array or include Enumerable for the methods to return a Collection instead of an Array (see MRI). Instead, we delegate methods where it doesn't matter and only allow the filtering methods that really make sense on a proxy collection.
Constants
- DEFINED_METHODS
- DELEGATED_METHODS
- METHODS
Public Class Methods
# File lib/toxiproxy/proxy_collection.rb, line 19 def initialize(collection) @collection = collection end
Public Instance Methods
Destroys all toxiproxy's in the collection
# File lib/toxiproxy/proxy_collection.rb, line 60 def destroy @collection.each(&:destroy) end
# File lib/toxiproxy/proxy_collection.rb, line 51 def disable @collection.each(&:disable) end
Sets every proxy in the collection as down. For example:
Toxiproxy.grep(/redis/).down { .. }
Would simulate every Redis server being down for the duration of the block.
# File lib/toxiproxy/proxy_collection.rb, line 29 def down(&block) @collection.inject(block) { |nested, proxy| -> { proxy.down(&nested) } }.call end
Set a downstream toxic.
# File lib/toxiproxy/proxy_collection.rb, line 43 def downstream(toxic, attrs = {}) toxics = ToxicCollection.new(@collection) toxics.downstream(toxic, attrs) toxics end
# File lib/toxiproxy/proxy_collection.rb, line 55 def enable @collection.each(&:enable) end
Grep allows easily selecting a subset of proxies, by returning a ProxyCollection
with every proxy name matching the regex passed.
# File lib/toxiproxy/proxy_collection.rb, line 74 def grep(regex) self.class.new(@collection.select { |proxy| proxy.name =~ regex }) end
# File lib/toxiproxy/proxy_collection.rb, line 68 def reject(&block) self.class.new(@collection.reject(&block)) end
# File lib/toxiproxy/proxy_collection.rb, line 64 def select(&block) self.class.new(@collection.select(&block)) end
Set an upstream toxic.
# File lib/toxiproxy/proxy_collection.rb, line 36 def upstream(toxic, attrs = {}) toxics = ToxicCollection.new(@collection) toxics.upstream(toxic, attrs) toxics end