Permalink
Browse files

RUBY-478 arbiter framework, in progress, hash.merge! fixes

  • Loading branch information...
1 parent 0e7ed88 commit 6bb0cdcf5b85f071d643a264f4f2feaa679fb0ac @gjmurakami-10gen gjmurakami-10gen committed Oct 4, 2012
Showing with 34 additions and 11 deletions.
  1. +12 −0 README.md
  2. +4 −3 test/replica_set/basic_test.rb
  3. +3 −4 test/test_helper.rb
  4. +15 −4 test/tools/mongo_config.rb
View
@@ -331,6 +331,18 @@ If you want to test replica set, you can run the following task:
$ rake test:rs
+To run a single test at the top level, add -Itest since we no longer modify LOAD_PATH:
+
+ $ ruby -Itest test/bson/bson_test.rb
+
+To run a single test from the test directory, add -I. since we no longer modify LOAD_PATH:
+
+ $ ruby -I. bson/bson_test.rb
+
+To run a single test from its subdirectory, add -I.. since we no longer modify LOAD_PATH:
+
+ $ ruby -I.. bson_test.rb
+
# Release Notes
See HISTORY.
@@ -1,4 +1,5 @@
require 'test_helper'
+require 'pp'
class BasicTest < Test::Unit::TestCase
def setup
@@ -7,16 +8,16 @@ def setup
def self.shutdown
@@cluster.stop
- @@cluster.clobber
+ #@@cluster.clobber
end
# TODO member.primary? ==> true
# To reset after (test) failure
# $ killall mongod; rm -fr rs
def test_connect
- seeds = @rs.replica_seeds
- @conn = Mongo::ReplSetConnection.new(seeds, :name => @rs.name)
+ seeds = @rs.repl_set_seeds
+ @conn = Mongo::ReplSetConnection.new(seeds, :name => @rs.repl_set_name)
assert @conn.connected?
p @rs
View
@@ -15,15 +15,14 @@ def ensure_cluster(kind=nil)
if kind == :rs
dbpath = 'rs'
opts = Mongo::Config::DEFAULT_REPLICA_SET
- opts.merge(:oplog_size => 10)
- opts.merge(:journal => false)
+ opts.merge!(:arbiters => 2, :oplog_size => 10, :journal => false)
else
dbpath = 'sc'
opts = Mongo::Config::DEFAULT_SHARDED_SIMPLE
- opts.merge(:routers => 4)
+ opts.merge!(:routers => 4)
end
- opts.merge(:dbpath => dbpath)
+ opts.merge!(:dbpath => dbpath)
#debug 1, opts
config = Mongo::Config.cluster(opts)
View
@@ -14,6 +14,15 @@ def debug(level, arg)
end
end
+#
+# Design Notes
+# Configuration and Cluster Management are modularized with the concept that the Cluster Manager
+# can be supplied with any configuration to run.
+# A configuration can be edited, modified, copied into a test file, and supplied to a cluster manager
+# as a parameter.
+# To Do
+# Addition of arbiters - http://docs.mongodb.org/manual/administration/replica-sets/#replica-set-arbiters
+#
module Mongo
class Config
DEFAULT_BASE_OPTS = { :host => 'localhost', :logpath => 'data/log', :dbpath => 'data' }
@@ -23,7 +32,7 @@ class Config
SERVER_PRELUDE_KEYS = [:host, :command]
SHARDING_OPT_KEYS = [:shards, :configs, :routers]
- REPLICA_OPT_KEYS = [:replicas]
+ REPLICA_OPT_KEYS = [:replicas] #[:replicas, :arbiters] # TODO - complete arbiters
MONGODS_OPT_KEYS = [:mongods]
CLUSTER_OPT_KEYS = SHARDING_OPT_KEYS + REPLICA_OPT_KEYS + MONGODS_OPT_KEYS
@@ -52,6 +61,7 @@ def self.cluster(opts = DEFAULT_SHARDED_SIMPLE)
server_params = { :host => opts[:host], :port => self.get_available_port, :logpath => logpath }
case key
when :replicas; server_params.merge!( :command => 'mongod', :dbpath => dbpath, :replSet => File.basename(opts[:dbpath]) )
+ when :arbiters; server_params.merge!( :command => 'mongod', :replSet => File.basename(opts[:dbpath]) ) # TODO - complete arbiters
when :configs; server_params.merge!( :command => 'mongod', :dbpath => dbpath, :configsvr => nil )
when :routers; server_params.merge!( :command => 'mongos', :configdb => self.configdb(config) ) # mongos, NO dbpath
else server_params.merge!( :command => 'mongod', :dbpath => dbpath ) # :mongods, :shards
@@ -225,9 +235,10 @@ def repl_set_get_status
end
def repl_set_initiate( cfg = nil )
+ # TODO - add arbiters
cfg ||= {
:_id => @config[:replicas].first[:replSet],
- :members => @config[:replicas].each_with_index.collect{|s, i| { :_id => i, :host => "#{s[:host]}:#{s[:port]}" } },
+ :members => (@config[:replicas]).each_with_index.collect{|s, i| { :_id => i, :host => "#{s[:host]}:#{s[:port]}" } },
}
command( @config[:replicas].first, 'admin', { :replSetInitiate => cfg } )
end
@@ -243,11 +254,11 @@ def repl_set_startup
raise Mongo::OperationFailure, "replSet startup failed - status: #{response.inspect}"
end
- def replica_seeds
+ def repl_set_seeds
@config[:replicas].collect{|router| "#{router[:host]}:#{router[:port]}"}
end
- def name
+ def repl_set_name
@config[:replicas].first[:replSet]
end

0 comments on commit 6bb0cdc

Please sign in to comment.