mongo 1.9.2 → 1.10.0.rc0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE +1 -1
- data/README.md +94 -334
- data/Rakefile +6 -4
- data/VERSION +1 -1
- data/bin/mongo_console +13 -6
- data/lib/mongo.rb +22 -27
- data/lib/mongo/bulk_write_collection_view.rb +352 -0
- data/lib/mongo/collection.rb +128 -188
- data/lib/mongo/collection_writer.rb +348 -0
- data/lib/mongo/connection.rb +19 -0
- data/lib/mongo/{util → connection}/node.rb +15 -1
- data/lib/mongo/{util → connection}/pool.rb +34 -19
- data/lib/mongo/{util → connection}/pool_manager.rb +8 -2
- data/lib/mongo/{util → connection}/sharding_pool_manager.rb +1 -1
- data/lib/mongo/connection/socket.rb +18 -0
- data/lib/mongo/{util → connection/socket}/socket_util.rb +5 -2
- data/lib/mongo/{util → connection/socket}/ssl_socket.rb +3 -4
- data/lib/mongo/{util → connection/socket}/tcp_socket.rb +25 -15
- data/lib/mongo/{util → connection/socket}/unix_socket.rb +6 -4
- data/lib/mongo/cursor.rb +113 -47
- data/lib/mongo/db.rb +203 -131
- data/lib/mongo/{exceptions.rb → exception.rb} +7 -1
- data/lib/mongo/functional.rb +19 -0
- data/lib/mongo/functional/authentication.rb +303 -0
- data/lib/mongo/{util → functional}/logging.rb +1 -1
- data/lib/mongo/{util → functional}/read_preference.rb +49 -1
- data/lib/mongo/{util → functional}/uri_parser.rb +81 -69
- data/lib/mongo/{util → functional}/write_concern.rb +2 -1
- data/{test/unit/pool_test.rb → lib/mongo/gridfs.rb} +5 -10
- data/lib/mongo/gridfs/grid.rb +1 -3
- data/lib/mongo/gridfs/grid_ext.rb +1 -1
- data/lib/mongo/gridfs/grid_file_system.rb +1 -1
- data/lib/mongo/gridfs/grid_io.rb +1 -1
- data/lib/mongo/legacy.rb +63 -8
- data/lib/mongo/mongo_client.rb +128 -154
- data/lib/mongo/mongo_replica_set_client.rb +17 -11
- data/lib/mongo/mongo_sharded_client.rb +2 -1
- data/lib/mongo/networking.rb +19 -10
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo/{util → utils}/conversions.rb +1 -1
- data/lib/mongo/{util → utils}/core_ext.rb +1 -1
- data/lib/mongo/{util → utils}/server_version.rb +1 -1
- data/lib/mongo/{util → utils}/support.rb +10 -57
- data/lib/mongo/{util → utils}/thread_local_variable_manager.rb +1 -1
- data/test/functional/authentication_test.rb +8 -21
- data/test/functional/bulk_write_collection_view_test.rb +782 -0
- data/test/functional/{connection_test.rb → client_test.rb} +153 -78
- data/test/functional/collection_test.rb +343 -97
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/functional/conversions_test.rb +1 -3
- data/test/functional/cursor_fail_test.rb +3 -3
- data/test/functional/cursor_message_test.rb +3 -3
- data/test/functional/cursor_test.rb +38 -3
- data/test/functional/db_api_test.rb +5 -5
- data/test/functional/db_connection_test.rb +2 -2
- data/test/functional/db_test.rb +35 -11
- data/test/functional/grid_file_system_test.rb +2 -2
- data/test/functional/grid_io_test.rb +2 -2
- data/test/functional/grid_test.rb +2 -2
- data/test/functional/pool_test.rb +2 -3
- data/test/functional/safe_test.rb +5 -5
- data/test/functional/ssl_test.rb +22 -102
- data/test/functional/support_test.rb +1 -1
- data/test/functional/timeout_test.rb +6 -22
- data/test/functional/uri_test.rb +113 -12
- data/test/functional/write_concern_test.rb +6 -6
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +309 -0
- data/test/replica_set/authentication_test.rb +8 -23
- data/test/replica_set/basic_test.rb +41 -14
- data/test/replica_set/client_test.rb +179 -117
- data/test/replica_set/complex_connect_test.rb +6 -7
- data/test/replica_set/connection_test.rb +46 -38
- data/test/replica_set/count_test.rb +2 -2
- data/test/replica_set/cursor_test.rb +8 -8
- data/test/replica_set/insert_test.rb +64 -2
- data/test/replica_set/max_values_test.rb +59 -10
- data/test/replica_set/pinning_test.rb +2 -2
- data/test/replica_set/query_test.rb +2 -2
- data/test/replica_set/read_preference_test.rb +6 -6
- data/test/replica_set/refresh_test.rb +7 -7
- data/test/replica_set/replication_ack_test.rb +5 -5
- data/test/replica_set/ssl_test.rb +24 -106
- data/test/sharded_cluster/basic_test.rb +43 -15
- data/test/shared/authentication/basic_auth_shared.rb +215 -0
- data/test/shared/authentication/sasl_plain_shared.rb +96 -0
- data/test/shared/ssl_shared.rb +173 -0
- data/test/test_helper.rb +31 -199
- data/test/threading/basic_test.rb +29 -3
- data/test/tools/mongo_config.rb +45 -20
- data/test/tools/mongo_config_test.rb +1 -1
- data/test/unit/client_test.rb +136 -57
- data/test/unit/collection_test.rb +31 -55
- data/test/unit/connection_test.rb +135 -72
- data/test/unit/cursor_test.rb +2 -2
- data/test/unit/db_test.rb +19 -15
- data/test/unit/grid_test.rb +2 -2
- data/test/unit/mongo_sharded_client_test.rb +17 -15
- data/test/unit/node_test.rb +2 -2
- data/test/unit/pool_manager_test.rb +7 -5
- data/test/unit/read_pref_test.rb +82 -2
- data/test/unit/read_test.rb +14 -14
- data/test/unit/safe_test.rb +9 -9
- data/test/unit/sharding_pool_manager_test.rb +11 -5
- data/test/unit/write_concern_test.rb +9 -9
- metadata +71 -56
- metadata.gz.sig +0 -0
- data/test/functional/threading_test.rb +0 -109
- data/test/shared/authentication.rb +0 -121
- data/test/unit/util_test.rb +0 -69
data/test/unit/cursor_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
|
-
class
|
17
|
+
class CursorUnitTest < Test::Unit::TestCase
|
18
18
|
class Mongo::Cursor
|
19
19
|
public :construct_query_spec
|
20
20
|
end
|
data/test/unit/db_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -23,7 +23,7 @@ def insert_message(db, documents)
|
|
23
23
|
message = db.add_message_headers(Mongo::Constants::OP_INSERT, message)
|
24
24
|
end
|
25
25
|
|
26
|
-
class
|
26
|
+
class DBUnitTest < Test::Unit::TestCase
|
27
27
|
context "DBTest: " do
|
28
28
|
context "DB commands" do
|
29
29
|
setup do
|
@@ -32,6 +32,7 @@ class DBTest < Test::Unit::TestCase
|
|
32
32
|
@client.stubs(:read).returns(:primary)
|
33
33
|
@client.stubs(:tag_sets)
|
34
34
|
@client.stubs(:acceptable_latency)
|
35
|
+
@client.stubs(:add_auth).returns({})
|
35
36
|
@db = DB.new("testing", @client)
|
36
37
|
@db.stubs(:safe)
|
37
38
|
@db.stubs(:read)
|
@@ -55,11 +56,18 @@ class DBTest < Test::Unit::TestCase
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
59
|
+
should "not include named nil opts in selector" do
|
60
|
+
@cursor = mock(:next_document => {"ok" => 1})
|
61
|
+
Cursor.expects(:new).with(@collection, :limit => -1,
|
62
|
+
:selector => {:ping => 1}, :socket => nil).returns(@cursor)
|
63
|
+
command = {:ping => 1}
|
64
|
+
@db.command(command, :socket => nil)
|
65
|
+
end
|
66
|
+
|
58
67
|
should "create the proper cursor" do
|
59
68
|
@cursor = mock(:next_document => {"ok" => 1})
|
60
69
|
Cursor.expects(:new).with(@collection,
|
61
|
-
:limit => -1, :selector => {:buildinfo => 1}
|
62
|
-
:socket => nil, :read => nil, :comment => nil).returns(@cursor)
|
70
|
+
:limit => -1, :selector => {:buildinfo => 1}).returns(@cursor)
|
63
71
|
command = {:buildinfo => 1}
|
64
72
|
@db.command(command, :check_response => true)
|
65
73
|
end
|
@@ -67,8 +75,7 @@ class DBTest < Test::Unit::TestCase
|
|
67
75
|
should "raise an error when the command fails" do
|
68
76
|
@cursor = mock(:next_document => {"ok" => 0})
|
69
77
|
Cursor.expects(:new).with(@collection,
|
70
|
-
:limit => -1, :selector => {:buildinfo => 1}
|
71
|
-
:socket => nil, :read => nil, :comment => nil).returns(@cursor)
|
78
|
+
:limit => -1, :selector => {:buildinfo => 1}).returns(@cursor)
|
72
79
|
assert_raise OperationFailure do
|
73
80
|
command = {:buildinfo => 1}
|
74
81
|
@db.command(command, :check_response => true)
|
@@ -79,21 +86,13 @@ class DBTest < Test::Unit::TestCase
|
|
79
86
|
@cursor = mock(:next_document => {"ok" => 0})
|
80
87
|
Cursor.expects(:new).with(@collection,
|
81
88
|
:limit => -1, :selector => {:buildinfo => 1},
|
82
|
-
:
|
89
|
+
:comment => "my comment").returns(@cursor)
|
83
90
|
assert_raise OperationFailure do
|
84
91
|
command = {:buildinfo => 1}
|
85
92
|
@db.command(command, :check_response => true, :comment => 'my comment')
|
86
93
|
end
|
87
94
|
end
|
88
95
|
|
89
|
-
should "raise an error if logging out fails" do
|
90
|
-
@db.expects(:command).returns({})
|
91
|
-
@client.expects(:auths).returns([])
|
92
|
-
assert_raise Mongo::MongoDBError do
|
93
|
-
@db.logout
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
96
|
should "raise an error if collection creation fails" do
|
98
97
|
@db.expects(:command).returns({'ok' => 0})
|
99
98
|
assert_raise Mongo::MongoDBError do
|
@@ -121,6 +120,11 @@ class DBTest < Test::Unit::TestCase
|
|
121
120
|
@db.profiling_level = :slow_only
|
122
121
|
end
|
123
122
|
end
|
123
|
+
|
124
|
+
should "warn when save_auth is not nil" do
|
125
|
+
assert @db.expects(:warn).with(regexp_matches(/\[DEPRECATED\] Disabling the 'save_auth' option/))
|
126
|
+
@db.authenticate('foo', 'bar', false)
|
127
|
+
end
|
124
128
|
end
|
125
129
|
end
|
126
130
|
end
|
data/test/unit/grid_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
|
-
class
|
17
|
+
class GridUnitTest < Test::Unit::TestCase
|
18
18
|
|
19
19
|
context "GridFS: " do
|
20
20
|
setup do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,23 +14,23 @@
|
|
14
14
|
|
15
15
|
require "test_helper"
|
16
16
|
|
17
|
-
class
|
17
|
+
class MongoShardedClientUnitTest < Test::Unit::TestCase
|
18
18
|
include Mongo
|
19
19
|
|
20
|
-
def setup
|
21
|
-
ENV["MONGODB_URI"] = nil
|
22
|
-
end
|
23
|
-
|
24
20
|
def test_initialize_with_single_mongos_uri
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
uri = "mongodb://localhost:27017"
|
22
|
+
with_preserved_env_uri(uri) do
|
23
|
+
client = MongoShardedClient.new(:connect => false)
|
24
|
+
assert_equal [[ "localhost", 27017 ]], client.seeds
|
25
|
+
end
|
28
26
|
end
|
29
27
|
|
30
28
|
def test_initialize_with_multiple_mongos_uris
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
uri = "mongodb://localhost:27017,localhost:27018"
|
30
|
+
with_preserved_env_uri(uri) do
|
31
|
+
client = MongoShardedClient.new(:connect => false)
|
32
|
+
assert_equal [[ "localhost", 27017 ], [ "localhost", 27018 ]], client.seeds
|
33
|
+
end
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_from_uri_with_string
|
@@ -39,8 +39,10 @@ class MongoShardedClientTest < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_from_uri_with_env_variable
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
uri = "mongodb://localhost:27017,localhost:27018"
|
43
|
+
with_preserved_env_uri(uri) do
|
44
|
+
client = MongoShardedClient.from_uri(nil, :connect => false)
|
45
|
+
assert_equal [[ "localhost", 27017 ], [ "localhost", 27018 ]], client.seeds
|
46
|
+
end
|
45
47
|
end
|
46
48
|
end
|
data/test/unit/node_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
|
-
class
|
17
|
+
class NodeUnitTest < Test::Unit::TestCase
|
18
18
|
|
19
19
|
def setup
|
20
20
|
@client = stub()
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -15,7 +15,7 @@
|
|
15
15
|
require 'test_helper'
|
16
16
|
include Mongo
|
17
17
|
|
18
|
-
class
|
18
|
+
class PoolManagerUnitTest < Test::Unit::TestCase
|
19
19
|
|
20
20
|
context "Initialization: " do
|
21
21
|
|
@@ -47,8 +47,10 @@ class PoolManagerTest < Test::Unit::TestCase
|
|
47
47
|
@ismaster = {
|
48
48
|
'hosts' => @hosts,
|
49
49
|
'arbiters' => @arbiters,
|
50
|
+
'maxBsonObjectSize' => 1024,
|
50
51
|
'maxMessageSizeBytes' => 1024 * 2.5,
|
51
|
-
'
|
52
|
+
'maxWireVersion' => 1,
|
53
|
+
'minWireVersion' => 0
|
52
54
|
}
|
53
55
|
end
|
54
56
|
|
@@ -60,8 +62,8 @@ class PoolManagerTest < Test::Unit::TestCase
|
|
60
62
|
|
61
63
|
# Subsequent calls to configure pools.
|
62
64
|
@ismaster.merge({'ismaster' => true}),
|
63
|
-
@ismaster.merge({'secondary' => true, 'maxMessageSizeBytes' => 700}),
|
64
65
|
@ismaster.merge({'secondary' => true, 'maxBsonObjectSize' => 500}),
|
66
|
+
@ismaster.merge({'secondary' => true, 'maxMessageSizeBytes' => 700}),
|
65
67
|
@ismaster.merge({'arbiterOnly' => true})
|
66
68
|
)
|
67
69
|
|
@@ -76,7 +78,7 @@ class PoolManagerTest < Test::Unit::TestCase
|
|
76
78
|
assert_equal [27018, 27019], manager.secondary_pools.map(&:port).sort
|
77
79
|
assert_equal [['localhost', 27020]], manager.arbiters
|
78
80
|
assert_equal 500, manager.max_bson_size
|
79
|
-
assert_equal 700
|
81
|
+
assert_equal 700, manager.max_message_size
|
80
82
|
end
|
81
83
|
|
82
84
|
should "populate pools with single unqueryable seed" do
|
data/test/unit/read_pref_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,7 +14,8 @@
|
|
14
14
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
|
-
class
|
17
|
+
class ReadPreferenceUnitTest < Test::Unit::TestCase
|
18
|
+
|
18
19
|
include ReadPreference
|
19
20
|
|
20
21
|
def setup
|
@@ -32,4 +33,83 @@ class ReadPrefTest < Test::Unit::TestCase
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
36
|
+
def test_sok_mapreduce_out_string_returns_false
|
37
|
+
command = BSON::OrderedHash['mapreduce', 'test-collection',
|
38
|
+
'out', 'new-test-collection']
|
39
|
+
assert_equal false, ReadPreference::secondary_ok?(command)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_sok_mapreduce_replace_collection_returns_false
|
43
|
+
command = BSON::OrderedHash['mapreduce', 'test-collection',
|
44
|
+
'out', BSON::OrderedHash['replace', 'new-test-collection']]
|
45
|
+
assert_equal false, ReadPreference::secondary_ok?(command)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_sok_mapreduce_inline_collection_returns_false
|
49
|
+
command = BSON::OrderedHash['mapreduce', 'test-collection',
|
50
|
+
'out', 'inline']
|
51
|
+
assert_equal false, ReadPreference::secondary_ok?(command)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_sok_inline_symbol_mapreduce_returns_true
|
55
|
+
command = BSON::OrderedHash['mapreduce', 'test-collection',
|
56
|
+
'out', BSON::OrderedHash[:inline, 'true']]
|
57
|
+
assert_equal true, ReadPreference::secondary_ok?(command)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_sok_inline_string_mapreduce_returns_true
|
61
|
+
command = BSON::OrderedHash['mapreduce', 'test-collection',
|
62
|
+
'out', BSON::OrderedHash['inline', 'true']]
|
63
|
+
assert_equal true, ReadPreference::secondary_ok?(command)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_sok_count_true
|
67
|
+
command = BSON::OrderedHash['count', 'test-collection',
|
68
|
+
'query', BSON::OrderedHash['a', 'b']]
|
69
|
+
assert_equal true, ReadPreference::secondary_ok?(command)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_sok_server_status_returns_false
|
73
|
+
command = BSON::OrderedHash['serverStatus', 1]
|
74
|
+
assert_equal false, ReadPreference::secondary_ok?(command)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_cmd_reroute_with_secondary
|
78
|
+
ReadPreference::expects(:warn).with(regexp_matches(/rerouted to primary/))
|
79
|
+
command = BSON::OrderedHash['mapreduce', 'test-collection',
|
80
|
+
'out', 'new-test-collection']
|
81
|
+
assert_equal :primary, ReadPreference::cmd_read_pref(:secondary, command)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_find_and_modify_reroute_with_secondary
|
85
|
+
ReadPreference::expects(:warn).with(regexp_matches(/rerouted to primary/))
|
86
|
+
command = BSON::OrderedHash['findAndModify', 'test-collection',
|
87
|
+
'query', {}]
|
88
|
+
assert_equal :primary, ReadPreference::cmd_read_pref(:secondary, command)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_cmd_no_reroute_with_secondary
|
92
|
+
command = BSON::OrderedHash['mapreduce', 'test-collection',
|
93
|
+
'out', BSON::OrderedHash['inline', 'true']]
|
94
|
+
assert_equal :secondary, ReadPreference::cmd_read_pref(:secondary, command)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_cmd_no_reroute_with_primary
|
98
|
+
command = BSON::OrderedHash['mapreduce', 'test-collection',
|
99
|
+
'out', 'new-test-collection']
|
100
|
+
assert_equal :primary, ReadPreference::cmd_read_pref(:primary, command)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_cmd_no_reroute_with_primary_secondary_ok
|
104
|
+
command = BSON::OrderedHash['mapreduce', 'test-collection',
|
105
|
+
'out', BSON::OrderedHash['inline', 'true']]
|
106
|
+
assert_equal :primary, ReadPreference::cmd_read_pref(:primary, command)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_parallel_scan_secondary_ok
|
110
|
+
command = BSON::OrderedHash['parallelCollectionScan', 'test-collection',
|
111
|
+
'numCursors', 3]
|
112
|
+
assert_equal true, ReadPreference::secondary_ok?(command)
|
113
|
+
end
|
114
|
+
|
35
115
|
end
|
data/test/unit/read_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
|
-
class
|
17
|
+
class ReadUnitTest < Test::Unit::TestCase
|
18
18
|
|
19
19
|
context "Read mode on standard connection: " do
|
20
20
|
setup do
|
@@ -46,29 +46,29 @@ class ReadTest < Test::Unit::TestCase
|
|
46
46
|
end
|
47
47
|
|
48
48
|
should "propogate to DB" do
|
49
|
-
db = @client[
|
49
|
+
db = @client[TEST_DB]
|
50
50
|
assert_equal @read, db.read
|
51
51
|
assert_equal @tags, db.tag_sets
|
52
52
|
assert_equal @acceptable_latency, db.acceptable_latency
|
53
53
|
|
54
|
-
db = @client.db(
|
54
|
+
db = @client.db(TEST_DB)
|
55
55
|
assert_equal @read, db.read
|
56
56
|
assert_equal @tags, db.tag_sets
|
57
57
|
assert_equal @acceptable_latency, db.acceptable_latency
|
58
58
|
|
59
|
-
db = DB.new(
|
59
|
+
db = DB.new(TEST_DB, @client)
|
60
60
|
assert_equal @read, db.read
|
61
61
|
assert_equal @tags, db.tag_sets
|
62
62
|
assert_equal @acceptable_latency, db.acceptable_latency
|
63
63
|
end
|
64
64
|
|
65
65
|
should "allow db override" do
|
66
|
-
db = DB.new(
|
66
|
+
db = DB.new(TEST_DB, @client, :read => :primary, :tag_sets => @bad_tags, :acceptable_latency => 25)
|
67
67
|
assert_equal :primary, db.read
|
68
68
|
assert_equal @bad_tags, db.tag_sets
|
69
69
|
assert_equal 25, db.acceptable_latency
|
70
70
|
|
71
|
-
db = @client.db(
|
71
|
+
db = @client.db(TEST_DB, :read => :primary, :tag_sets => @bad_tags, :acceptable_latency => 25)
|
72
72
|
assert_equal :primary, db.read
|
73
73
|
assert_equal @bad_tags, db.tag_sets
|
74
74
|
assert_equal 25, db.acceptable_latency
|
@@ -76,33 +76,33 @@ class ReadTest < Test::Unit::TestCase
|
|
76
76
|
|
77
77
|
context "on DB: " do
|
78
78
|
setup do
|
79
|
-
@db = @client[
|
79
|
+
@db = @client[TEST_DB]
|
80
80
|
end
|
81
81
|
|
82
82
|
should "propogate to collection" do
|
83
|
-
col = @db.collection('
|
83
|
+
col = @db.collection('read-unit-test')
|
84
84
|
assert_equal @read, col.read
|
85
85
|
assert_equal @tags, col.tag_sets
|
86
86
|
assert_equal @acceptable_latency, col.acceptable_latency
|
87
87
|
|
88
|
-
col = @db['
|
88
|
+
col = @db['read-unit-test']
|
89
89
|
assert_equal @read, col.read
|
90
90
|
assert_equal @tags, col.tag_sets
|
91
91
|
assert_equal @acceptable_latency, col.acceptable_latency
|
92
92
|
|
93
|
-
col = Collection.new('
|
93
|
+
col = Collection.new('read-unit-test', @db)
|
94
94
|
assert_equal @read, col.read
|
95
95
|
assert_equal @tags, col.tag_sets
|
96
96
|
assert_equal @acceptable_latency, col.acceptable_latency
|
97
97
|
end
|
98
98
|
|
99
99
|
should "allow override on collection" do
|
100
|
-
col = @db.collection('
|
100
|
+
col = @db.collection('read-unit-test', :read => :primary, :tag_sets => @bad_tags, :acceptable_latency => 25)
|
101
101
|
assert_equal :primary, col.read
|
102
102
|
assert_equal @bad_tags, col.tag_sets
|
103
103
|
assert_equal 25, col.acceptable_latency
|
104
104
|
|
105
|
-
col = Collection.new('
|
105
|
+
col = Collection.new('read-unit-test', @db, :read => :primary, :tag_sets => @bad_tags, :acceptable_latency => 25)
|
106
106
|
assert_equal :primary, col.read
|
107
107
|
assert_equal @bad_tags, col.tag_sets
|
108
108
|
assert_equal 25, col.acceptable_latency
|
@@ -111,7 +111,7 @@ class ReadTest < Test::Unit::TestCase
|
|
111
111
|
|
112
112
|
context "on read mode ops" do
|
113
113
|
setup do
|
114
|
-
@col = @client[
|
114
|
+
@col = @client[TEST_DB]['read-unit-test']
|
115
115
|
@mock_socket = new_mock_socket
|
116
116
|
end
|
117
117
|
|
data/test/unit/safe_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
|
-
class
|
17
|
+
class SafeUnitTest < Test::Unit::TestCase
|
18
18
|
|
19
19
|
context "Write-Concern modes on Mongo::Connection " do
|
20
20
|
setup do
|
@@ -23,28 +23,28 @@ class SafeTest < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
should "propogate to DB" do
|
26
|
-
db = @connection[
|
26
|
+
db = @connection[TEST_DB]
|
27
27
|
assert_equal @safe_value[:w], db.write_concern[:w]
|
28
28
|
|
29
29
|
|
30
|
-
db = @connection.db(
|
30
|
+
db = @connection.db(TEST_DB)
|
31
31
|
assert_equal @safe_value[:w], db.write_concern[:w]
|
32
32
|
|
33
|
-
db = DB.new(
|
33
|
+
db = DB.new(TEST_DB, @connection)
|
34
34
|
assert_equal @safe_value[:w], db.write_concern[:w]
|
35
35
|
end
|
36
36
|
|
37
37
|
should "allow db override" do
|
38
|
-
db = DB.new(
|
38
|
+
db = DB.new(TEST_DB, @connection, :safe => false)
|
39
39
|
assert_equal 0, db.write_concern[:w]
|
40
40
|
|
41
|
-
db = @connection.db(
|
41
|
+
db = @connection.db(TEST_DB, :safe => false)
|
42
42
|
assert_equal 0, db.write_concern[:w]
|
43
43
|
end
|
44
44
|
|
45
45
|
context "on DB: " do
|
46
46
|
setup do
|
47
|
-
@db = @connection[
|
47
|
+
@db = @connection[TEST_DB]
|
48
48
|
end
|
49
49
|
|
50
50
|
should "propogate to collection" do
|
@@ -69,7 +69,7 @@ class SafeTest < Test::Unit::TestCase
|
|
69
69
|
|
70
70
|
context "on operations supporting safe mode" do
|
71
71
|
setup do
|
72
|
-
@col = @connection[
|
72
|
+
@col = @connection[TEST_DB]['bar']
|
73
73
|
end
|
74
74
|
|
75
75
|
should "use default value on insert" do
|