mongo 1.3.0 → 1.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +122 -271
- data/Rakefile +25 -209
- data/VERSION +1 -0
- data/bin/mongo_console +31 -9
- data/lib/mongo/bulk_write_collection_view.rb +387 -0
- data/lib/mongo/collection.rb +576 -269
- data/lib/mongo/collection_writer.rb +364 -0
- data/lib/mongo/connection/node.rb +249 -0
- data/lib/mongo/connection/pool.rb +340 -0
- data/lib/mongo/connection/pool_manager.rb +320 -0
- data/lib/mongo/connection/sharding_pool_manager.rb +67 -0
- data/lib/mongo/connection/socket/socket_util.rb +37 -0
- data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
- data/lib/mongo/connection/socket/tcp_socket.rb +87 -0
- data/lib/mongo/connection/socket/unix_socket.rb +39 -0
- data/lib/mongo/connection/socket.rb +18 -0
- data/lib/mongo/connection.rb +7 -875
- data/lib/mongo/cursor.rb +403 -117
- data/lib/mongo/db.rb +444 -243
- data/lib/mongo/exception.rb +145 -0
- data/lib/mongo/functional/authentication.rb +455 -0
- data/lib/mongo/functional/logging.rb +85 -0
- data/lib/mongo/functional/read_preference.rb +183 -0
- data/lib/mongo/functional/scram.rb +556 -0
- data/lib/mongo/functional/uri_parser.rb +409 -0
- data/lib/mongo/functional/write_concern.rb +66 -0
- data/lib/mongo/functional.rb +20 -0
- data/lib/mongo/gridfs/grid.rb +30 -24
- data/lib/mongo/gridfs/grid_ext.rb +6 -10
- data/lib/mongo/gridfs/grid_file_system.rb +38 -20
- data/lib/mongo/gridfs/grid_io.rb +84 -75
- data/lib/mongo/gridfs.rb +18 -0
- data/lib/mongo/legacy.rb +140 -0
- data/lib/mongo/mongo_client.rb +697 -0
- data/lib/mongo/mongo_replica_set_client.rb +535 -0
- data/lib/mongo/mongo_sharded_client.rb +159 -0
- data/lib/mongo/networking.rb +372 -0
- data/lib/mongo/{util → utils}/conversions.rb +29 -8
- data/lib/mongo/{util → utils}/core_ext.rb +28 -18
- data/lib/mongo/{util → utils}/server_version.rb +4 -6
- data/lib/mongo/{util → utils}/support.rb +29 -31
- data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo.rb +51 -50
- data/mongo.gemspec +29 -32
- data/test/functional/authentication_test.rb +39 -0
- data/test/functional/bulk_api_stress_test.rb +133 -0
- data/test/functional/bulk_write_collection_view_test.rb +1198 -0
- data/test/functional/client_test.rb +627 -0
- data/test/functional/collection_test.rb +2175 -0
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/{conversions_test.rb → functional/conversions_test.rb} +47 -3
- data/test/functional/cursor_fail_test.rb +57 -0
- data/test/functional/cursor_message_test.rb +56 -0
- data/test/functional/cursor_test.rb +683 -0
- data/test/functional/db_api_test.rb +835 -0
- data/test/functional/db_connection_test.rb +25 -0
- data/test/functional/db_test.rb +348 -0
- data/test/functional/grid_file_system_test.rb +285 -0
- data/test/{grid_io_test.rb → functional/grid_io_test.rb} +72 -11
- data/test/{grid_test.rb → functional/grid_test.rb} +88 -15
- data/test/functional/pool_test.rb +136 -0
- data/test/functional/safe_test.rb +98 -0
- data/test/functional/ssl_test.rb +29 -0
- data/test/functional/support_test.rb +62 -0
- data/test/functional/timeout_test.rb +60 -0
- data/test/functional/uri_test.rb +446 -0
- data/test/functional/write_concern_test.rb +118 -0
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +476 -0
- data/test/replica_set/authentication_test.rb +37 -0
- data/test/replica_set/basic_test.rb +189 -0
- data/test/replica_set/client_test.rb +393 -0
- data/test/replica_set/connection_test.rb +138 -0
- data/test/replica_set/count_test.rb +66 -0
- data/test/replica_set/cursor_test.rb +220 -0
- data/test/replica_set/insert_test.rb +157 -0
- data/test/replica_set/max_values_test.rb +151 -0
- data/test/replica_set/pinning_test.rb +105 -0
- data/test/replica_set/query_test.rb +73 -0
- data/test/replica_set/read_preference_test.rb +219 -0
- data/test/replica_set/refresh_test.rb +211 -0
- data/test/replica_set/replication_ack_test.rb +95 -0
- data/test/replica_set/ssl_test.rb +32 -0
- data/test/sharded_cluster/basic_test.rb +203 -0
- data/test/shared/authentication/basic_auth_shared.rb +260 -0
- data/test/shared/authentication/bulk_api_auth_shared.rb +249 -0
- data/test/shared/authentication/gssapi_shared.rb +176 -0
- data/test/shared/authentication/sasl_plain_shared.rb +96 -0
- data/test/shared/authentication/scram_shared.rb +92 -0
- data/test/shared/ssl_shared.rb +235 -0
- data/test/test_helper.rb +53 -94
- data/test/threading/basic_test.rb +120 -0
- data/test/tools/mongo_config.rb +708 -0
- data/test/tools/mongo_config_test.rb +160 -0
- data/test/unit/client_test.rb +381 -0
- data/test/unit/collection_test.rb +89 -53
- data/test/unit/connection_test.rb +282 -32
- data/test/unit/cursor_test.rb +206 -8
- data/test/unit/db_test.rb +55 -13
- data/test/unit/grid_test.rb +43 -16
- data/test/unit/mongo_sharded_client_test.rb +48 -0
- data/test/unit/node_test.rb +93 -0
- data/test/unit/pool_manager_test.rb +111 -0
- data/test/unit/read_pref_test.rb +406 -0
- data/test/unit/read_test.rb +159 -0
- data/test/unit/safe_test.rb +69 -36
- data/test/unit/sharding_pool_manager_test.rb +84 -0
- data/test/unit/write_concern_test.rb +175 -0
- data.tar.gz.sig +3 -0
- metadata +227 -216
- metadata.gz.sig +0 -0
- data/docs/CREDITS.md +0 -123
- data/docs/FAQ.md +0 -116
- data/docs/GridFS.md +0 -158
- data/docs/HISTORY.md +0 -244
- data/docs/RELEASES.md +0 -33
- data/docs/REPLICA_SETS.md +0 -72
- data/docs/TUTORIAL.md +0 -247
- data/docs/WRITE_CONCERN.md +0 -28
- data/lib/mongo/exceptions.rb +0 -71
- data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
- data/lib/mongo/repl_set_connection.rb +0 -342
- data/lib/mongo/test.rb +0 -20
- data/lib/mongo/util/pool.rb +0 -177
- data/lib/mongo/util/uri_parser.rb +0 -185
- data/test/async/collection_test.rb +0 -224
- data/test/async/connection_test.rb +0 -24
- data/test/async/cursor_test.rb +0 -162
- data/test/async/worker_pool_test.rb +0 -99
- data/test/auxillary/1.4_features.rb +0 -166
- data/test/auxillary/authentication_test.rb +0 -68
- data/test/auxillary/autoreconnect_test.rb +0 -41
- data/test/auxillary/fork_test.rb +0 -30
- data/test/auxillary/repl_set_auth_test.rb +0 -58
- data/test/auxillary/slave_connection_test.rb +0 -36
- data/test/auxillary/threaded_authentication_test.rb +0 -101
- data/test/bson/binary_test.rb +0 -15
- data/test/bson/bson_test.rb +0 -649
- data/test/bson/byte_buffer_test.rb +0 -208
- data/test/bson/hash_with_indifferent_access_test.rb +0 -38
- data/test/bson/json_test.rb +0 -17
- data/test/bson/object_id_test.rb +0 -154
- data/test/bson/ordered_hash_test.rb +0 -204
- data/test/bson/timestamp_test.rb +0 -24
- data/test/collection_test.rb +0 -910
- data/test/connection_test.rb +0 -309
- data/test/cursor_fail_test.rb +0 -75
- data/test/cursor_message_test.rb +0 -43
- data/test/cursor_test.rb +0 -483
- data/test/db_api_test.rb +0 -726
- data/test/db_connection_test.rb +0 -15
- data/test/db_test.rb +0 -287
- data/test/grid_file_system_test.rb +0 -243
- data/test/load/resque/load.rb +0 -21
- data/test/load/resque/processor.rb +0 -26
- data/test/load/thin/load.rb +0 -24
- data/test/load/unicorn/load.rb +0 -23
- data/test/load/unicorn/unicorn.rb +0 -29
- data/test/replica_sets/connect_test.rb +0 -94
- data/test/replica_sets/connection_string_test.rb +0 -32
- data/test/replica_sets/count_test.rb +0 -35
- data/test/replica_sets/insert_test.rb +0 -53
- data/test/replica_sets/pooled_insert_test.rb +0 -55
- data/test/replica_sets/query_secondaries.rb +0 -96
- data/test/replica_sets/query_test.rb +0 -51
- data/test/replica_sets/replication_ack_test.rb +0 -66
- data/test/replica_sets/rs_test_helper.rb +0 -27
- data/test/safe_test.rb +0 -68
- data/test/support/hash_with_indifferent_access.rb +0 -186
- data/test/support/keys.rb +0 -45
- data/test/support_test.rb +0 -18
- data/test/threading/threading_with_large_pool_test.rb +0 -90
- data/test/threading_test.rb +0 -87
- data/test/tools/auth_repl_set_manager.rb +0 -14
- data/test/tools/load.rb +0 -58
- data/test/tools/repl_set_manager.rb +0 -266
- data/test/tools/sharding_manager.rb +0 -202
- data/test/tools/test.rb +0 -4
- data/test/unit/pool_test.rb +0 -9
- data/test/unit/repl_set_connection_test.rb +0 -59
- data/test/uri_test.rb +0 -91
data/test/unit/safe_test.rb
CHANGED
@@ -1,65 +1,79 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'test_helper'
|
16
|
+
|
17
|
+
class SafeUnitTest < Test::Unit::TestCase
|
18
|
+
|
19
|
+
context "Write-Concern modes on Mongo::Connection " do
|
6
20
|
setup do
|
7
|
-
@safe_value = {:w => 7}
|
8
|
-
@
|
21
|
+
@safe_value = {:w => 7, :j => false, :fsync => false, :wtimeout => nil}
|
22
|
+
@connection = Mongo::Connection.new('localhost', 27017, :safe => @safe_value, :connect => false)
|
9
23
|
end
|
10
24
|
|
11
25
|
should "propogate to DB" do
|
12
|
-
db = @
|
13
|
-
assert_equal @safe_value, db.
|
26
|
+
db = @connection[TEST_DB]
|
27
|
+
assert_equal @safe_value[:w], db.write_concern[:w]
|
14
28
|
|
15
29
|
|
16
|
-
db = @
|
17
|
-
assert_equal @safe_value, db.
|
30
|
+
db = @connection.db(TEST_DB)
|
31
|
+
assert_equal @safe_value[:w], db.write_concern[:w]
|
18
32
|
|
19
|
-
db = DB.new(
|
20
|
-
assert_equal @safe_value, db.
|
33
|
+
db = DB.new(TEST_DB, @connection)
|
34
|
+
assert_equal @safe_value[:w], db.write_concern[:w]
|
21
35
|
end
|
22
36
|
|
23
37
|
should "allow db override" do
|
24
|
-
db = DB.new(
|
25
|
-
assert_equal
|
38
|
+
db = DB.new(TEST_DB, @connection, :safe => false)
|
39
|
+
assert_equal 0, db.write_concern[:w]
|
26
40
|
|
27
|
-
db = @
|
28
|
-
assert_equal
|
41
|
+
db = @connection.db(TEST_DB, :safe => false)
|
42
|
+
assert_equal 0, db.write_concern[:w]
|
29
43
|
end
|
30
44
|
|
31
45
|
context "on DB: " do
|
32
46
|
setup do
|
33
|
-
@db = @
|
47
|
+
@db = @connection[TEST_DB]
|
34
48
|
end
|
35
49
|
|
36
50
|
should "propogate to collection" do
|
37
51
|
col = @db.collection('bar')
|
38
|
-
assert_equal @safe_value, col.
|
52
|
+
assert_equal @safe_value, col.write_concern
|
39
53
|
|
40
54
|
col = @db['bar']
|
41
|
-
assert_equal @safe_value, col.
|
55
|
+
assert_equal @safe_value, col.write_concern
|
42
56
|
|
43
57
|
col = Collection.new('bar', @db)
|
44
|
-
assert_equal @safe_value, col.
|
58
|
+
assert_equal @safe_value, col.write_concern
|
45
59
|
end
|
46
60
|
|
47
61
|
should "allow override on collection" do
|
48
62
|
col = @db.collection('bar', :safe => false)
|
49
|
-
assert_equal
|
63
|
+
assert_equal 0, col.write_concern[:w]
|
50
64
|
|
51
65
|
col = Collection.new('bar', @db, :safe => false)
|
52
|
-
assert_equal
|
66
|
+
assert_equal 0, col.write_concern[:w]
|
53
67
|
end
|
54
68
|
end
|
55
69
|
|
56
70
|
context "on operations supporting safe mode" do
|
57
71
|
setup do
|
58
|
-
@col = @
|
72
|
+
@col = @connection[TEST_DB]['bar']
|
59
73
|
end
|
60
74
|
|
61
75
|
should "use default value on insert" do
|
62
|
-
@
|
76
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
63
77
|
safe == @safe_value
|
64
78
|
end
|
65
79
|
|
@@ -67,20 +81,20 @@ class SafeTest < Test::Unit::TestCase
|
|
67
81
|
end
|
68
82
|
|
69
83
|
should "allow override alternate value on insert" do
|
70
|
-
@
|
71
|
-
safe == {:w => 100}
|
84
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
85
|
+
safe == {:w => 100, :j => false, :fsync => false, :wtimeout => nil}
|
72
86
|
end
|
73
87
|
|
74
88
|
@col.insert({:a => 1}, :safe => {:w => 100})
|
75
89
|
end
|
76
90
|
|
77
91
|
should "allow override to disable on insert" do
|
78
|
-
@
|
92
|
+
@connection.expects(:send_message)
|
79
93
|
@col.insert({:a => 1}, :safe => false)
|
80
94
|
end
|
81
95
|
|
82
96
|
should "use default value on update" do
|
83
|
-
@
|
97
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
84
98
|
safe == @safe_value
|
85
99
|
end
|
86
100
|
|
@@ -88,20 +102,39 @@ class SafeTest < Test::Unit::TestCase
|
|
88
102
|
end
|
89
103
|
|
90
104
|
should "allow override alternate value on update" do
|
91
|
-
@
|
92
|
-
safe == {:w => 100}
|
105
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
106
|
+
safe == {:w => 100, :j => false, :fsync => false, :wtimeout => nil}
|
93
107
|
end
|
94
108
|
|
95
109
|
@col.update({:a => 1}, {:a => 2}, :safe => {:w => 100})
|
96
110
|
end
|
97
111
|
|
98
112
|
should "allow override to disable on update" do
|
99
|
-
@
|
113
|
+
@connection.expects(:send_message)
|
100
114
|
@col.update({:a => 1}, {:a => 2}, :safe => false)
|
101
115
|
end
|
102
116
|
|
117
|
+
should "use default value on save" do
|
118
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
119
|
+
safe == @safe_value
|
120
|
+
end
|
121
|
+
@col.save({:a => 1})
|
122
|
+
end
|
123
|
+
|
124
|
+
should "allow override alternate value on save" do
|
125
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
126
|
+
safe == @safe_value.merge(:w => 1)
|
127
|
+
end
|
128
|
+
@col.save({:a => 1}, :safe => true)
|
129
|
+
end
|
130
|
+
|
131
|
+
should "allow override to disable on save" do
|
132
|
+
@connection.expects(:send_message)
|
133
|
+
@col.save({:a => 1}, :safe => false)
|
134
|
+
end
|
135
|
+
|
103
136
|
should "use default value on remove" do
|
104
|
-
@
|
137
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
105
138
|
safe == @safe_value
|
106
139
|
end
|
107
140
|
|
@@ -109,15 +142,15 @@ class SafeTest < Test::Unit::TestCase
|
|
109
142
|
end
|
110
143
|
|
111
144
|
should "allow override alternate value on remove" do
|
112
|
-
@
|
113
|
-
safe == {:w => 100}
|
145
|
+
@connection.expects(:send_message_with_gle).with do |op, msg, log, n, safe|
|
146
|
+
safe == {:w => 100, :j => false, :fsync => false, :wtimeout => nil}
|
114
147
|
end
|
115
148
|
|
116
149
|
@col.remove({}, :safe => {:w => 100})
|
117
150
|
end
|
118
151
|
|
119
152
|
should "allow override to disable on remove" do
|
120
|
-
@
|
153
|
+
@connection.expects(:send_message)
|
121
154
|
@col.remove({}, :safe => false)
|
122
155
|
end
|
123
156
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'test_helper'
|
16
|
+
include Mongo
|
17
|
+
|
18
|
+
class ShardingPoolManagerUnitTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
context "Initialization: " do
|
21
|
+
|
22
|
+
setup do
|
23
|
+
TCPSocket.stubs(:new).returns(new_mock_socket)
|
24
|
+
@db = new_mock_db
|
25
|
+
|
26
|
+
@client = stub("MongoShardedClient")
|
27
|
+
@client.stubs(:connect_timeout).returns(5)
|
28
|
+
@client.stubs(:op_timeout).returns(5)
|
29
|
+
@client.stubs(:pool_size).returns(2)
|
30
|
+
@client.stubs(:pool_timeout).returns(100)
|
31
|
+
@client.stubs(:socket_class).returns(TCPSocket)
|
32
|
+
@client.stubs(:mongos?).returns(true)
|
33
|
+
@client.stubs(:[]).returns(@db)
|
34
|
+
@client.stubs(:socket_opts)
|
35
|
+
|
36
|
+
@client.stubs(:replica_set_name).returns(nil)
|
37
|
+
@client.stubs(:log)
|
38
|
+
@arbiters = ['localhost:27020']
|
39
|
+
@hosts = [
|
40
|
+
'localhost:27017',
|
41
|
+
'localhost:27018',
|
42
|
+
'localhost:27019'
|
43
|
+
]
|
44
|
+
|
45
|
+
@ismaster = {
|
46
|
+
'hosts' => @hosts,
|
47
|
+
'arbiters' => @arbiters,
|
48
|
+
'maxBsonObjectSize' => 1024,
|
49
|
+
'maxMessageSizeBytes' => 1024 * 2.5,
|
50
|
+
'maxWireVersion' => 1,
|
51
|
+
'minWireVersion' => 0
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
should "populate pools correctly" do
|
56
|
+
|
57
|
+
@db.stubs(:command).returns(
|
58
|
+
# First call to get a socket.
|
59
|
+
@ismaster.merge({'ismaster' => true}),
|
60
|
+
|
61
|
+
# Subsequent calls to configure pools.
|
62
|
+
@ismaster.merge({'ismaster' => true}),
|
63
|
+
@ismaster.merge({'secondary' => true, 'maxBsonObjectSize' => 500}),
|
64
|
+
@ismaster.merge({'secondary' => true, 'maxMessageSizeBytes' => 700}),
|
65
|
+
@ismaster.merge({'secondary' => true, 'maxWireVersion' => 0}),
|
66
|
+
@ismaster.merge({'secondary' => true, 'minWireVersion' => 0}),
|
67
|
+
@ismaster.merge({'arbiterOnly' => true})
|
68
|
+
)
|
69
|
+
|
70
|
+
seed = ['localhost:27017']
|
71
|
+
manager = Mongo::ShardingPoolManager.new(@client, seed)
|
72
|
+
@client.stubs(:local_manager).returns(manager)
|
73
|
+
manager.connect
|
74
|
+
|
75
|
+
formatted_seed = ['localhost', 27017]
|
76
|
+
|
77
|
+
assert manager.seeds.include? formatted_seed
|
78
|
+
assert_equal 500, manager.max_bson_size
|
79
|
+
assert_equal 700, manager.max_message_size
|
80
|
+
assert_equal 0, manager.max_wire_version
|
81
|
+
assert_equal 0, manager.min_wire_version
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'test_helper'
|
16
|
+
|
17
|
+
class WriteConcernUnitTest < Test::Unit::TestCase
|
18
|
+
|
19
|
+
context "Write-Concern modes on Mongo::MongoClient " do
|
20
|
+
setup do
|
21
|
+
@write_concern = {
|
22
|
+
:w => 7,
|
23
|
+
:j => false,
|
24
|
+
:fsync => false,
|
25
|
+
:wtimeout => nil
|
26
|
+
}
|
27
|
+
|
28
|
+
class Mongo::MongoClient
|
29
|
+
public :build_get_last_error_message, :build_command_message
|
30
|
+
end
|
31
|
+
|
32
|
+
@client =
|
33
|
+
MongoClient.new('localhost', 27017,
|
34
|
+
@write_concern.merge({:connect => false}))
|
35
|
+
end
|
36
|
+
|
37
|
+
should "propogate to DB" do
|
38
|
+
db = @client[TEST_DB]
|
39
|
+
assert_equal @write_concern, db.write_concern
|
40
|
+
|
41
|
+
|
42
|
+
db = @client.db(TEST_DB)
|
43
|
+
assert_equal @write_concern, db.write_concern
|
44
|
+
|
45
|
+
db = DB.new(TEST_DB, @client)
|
46
|
+
assert_equal @write_concern, db.write_concern
|
47
|
+
end
|
48
|
+
|
49
|
+
should "allow db override" do
|
50
|
+
db = DB.new(TEST_DB, @client, :w => 0)
|
51
|
+
assert_equal 0, db.write_concern[:w]
|
52
|
+
|
53
|
+
db = @client.db(TEST_DB, :w => 0)
|
54
|
+
assert_equal 0, db.write_concern[:w]
|
55
|
+
end
|
56
|
+
|
57
|
+
context "on DB: " do
|
58
|
+
setup do
|
59
|
+
@db = @client[TEST_DB]
|
60
|
+
end
|
61
|
+
|
62
|
+
should "propogate to collection" do
|
63
|
+
collection = @db.collection('bar')
|
64
|
+
assert_equal @write_concern, collection.write_concern
|
65
|
+
|
66
|
+
collection = @db['bar']
|
67
|
+
assert_equal @write_concern, collection.write_concern
|
68
|
+
|
69
|
+
collection = Collection.new('bar', @db)
|
70
|
+
assert_equal @write_concern, collection.write_concern
|
71
|
+
end
|
72
|
+
|
73
|
+
should "allow override on collection" do
|
74
|
+
collection = @db.collection('bar', :w => 0)
|
75
|
+
assert_equal 0, collection.write_concern[:w]
|
76
|
+
|
77
|
+
collection = Collection.new('bar', @db, :w => 0)
|
78
|
+
assert_equal 0, collection.write_concern[:w]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "on operations supporting 'gle' mode" do
|
83
|
+
setup do
|
84
|
+
@collection = @client[TEST_DB]['bar']
|
85
|
+
end
|
86
|
+
|
87
|
+
should "not send w = 1 to the server" do
|
88
|
+
gle = @client.build_get_last_error_message("fake", {:w => 1})
|
89
|
+
assert_equal gle, @client.build_command_message("fake", {:getlasterror => 1})
|
90
|
+
end
|
91
|
+
|
92
|
+
should "use default value on insert" do
|
93
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
94
|
+
wc == @write_concern
|
95
|
+
end
|
96
|
+
|
97
|
+
@collection.insert({:a => 1})
|
98
|
+
end
|
99
|
+
|
100
|
+
should "allow override alternate value on insert" do
|
101
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
102
|
+
wc == {:w => 100, :j => false, :fsync => false, :wtimeout => nil}
|
103
|
+
end
|
104
|
+
|
105
|
+
@collection.insert({:a => 1}, {:w => 100})
|
106
|
+
end
|
107
|
+
|
108
|
+
should "allow override to disable on insert" do
|
109
|
+
@client.expects(:send_message)
|
110
|
+
@collection.insert({:a => 1}, :w => 0)
|
111
|
+
end
|
112
|
+
|
113
|
+
should "use default value on update" do
|
114
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
115
|
+
wc == @write_concern
|
116
|
+
end
|
117
|
+
|
118
|
+
@collection.update({:a => 1}, {:a => 2})
|
119
|
+
end
|
120
|
+
|
121
|
+
should "allow override alternate value on update" do
|
122
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
123
|
+
wc == {:w => 100, :j => false, :fsync => false, :wtimeout => nil}
|
124
|
+
end
|
125
|
+
|
126
|
+
@collection.update({:a => 1}, {:a => 2}, {:w => 100})
|
127
|
+
end
|
128
|
+
|
129
|
+
should "allow override to disable on update" do
|
130
|
+
@client.expects(:send_message)
|
131
|
+
@collection.update({:a => 1}, {:a => 2}, :w => 0)
|
132
|
+
end
|
133
|
+
|
134
|
+
should "use default value on save" do
|
135
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
136
|
+
wc == @write_concern
|
137
|
+
end
|
138
|
+
@collection.save({:a => 1})
|
139
|
+
end
|
140
|
+
|
141
|
+
should "allow override alternate value on save" do
|
142
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
143
|
+
wc == @write_concern.merge(:w => 1)
|
144
|
+
end
|
145
|
+
@collection.save({:a => 1}, :w => 1)
|
146
|
+
end
|
147
|
+
|
148
|
+
should "allow override to disable on save" do
|
149
|
+
@client.expects(:send_message)
|
150
|
+
@collection.save({:a => 1}, :w => 0)
|
151
|
+
end
|
152
|
+
|
153
|
+
should "use default value on remove" do
|
154
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
155
|
+
wc == @write_concern
|
156
|
+
end
|
157
|
+
|
158
|
+
@collection.remove
|
159
|
+
end
|
160
|
+
|
161
|
+
should "allow override alternate value on remove" do
|
162
|
+
@client.expects(:send_message_with_gle).with do |op, msg, log, n, wc|
|
163
|
+
wc == {:w => 100, :j => false, :fsync => false, :wtimeout => nil}
|
164
|
+
end
|
165
|
+
|
166
|
+
@collection.remove({}, {:w => 100})
|
167
|
+
end
|
168
|
+
|
169
|
+
should "allow override to disable on remove" do
|
170
|
+
@client.expects(:send_message)
|
171
|
+
@collection.remove({}, :w => 0)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
data.tar.gz.sig
ADDED