Skip to content

Commit

Permalink
Ruby-478 cluster setup "kind" processing is order significant - fix f…
Browse files Browse the repository at this point in the history
…or Ruby 1.8.7, also more tests for server options
  • Loading branch information
gjmurakami-10gen committed Oct 15, 2012
1 parent f8c5edf commit fc86fa3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
24 changes: 19 additions & 5 deletions test/tools/mongo_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.cluster(opts = DEFAULT_SHARDED_SIMPLE)
raise "missing required option" if [:host, :dbpath].any?{|k| !opts[k]}

config = opts.reject {|k,v| CLUSTER_OPT_KEYS.include?(k)}
kinds = opts.keys.select {|k| CLUSTER_OPT_KEYS.include?(k)}
kinds = CLUSTER_OPT_KEYS.select{|key| opts.has_key?(key)} # order is significant

kinds.each do |kind|
config[kind] = opts.fetch(kind,1).times.collect do |i| #default to 1 of whatever
Expand Down Expand Up @@ -349,9 +349,7 @@ def arbiter_names

def members_by_name(names)
names.collect do |name|
host, port = name.split(':')
port = port.to_i
servers.find{|server| server.host == host && server.port == port}
servers.find{|server| server.host_port == name}
end.compact
end

Expand All @@ -371,8 +369,24 @@ def arbiters
members_by_name(arbiter_names)
end

def config_names_by_kind(kind)
@config[kind].collect{|conf| "#{conf[:host]}:#{conf[:port]}"}
end

def shards
members_by_name(config_names_by_kind(:shards))
end

def configs
members_by_name(config_names_by_kind(:configs))
end

def routers
members_by_name(config_names_by_kind(:routers))
end

def mongos_seeds
@config[:routers].collect{|router| "#{router[:host]}:#{router[:port]}"}
config_names_by_kind(:routers)
end

def ismaster
Expand Down
28 changes: 16 additions & 12 deletions test/tools/mongo_config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,27 @@ def cluster_test(opts)

test "cluster manager replica set" do
cluster_test(Mongo::Config::DEFAULT_REPLICA_SET) do |manager|
server = manager.replicas.first
assert_not_nil(Mongo::Connection.new(server.host, server.port))
assert_match(/oplogSize/, server.cmd, '--oplogSize option should be specified')
assert_match(/smallfiles/, server.cmd, '--smallfiles option should be specified')
assert_no_match(/nojournal/, server.cmd, '--nojournal option should not be specified')
assert_match(/noprealloc/, server.cmd, '--noprealloc option should be specified')
servers = manager.servers
servers.each do |server|
assert_not_nil(Mongo::Connection.new(server.host, server.port))
assert_match(/oplogSize/, server.cmd, '--oplogSize option should be specified')
assert_match(/smallfiles/, server.cmd, '--smallfiles option should be specified')
assert_no_match(/nojournal/, server.cmd, '--nojournal option should not be specified')
assert_match(/noprealloc/, server.cmd, '--noprealloc option should be specified')
end
end
end

test "cluster manager sharded simple" do
cluster_test(Mongo::Config::DEFAULT_SHARDED_SIMPLE) do |manager|
server = manager.servers.first #TODO - assertions on configs
assert_not_nil(Mongo::Connection.new(server.host, server.port))
assert_match(/oplogSize/, server.cmd, '--oplogSize option should be specified')
assert_match(/smallfiles/, server.cmd, '--smallfiles option should be specified')
assert_no_match(/nojournal/, server.cmd, '--nojournal option should not be specified')
assert_match(/noprealloc/, server.cmd, '--noprealloc option should be specified')
servers = manager.shards + manager.configs
servers.each do |server|
assert_not_nil(Mongo::Connection.new(server.host, server.port))
assert_match(/oplogSize/, server.cmd, '--oplogSize option should be specified')
assert_match(/smallfiles/, server.cmd, '--smallfiles option should be specified')
assert_no_match(/nojournal/, server.cmd, '--nojournal option should not be specified')
assert_match(/noprealloc/, server.cmd, '--noprealloc option should be specified')
end
end
end

Expand Down

0 comments on commit fc86fa3

Please sign in to comment.