Class: ScenarioB

Inherits:
Scenario show all
Defined in:
lib/scenario.rb

Instance Method Summary collapse

Methods inherited from Scenario

register

Instance Method Details

#run(clients) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/scenario.rb', line 35

def run(clients)
  clients.each do |client|
    client.msg 't' => 'STOP'
  end

  rand_clients = clients.sort_by { rand }

  proxy = rand_clients.pop
  db = rand_clients.pop
  rails_nodes = rand_clients.slice!(0,5) # up to 5 of the rest get to be rails nodes

  db.msg 't' => 'ROLE', 'role' => 'db', 'slaves' => []

  rails_nodes.each do |rails|
    rails.msg 't' => 'ROLE', 'role' => 'rails', 'db_write' => [db.addr], 'db_read' => [db.addr]
  end

  proxy.msg 't' => 'ROLE', 'role' => 'proxy', 'backends' => rails_nodes.map { |n| n.addr }
end