mongo 1.7.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +124 -111
- data/Rakefile +9 -325
- data/VERSION +1 -0
- data/bin/mongo_console +4 -4
- data/examples/admin.rb +43 -0
- data/examples/capped.rb +22 -0
- data/examples/cursor.rb +48 -0
- data/examples/gridfs.rb +44 -0
- data/examples/index_test.rb +126 -0
- data/examples/info.rb +31 -0
- data/examples/queries.rb +74 -0
- data/examples/replica_set.rb +26 -0
- data/examples/simple.rb +25 -0
- data/examples/strict.rb +35 -0
- data/examples/types.rb +36 -0
- data/{test/load → examples/web}/thin/load.rb +3 -1
- data/{test/load → examples/web}/unicorn/load.rb +5 -3
- data/lib/mongo.rb +8 -10
- data/lib/mongo/collection.rb +134 -114
- data/lib/mongo/cursor.rb +21 -14
- data/lib/mongo/db.rb +30 -28
- data/lib/mongo/exceptions.rb +1 -1
- data/lib/mongo/gridfs/grid.rb +8 -7
- data/lib/mongo/gridfs/grid_ext.rb +1 -1
- data/lib/mongo/gridfs/grid_file_system.rb +6 -5
- data/lib/mongo/gridfs/grid_io.rb +22 -19
- data/lib/mongo/legacy.rb +82 -0
- data/lib/mongo/{connection.rb → mongo_client.rb} +82 -61
- data/lib/mongo/{repl_set_connection.rb → mongo_replica_set_client.rb} +54 -39
- data/lib/mongo/{sharded_connection.rb → mongo_sharded_client.rb} +9 -9
- data/lib/mongo/networking.rb +25 -20
- data/lib/mongo/util/conversions.rb +1 -1
- data/lib/mongo/util/core_ext.rb +1 -1
- data/lib/mongo/util/logging.rb +20 -4
- data/lib/mongo/util/node.rb +16 -16
- data/lib/mongo/util/pool.rb +56 -27
- data/lib/mongo/util/pool_manager.rb +28 -27
- data/lib/mongo/util/server_version.rb +1 -1
- data/lib/mongo/util/sharding_pool_manager.rb +8 -8
- data/lib/mongo/util/ssl_socket.rb +1 -5
- data/lib/mongo/util/support.rb +24 -8
- data/lib/mongo/util/tcp_socket.rb +0 -4
- data/lib/mongo/util/uri_parser.rb +54 -38
- data/lib/mongo/util/write_concern.rb +67 -0
- data/mongo.gemspec +21 -32
- data/test/auxillary/{1.4_features.rb → 1.4_feature_test.rb} +4 -5
- data/test/auxillary/authentication_test.rb +18 -20
- data/test/auxillary/autoreconnect_test.rb +3 -5
- data/test/auxillary/fork_test.rb +5 -7
- data/test/auxillary/repl_set_auth_test.rb +13 -15
- data/test/auxillary/slave_connection_test.rb +8 -7
- data/test/auxillary/threaded_authentication_test.rb +15 -17
- data/test/bson/binary_test.rb +1 -1
- data/test/bson/bson_test.rb +60 -36
- data/test/bson/byte_buffer_test.rb +1 -1
- data/test/bson/hash_with_indifferent_access_test.rb +2 -2
- data/test/bson/json_test.rb +1 -2
- data/test/bson/object_id_test.rb +1 -2
- data/test/bson/ordered_hash_test.rb +1 -1
- data/test/bson/timestamp_test.rb +1 -1
- data/test/{collection_test.rb → functional/collection_test.rb} +57 -57
- data/test/{connection_test.rb → functional/connection_test.rb} +75 -89
- data/test/{conversions_test.rb → functional/conversions_test.rb} +1 -1
- data/test/{cursor_fail_test.rb → functional/cursor_fail_test.rb} +3 -29
- data/test/{cursor_message_test.rb → functional/cursor_message_test.rb} +1 -1
- data/test/{cursor_test.rb → functional/cursor_test.rb} +5 -1
- data/test/{db_api_test.rb → functional/db_api_test.rb} +8 -9
- data/test/{db_connection_test.rb → functional/db_connection_test.rb} +3 -5
- data/test/{db_test.rb → functional/db_test.rb} +13 -13
- data/test/{grid_file_system_test.rb → functional/grid_file_system_test.rb} +2 -2
- data/test/{grid_io_test.rb → functional/grid_io_test.rb} +6 -6
- data/test/{grid_test.rb → functional/grid_test.rb} +4 -10
- data/test/{pool_test.rb → functional/pool_test.rb} +1 -1
- data/test/functional/safe_test.rb +84 -0
- data/test/{support_test.rb → functional/support_test.rb} +1 -1
- data/test/{threading_test.rb → functional/threading_test.rb} +9 -9
- data/test/{timeout_test.rb → functional/timeout_test.rb} +1 -1
- data/test/{uri_test.rb → functional/uri_test.rb} +1 -1
- data/test/functional/write_concern_test.rb +104 -0
- data/test/replica_set/basic_test.rb +139 -0
- data/test/replica_set/client_test.rb +255 -0
- data/test/replica_set/complex_connect_test.rb +62 -0
- data/test/replica_set/connection_test.rb +255 -0
- data/test/{replica_sets → replica_set}/count_test.rb +17 -14
- data/test/replica_set/cursor_test.rb +75 -0
- data/test/{replica_sets → replica_set}/insert_test.rb +19 -16
- data/test/replica_set/query_test.rb +64 -0
- data/test/replica_set/refresh_test.rb +153 -0
- data/test/{replica_sets → replica_set}/replication_ack_test.rb +21 -17
- data/test/sharded_cluster/basic_test.rb +31 -50
- data/test/support/hash_with_indifferent_access.rb +1 -1
- data/test/test_helper.rb +56 -9
- data/test/threading/threading_with_large_pool_test.rb +8 -8
- data/test/tools/mongo_config.rb +270 -58
- data/test/tools/mongo_config_test.rb +146 -0
- data/test/unit/client_test.rb +230 -0
- data/test/unit/collection_test.rb +45 -32
- data/test/unit/connection_test.rb +82 -74
- data/test/unit/cursor_test.rb +14 -6
- data/test/unit/db_test.rb +8 -8
- data/test/unit/grid_test.rb +11 -11
- data/test/unit/node_test.rb +24 -24
- data/test/unit/pool_manager_test.rb +13 -13
- data/test/unit/pool_test.rb +1 -1
- data/test/unit/read_test.rb +21 -26
- data/test/unit/safe_test.rb +52 -33
- data/test/unit/util_test.rb +55 -0
- data/test/unit/write_concern_test.rb +161 -0
- metadata +158 -171
- data/docs/CREDITS.md +0 -123
- data/docs/FAQ.md +0 -116
- data/docs/GRID_FS.md +0 -158
- data/docs/HISTORY.md +0 -392
- data/docs/READ_PREFERENCE.md +0 -99
- data/docs/RELEASES.md +0 -54
- data/docs/REPLICA_SETS.md +0 -113
- data/docs/TAILABLE_CURSORS.md +0 -51
- data/docs/TUTORIAL.md +0 -356
- data/docs/WRITE_CONCERN.md +0 -31
- data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
- data/lib/mongo/version.rb +0 -3
- data/test/bson/test_helper.rb +0 -30
- data/test/replica_sets/basic_test.rb +0 -119
- data/test/replica_sets/complex_connect_test.rb +0 -57
- data/test/replica_sets/complex_read_preference_test.rb +0 -237
- data/test/replica_sets/connect_test.rb +0 -156
- data/test/replica_sets/cursor_test.rb +0 -70
- data/test/replica_sets/pooled_insert_test.rb +0 -57
- data/test/replica_sets/query_test.rb +0 -50
- data/test/replica_sets/read_preference_test.rb +0 -234
- data/test/replica_sets/refresh_test.rb +0 -156
- data/test/replica_sets/refresh_with_threads_test.rb +0 -60
- data/test/replica_sets/rs_test_helper.rb +0 -39
- data/test/safe_test.rb +0 -68
- data/test/sharded_cluster/mongo_config_test.rb +0 -126
- data/test/sharded_cluster/sc_test_helper.rb +0 -39
- data/test/tools/repl_set_manager.rb +0 -418
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
include Mongo
|
3
3
|
|
4
4
|
class PoolManagerTest < Test::Unit::TestCase
|
@@ -9,17 +9,17 @@ class PoolManagerTest < Test::Unit::TestCase
|
|
9
9
|
TCPSocket.stubs(:new).returns(new_mock_socket)
|
10
10
|
@db = new_mock_db
|
11
11
|
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
|
21
|
-
@
|
22
|
-
@
|
12
|
+
@client = stub("MongoClient")
|
13
|
+
@client.stubs(:connect_timeout).returns(5)
|
14
|
+
@client.stubs(:op_timeout).returns(5)
|
15
|
+
@client.stubs(:pool_size).returns(2)
|
16
|
+
@client.stubs(:pool_timeout).returns(100)
|
17
|
+
@client.stubs(:seeds).returns(['localhost:30000'])
|
18
|
+
@client.stubs(:socket_class).returns(TCPSocket)
|
19
|
+
@client.stubs(:[]).returns(@db)
|
20
|
+
|
21
|
+
@client.stubs(:replica_set_name).returns(nil)
|
22
|
+
@client.stubs(:log)
|
23
23
|
@arbiters = ['localhost:27020']
|
24
24
|
@hosts = ['localhost:27017', 'localhost:27018', 'localhost:27019',
|
25
25
|
'localhost:27020']
|
@@ -35,7 +35,7 @@ class PoolManagerTest < Test::Unit::TestCase
|
|
35
35
|
{'arbiterOnly' => true, 'hosts' => @hosts, 'arbiters' => @arbiters})
|
36
36
|
|
37
37
|
seeds = [['localhost', 27017]]
|
38
|
-
manager = Mongo::PoolManager.new(@
|
38
|
+
manager = Mongo::PoolManager.new(@client, seeds)
|
39
39
|
manager.connect
|
40
40
|
|
41
41
|
assert_equal ['localhost', 27017], manager.primary
|
data/test/unit/pool_test.rb
CHANGED
data/test/unit/read_test.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class ReadTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
context "Read mode on standard connection: " do
|
6
6
|
setup do
|
7
7
|
@read_preference = :secondary
|
8
|
-
@
|
8
|
+
@client = MongoClient.new('localhost', 27017, :read => @read_preference, :connect => false)
|
9
9
|
end
|
10
10
|
|
11
11
|
end
|
@@ -16,7 +16,7 @@ class ReadTest < Test::Unit::TestCase
|
|
16
16
|
@acceptable_latency = 100
|
17
17
|
@tags = {"dc" => "Tyler", "rack" => "Brock"}
|
18
18
|
@bad_tags = {"wow" => "cool"}
|
19
|
-
@
|
19
|
+
@client = MongoReplicaSetClient.new(
|
20
20
|
['localhost:27017'],
|
21
21
|
:read => @read_preference,
|
22
22
|
:tag_sets => @tags,
|
@@ -25,36 +25,36 @@ class ReadTest < Test::Unit::TestCase
|
|
25
25
|
)
|
26
26
|
end
|
27
27
|
|
28
|
-
should "store read preference on
|
29
|
-
assert_equal @read_preference, @
|
30
|
-
assert_equal @tags, @
|
31
|
-
assert_equal @acceptable_latency, @
|
28
|
+
should "store read preference on MongoClient" do
|
29
|
+
assert_equal @read_preference, @client.read_preference
|
30
|
+
assert_equal @tags, @client.tag_sets
|
31
|
+
assert_equal @acceptable_latency, @client.acceptable_latency
|
32
32
|
end
|
33
33
|
|
34
34
|
should "propogate to DB" do
|
35
|
-
db = @
|
35
|
+
db = @client['foo']
|
36
36
|
assert_equal @read_preference, db.read_preference
|
37
37
|
assert_equal @tags, db.tag_sets
|
38
38
|
assert_equal @acceptable_latency, db.acceptable_latency
|
39
39
|
|
40
|
-
db = @
|
40
|
+
db = @client.db('foo')
|
41
41
|
assert_equal @read_preference, db.read_preference
|
42
42
|
assert_equal @tags, db.tag_sets
|
43
43
|
assert_equal @acceptable_latency, db.acceptable_latency
|
44
44
|
|
45
|
-
db = DB.new('foo', @
|
45
|
+
db = DB.new('foo', @client)
|
46
46
|
assert_equal @read_preference, db.read_preference
|
47
47
|
assert_equal @tags, db.tag_sets
|
48
48
|
assert_equal @acceptable_latency, db.acceptable_latency
|
49
49
|
end
|
50
50
|
|
51
51
|
should "allow db override" do
|
52
|
-
db = DB.new('foo', @
|
52
|
+
db = DB.new('foo', @client, :read => :primary, :tag_sets => @bad_tags, :acceptable_latency => 25)
|
53
53
|
assert_equal :primary, db.read_preference
|
54
54
|
assert_equal @bad_tags, db.tag_sets
|
55
55
|
assert_equal 25, db.acceptable_latency
|
56
56
|
|
57
|
-
db = @
|
57
|
+
db = @client.db('foo', :read => :primary, :tag_sets => @bad_tags, :acceptable_latency => 25)
|
58
58
|
assert_equal :primary, db.read_preference
|
59
59
|
assert_equal @bad_tags, db.tag_sets
|
60
60
|
assert_equal 25, db.acceptable_latency
|
@@ -62,7 +62,7 @@ class ReadTest < Test::Unit::TestCase
|
|
62
62
|
|
63
63
|
context "on DB: " do
|
64
64
|
setup do
|
65
|
-
@db = @
|
65
|
+
@db = @client['foo']
|
66
66
|
end
|
67
67
|
|
68
68
|
should "propogate to collection" do
|
@@ -97,7 +97,7 @@ class ReadTest < Test::Unit::TestCase
|
|
97
97
|
|
98
98
|
context "on read mode ops" do
|
99
99
|
setup do
|
100
|
-
@col = @
|
100
|
+
@col = @client['foo']['bar']
|
101
101
|
@mock_socket = new_mock_socket
|
102
102
|
end
|
103
103
|
|
@@ -105,12 +105,12 @@ class ReadTest < Test::Unit::TestCase
|
|
105
105
|
@cursor = @col.find({:a => 1})
|
106
106
|
sock = new_mock_socket
|
107
107
|
read_pool = stub(:checkin => true)
|
108
|
-
@
|
108
|
+
@client.stubs(:read_pool).returns(read_pool)
|
109
109
|
primary_pool = stub(:checkin => true)
|
110
110
|
sock.stubs(:pool).returns(primary_pool)
|
111
|
-
@
|
112
|
-
@
|
113
|
-
@
|
111
|
+
@client.stubs(:primary_pool).returns(primary_pool)
|
112
|
+
@client.expects(:checkout_reader).returns(sock)
|
113
|
+
@client.expects(:receive_message).with do |o, m, l, s, c, r|
|
114
114
|
r == nil
|
115
115
|
end.returns([[], 0, 0])
|
116
116
|
|
@@ -122,9 +122,9 @@ class ReadTest < Test::Unit::TestCase
|
|
122
122
|
sock = new_mock_socket
|
123
123
|
primary_pool = stub(:checkin => true)
|
124
124
|
sock.stubs(:pool).returns(primary_pool)
|
125
|
-
@
|
126
|
-
@
|
127
|
-
@
|
125
|
+
@client.stubs(:primary_pool).returns(primary_pool)
|
126
|
+
@client.expects(:checkout_reader).returns(sock)
|
127
|
+
@client.expects(:receive_message).with do |o, m, l, s, c, r|
|
128
128
|
r == nil
|
129
129
|
end.returns([[], 0, 0])
|
130
130
|
|
@@ -132,11 +132,6 @@ class ReadTest < Test::Unit::TestCase
|
|
132
132
|
end
|
133
133
|
|
134
134
|
should "allow override alternate value on query" do
|
135
|
-
# TODO: enable this test once we enable reading from tags.
|
136
|
-
# @con.expects(:receive_message).with do |o, m, l, s, c, r|
|
137
|
-
# tags = {:dc => "ny"}
|
138
|
-
# end.returns([[], 0, 0])
|
139
|
-
|
140
135
|
assert_raise MongoArgumentError do
|
141
136
|
@col.find_one({:a => 1}, :read => {:dc => "ny"})
|
142
137
|
end
|
data/test/unit/safe_test.rb
CHANGED
@@ -1,65 +1,65 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class SafeTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
context "
|
5
|
+
context "Write-Concern modes on Mongo::Connection " do
|
6
6
|
setup do
|
7
|
-
@safe_value = {:w => 7}
|
8
|
-
@
|
7
|
+
@safe_value = {:w => 7, :j => false, :fsync => false, :wtimeout => false}
|
8
|
+
@connection = Mongo::Connection.new('localhost', 27017, :safe => @safe_value, :connect => false)
|
9
9
|
end
|
10
10
|
|
11
11
|
should "propogate to DB" do
|
12
|
-
db = @
|
13
|
-
assert_equal @safe_value, db.
|
12
|
+
db = @connection['foo']
|
13
|
+
assert_equal @safe_value[:w], db.write_concern[:w]
|
14
14
|
|
15
15
|
|
16
|
-
db = @
|
17
|
-
assert_equal @safe_value, db.
|
16
|
+
db = @connection.db('foo')
|
17
|
+
assert_equal @safe_value[:w], db.write_concern[:w]
|
18
18
|
|
19
|
-
db = DB.new('foo', @
|
20
|
-
assert_equal @safe_value, db.
|
19
|
+
db = DB.new('foo', @connection)
|
20
|
+
assert_equal @safe_value[:w], db.write_concern[:w]
|
21
21
|
end
|
22
22
|
|
23
23
|
should "allow db override" do
|
24
|
-
db = DB.new('foo', @
|
25
|
-
assert_equal
|
24
|
+
db = DB.new('foo', @connection, :safe => false)
|
25
|
+
assert_equal 0, db.write_concern[:w]
|
26
26
|
|
27
|
-
db = @
|
28
|
-
assert_equal
|
27
|
+
db = @connection.db('foo', :safe => false)
|
28
|
+
assert_equal 0, db.write_concern[:w]
|
29
29
|
end
|
30
30
|
|
31
31
|
context "on DB: " do
|
32
32
|
setup do
|
33
|
-
@db = @
|
33
|
+
@db = @connection['foo']
|
34
34
|
end
|
35
35
|
|
36
36
|
should "propogate to collection" do
|
37
37
|
col = @db.collection('bar')
|
38
|
-
assert_equal @safe_value, col.
|
38
|
+
assert_equal @safe_value, col.write_concern
|
39
39
|
|
40
40
|
col = @db['bar']
|
41
|
-
assert_equal @safe_value, col.
|
41
|
+
assert_equal @safe_value, col.write_concern
|
42
42
|
|
43
43
|
col = Collection.new('bar', @db)
|
44
|
-
assert_equal @safe_value, col.
|
44
|
+
assert_equal @safe_value, col.write_concern
|
45
45
|
end
|
46
46
|
|
47
47
|
should "allow override on collection" do
|
48
48
|
col = @db.collection('bar', :safe => false)
|
49
|
-
assert_equal
|
49
|
+
assert_equal 0, col.write_concern[:w]
|
50
50
|
|
51
51
|
col = Collection.new('bar', @db, :safe => false)
|
52
|
-
assert_equal
|
52
|
+
assert_equal 0, col.write_concern[:w]
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
context "on operations supporting safe mode" do
|
57
57
|
setup do
|
58
|
-
@col = @
|
58
|
+
@col = @connection['foo']['bar']
|
59
59
|
end
|
60
60
|
|
61
61
|
should "use default value on insert" do
|
62
|
-
@
|
62
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
63
63
|
safe == @safe_value
|
64
64
|
end
|
65
65
|
|
@@ -67,20 +67,20 @@ class SafeTest < Test::Unit::TestCase
|
|
67
67
|
end
|
68
68
|
|
69
69
|
should "allow override alternate value on insert" do
|
70
|
-
@
|
71
|
-
safe == {:w => 100}
|
70
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
71
|
+
safe == {:w => 100, :j => false, :fsync => false, :wtimeout => false}
|
72
72
|
end
|
73
73
|
|
74
74
|
@col.insert({:a => 1}, :safe => {:w => 100})
|
75
75
|
end
|
76
76
|
|
77
77
|
should "allow override to disable on insert" do
|
78
|
-
@
|
78
|
+
@connection.expects(:send_message)
|
79
79
|
@col.insert({:a => 1}, :safe => false)
|
80
80
|
end
|
81
81
|
|
82
82
|
should "use default value on update" do
|
83
|
-
@
|
83
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
84
84
|
safe == @safe_value
|
85
85
|
end
|
86
86
|
|
@@ -88,20 +88,39 @@ class SafeTest < Test::Unit::TestCase
|
|
88
88
|
end
|
89
89
|
|
90
90
|
should "allow override alternate value on update" do
|
91
|
-
@
|
92
|
-
safe == {:w => 100}
|
91
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
92
|
+
safe == {:w => 100, :j => false, :fsync => false, :wtimeout => false}
|
93
93
|
end
|
94
94
|
|
95
95
|
@col.update({:a => 1}, {:a => 2}, :safe => {:w => 100})
|
96
96
|
end
|
97
97
|
|
98
98
|
should "allow override to disable on update" do
|
99
|
-
@
|
99
|
+
@connection.expects(:send_message)
|
100
100
|
@col.update({:a => 1}, {:a => 2}, :safe => false)
|
101
101
|
end
|
102
102
|
|
103
|
+
should "use default value on save" do
|
104
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
105
|
+
safe == @safe_value
|
106
|
+
end
|
107
|
+
@col.save({:a => 1})
|
108
|
+
end
|
109
|
+
|
110
|
+
should "allow override alternate value on save" do
|
111
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
112
|
+
safe == @safe_value.merge(:w => 1)
|
113
|
+
end
|
114
|
+
@col.save({:a => 1}, :safe => true)
|
115
|
+
end
|
116
|
+
|
117
|
+
should "allow override to disable on save" do
|
118
|
+
@connection.expects(:send_message)
|
119
|
+
@col.save({:a => 1}, :safe => false)
|
120
|
+
end
|
121
|
+
|
103
122
|
should "use default value on remove" do
|
104
|
-
@
|
123
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
105
124
|
safe == @safe_value
|
106
125
|
end
|
107
126
|
|
@@ -109,15 +128,15 @@ class SafeTest < Test::Unit::TestCase
|
|
109
128
|
end
|
110
129
|
|
111
130
|
should "allow override alternate value on remove" do
|
112
|
-
@
|
113
|
-
safe == {:w => 100}
|
131
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
132
|
+
safe == {:w => 100, :j => false, :fsync => false, :wtimeout => false}
|
114
133
|
end
|
115
134
|
|
116
135
|
@col.remove({}, :safe => {:w => 100})
|
117
136
|
end
|
118
137
|
|
119
138
|
should "allow override to disable on remove" do
|
120
|
-
@
|
139
|
+
@connection.expects(:send_message)
|
121
140
|
@col.remove({}, :safe => false)
|
122
141
|
end
|
123
142
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
|
+
|
3
|
+
class UtilTest < Test::Unit::TestCase
|
4
|
+
context "Support" do
|
5
|
+
context ".secondary_ok?" do
|
6
|
+
should "return false for mapreduces with a string for out" do
|
7
|
+
assert_equal false, Mongo::Support.secondary_ok?(BSON::OrderedHash[
|
8
|
+
'mapreduce', 'test-collection',
|
9
|
+
'out', 'new-test-collection'
|
10
|
+
])
|
11
|
+
end
|
12
|
+
|
13
|
+
should "return false for mapreduces replacing a collection" do
|
14
|
+
assert_equal false, Mongo::Support.secondary_ok?(BSON::OrderedHash[
|
15
|
+
'mapreduce', 'test-collection',
|
16
|
+
'out', BSON::OrderedHash['replace', 'new-test-collection']
|
17
|
+
])
|
18
|
+
end
|
19
|
+
|
20
|
+
should "return false for mapreduces replacing the inline collection" do
|
21
|
+
assert_equal false, Mongo::Support.secondary_ok?(BSON::OrderedHash[
|
22
|
+
'mapreduce', 'test-collection',
|
23
|
+
'out', 'inline'
|
24
|
+
])
|
25
|
+
end
|
26
|
+
|
27
|
+
should "return true for inline output mapreduces when inline is a symbol" do
|
28
|
+
assert_equal true, Mongo::Support.secondary_ok?(BSON::OrderedHash[
|
29
|
+
'mapreduce', 'test-collection',
|
30
|
+
'out', BSON::OrderedHash[:inline, 'true']
|
31
|
+
])
|
32
|
+
end
|
33
|
+
|
34
|
+
should "return true for inline output mapreduces when inline is a string" do
|
35
|
+
assert_equal true, Mongo::Support.secondary_ok?(BSON::OrderedHash[
|
36
|
+
'mapreduce', 'test-collection',
|
37
|
+
'out', BSON::OrderedHash['inline', 'true']
|
38
|
+
])
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'return true for count' do
|
42
|
+
assert_equal true, Mongo::Support.secondary_ok?(BSON::OrderedHash[
|
43
|
+
'count', 'test-collection',
|
44
|
+
'query', BSON::OrderedHash['a', 'b']
|
45
|
+
])
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'return false for serverStatus' do
|
49
|
+
assert_equal false, Mongo::Support.secondary_ok?(BSON::OrderedHash[
|
50
|
+
'serverStatus', 1
|
51
|
+
])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class WriteConcernTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Write-Concern modes on Mongo::MongoClient " do
|
6
|
+
setup do
|
7
|
+
@write_concern = {
|
8
|
+
:w => 7,
|
9
|
+
:j => false,
|
10
|
+
:fsync => false,
|
11
|
+
:wtimeout => false
|
12
|
+
}
|
13
|
+
|
14
|
+
class Mongo::MongoClient
|
15
|
+
public :build_get_last_error_message, :build_command_message
|
16
|
+
end
|
17
|
+
|
18
|
+
@client =
|
19
|
+
MongoClient.new('localhost', 27017,
|
20
|
+
@write_concern.merge({:connect => false}))
|
21
|
+
end
|
22
|
+
|
23
|
+
should "propogate to DB" do
|
24
|
+
db = @client['foo']
|
25
|
+
assert_equal @write_concern, db.write_concern
|
26
|
+
|
27
|
+
|
28
|
+
db = @client.db('foo')
|
29
|
+
assert_equal @write_concern, db.write_concern
|
30
|
+
|
31
|
+
db = DB.new('foo', @client)
|
32
|
+
assert_equal @write_concern, db.write_concern
|
33
|
+
end
|
34
|
+
|
35
|
+
should "allow db override" do
|
36
|
+
db = DB.new('foo', @client, :w => 0)
|
37
|
+
assert_equal 0, db.write_concern[:w]
|
38
|
+
|
39
|
+
db = @client.db('foo', :w => 0)
|
40
|
+
assert_equal 0, db.write_concern[:w]
|
41
|
+
end
|
42
|
+
|
43
|
+
context "on DB: " do
|
44
|
+
setup do
|
45
|
+
@db = @client['foo']
|
46
|
+
end
|
47
|
+
|
48
|
+
should "propogate to collection" do
|
49
|
+
collection = @db.collection('bar')
|
50
|
+
assert_equal @write_concern, collection.write_concern
|
51
|
+
|
52
|
+
collection = @db['bar']
|
53
|
+
assert_equal @write_concern, collection.write_concern
|
54
|
+
|
55
|
+
collection = Collection.new('bar', @db)
|
56
|
+
assert_equal @write_concern, collection.write_concern
|
57
|
+
end
|
58
|
+
|
59
|
+
should "allow override on collection" do
|
60
|
+
collection = @db.collection('bar', :w => 0)
|
61
|
+
assert_equal 0, collection.write_concern[:w]
|
62
|
+
|
63
|
+
collection = Collection.new('bar', @db, :w => 0)
|
64
|
+
assert_equal 0, collection.write_concern[:w]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "on operations supporting 'gle' mode" do
|
69
|
+
setup do
|
70
|
+
@collection = @client['foo']['bar']
|
71
|
+
end
|
72
|
+
|
73
|
+
should "not send w = 1 to the server" do
|
74
|
+
gle = @client.build_get_last_error_message("fake", {:w => 1})
|
75
|
+
assert_equal gle, @client.build_command_message("fake", {:getlasterror => 1})
|
76
|
+
end
|
77
|
+
|
78
|
+
should "use default value on insert" do
|
79
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
80
|
+
wc == @write_concern
|
81
|
+
end
|
82
|
+
|
83
|
+
@collection.insert({:a => 1})
|
84
|
+
end
|
85
|
+
|
86
|
+
should "allow override alternate value on insert" do
|
87
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
88
|
+
wc == {:w => 100, :j => false, :fsync => false, :wtimeout => false}
|
89
|
+
end
|
90
|
+
|
91
|
+
@collection.insert({:a => 1}, {:w => 100})
|
92
|
+
end
|
93
|
+
|
94
|
+
should "allow override to disable on insert" do
|
95
|
+
@client.expects(:send_message)
|
96
|
+
@collection.insert({:a => 1}, :w => 0)
|
97
|
+
end
|
98
|
+
|
99
|
+
should "use default value on update" do
|
100
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
101
|
+
wc == @write_concern
|
102
|
+
end
|
103
|
+
|
104
|
+
@collection.update({:a => 1}, {:a => 2})
|
105
|
+
end
|
106
|
+
|
107
|
+
should "allow override alternate value on update" do
|
108
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
109
|
+
wc == {:w => 100, :j => false, :fsync => false, :wtimeout => false}
|
110
|
+
end
|
111
|
+
|
112
|
+
@collection.update({:a => 1}, {:a => 2}, {:w => 100})
|
113
|
+
end
|
114
|
+
|
115
|
+
should "allow override to disable on update" do
|
116
|
+
@client.expects(:send_message)
|
117
|
+
@collection.update({:a => 1}, {:a => 2}, :w => 0)
|
118
|
+
end
|
119
|
+
|
120
|
+
should "use default value on save" do
|
121
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
122
|
+
wc == @write_concern
|
123
|
+
end
|
124
|
+
@collection.save({:a => 1})
|
125
|
+
end
|
126
|
+
|
127
|
+
should "allow override alternate value on save" do
|
128
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
129
|
+
wc == @write_concern.merge(:w => 1)
|
130
|
+
end
|
131
|
+
@collection.save({:a => 1}, :w => 1)
|
132
|
+
end
|
133
|
+
|
134
|
+
should "allow override to disable on save" do
|
135
|
+
@client.expects(:send_message)
|
136
|
+
@collection.save({:a => 1}, :w => 0)
|
137
|
+
end
|
138
|
+
|
139
|
+
should "use default value on remove" do
|
140
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
141
|
+
wc == @write_concern
|
142
|
+
end
|
143
|
+
|
144
|
+
@collection.remove
|
145
|
+
end
|
146
|
+
|
147
|
+
should "allow override alternate value on remove" do
|
148
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
149
|
+
wc == {:w => 100, :j => false, :fsync => false, :wtimeout => false}
|
150
|
+
end
|
151
|
+
|
152
|
+
@collection.remove({}, {:w => 100})
|
153
|
+
end
|
154
|
+
|
155
|
+
should "allow override to disable on remove" do
|
156
|
+
@client.expects(:send_message)
|
157
|
+
@collection.remove({}, :w => 0)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|