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

new(collection) click to toggle source
# File lib/toxiproxy/proxy_collection.rb, line 19
def initialize(collection)
  @collection = collection
end

Public Instance Methods

destroy() click to toggle source

Destroys all toxiproxy's in the collection

# File lib/toxiproxy/proxy_collection.rb, line 60
def destroy
  @collection.each(&:destroy)
end
disable() click to toggle source
# File lib/toxiproxy/proxy_collection.rb, line 51
def disable
  @collection.each(&:disable)
end
down(&block) click to toggle source

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
downstream(toxic, attrs = {}) click to toggle source

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
Also aliased as: toxicate, toxic
enable() click to toggle source
# File lib/toxiproxy/proxy_collection.rb, line 55
def enable
  @collection.each(&:enable)
end
grep(regex) click to toggle source

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
reject(&block) click to toggle source
# File lib/toxiproxy/proxy_collection.rb, line 68
def reject(&block)
  self.class.new(@collection.reject(&block))
end
select(&block) click to toggle source
# File lib/toxiproxy/proxy_collection.rb, line 64
def select(&block)
  self.class.new(@collection.select(&block))
end
toxic(toxic, attrs = {})
Alias for: downstream
toxicate(toxic, attrs = {})
Alias for: downstream
upstream(toxic, attrs = {}) click to toggle source

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