Class: ScenarioD

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

Instance Method Summary collapse

Methods inherited from Scenario

register

Instance Method Details

#run(clients) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/scenario.rb', line 89

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

  rand_clients = clients.sort_by { rand }

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

  slave_dbs.each do |slave_db|
    slave_db.msg 't' => 'ROLE', 'role' => 'db', 'slaves' => [], 'slave' => true
  end

  master_db.msg 't' => 'ROLE', 'role' => 'db', 'slaves' => slave_dbs.map { |n| n.addr }

  stats.msg 't' => 'ROLE', 'role' => 'stats', 'db_read' => slave_dbs.map { |n| n.addr }

  rails_nodes.each do |rails|
    rails.msg 't' => 'ROLE', 'role' => 'rails', 'db_write' => [master_db.addr], 'db_read' => slave_dbs.map { |n| n.addr }
  end

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