mongo 1.7.1 → 1.8.0

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.
Files changed (138) hide show
  1. data/{LICENSE.txt → LICENSE} +0 -0
  2. data/README.md +124 -111
  3. data/Rakefile +9 -325
  4. data/VERSION +1 -0
  5. data/bin/mongo_console +4 -4
  6. data/examples/admin.rb +43 -0
  7. data/examples/capped.rb +22 -0
  8. data/examples/cursor.rb +48 -0
  9. data/examples/gridfs.rb +44 -0
  10. data/examples/index_test.rb +126 -0
  11. data/examples/info.rb +31 -0
  12. data/examples/queries.rb +74 -0
  13. data/examples/replica_set.rb +26 -0
  14. data/examples/simple.rb +25 -0
  15. data/examples/strict.rb +35 -0
  16. data/examples/types.rb +36 -0
  17. data/{test/load → examples/web}/thin/load.rb +3 -1
  18. data/{test/load → examples/web}/unicorn/load.rb +5 -3
  19. data/lib/mongo.rb +8 -10
  20. data/lib/mongo/collection.rb +134 -114
  21. data/lib/mongo/cursor.rb +21 -14
  22. data/lib/mongo/db.rb +30 -28
  23. data/lib/mongo/exceptions.rb +1 -1
  24. data/lib/mongo/gridfs/grid.rb +8 -7
  25. data/lib/mongo/gridfs/grid_ext.rb +1 -1
  26. data/lib/mongo/gridfs/grid_file_system.rb +6 -5
  27. data/lib/mongo/gridfs/grid_io.rb +22 -19
  28. data/lib/mongo/legacy.rb +82 -0
  29. data/lib/mongo/{connection.rb → mongo_client.rb} +82 -61
  30. data/lib/mongo/{repl_set_connection.rb → mongo_replica_set_client.rb} +54 -39
  31. data/lib/mongo/{sharded_connection.rb → mongo_sharded_client.rb} +9 -9
  32. data/lib/mongo/networking.rb +25 -20
  33. data/lib/mongo/util/conversions.rb +1 -1
  34. data/lib/mongo/util/core_ext.rb +1 -1
  35. data/lib/mongo/util/logging.rb +20 -4
  36. data/lib/mongo/util/node.rb +16 -16
  37. data/lib/mongo/util/pool.rb +56 -27
  38. data/lib/mongo/util/pool_manager.rb +28 -27
  39. data/lib/mongo/util/server_version.rb +1 -1
  40. data/lib/mongo/util/sharding_pool_manager.rb +8 -8
  41. data/lib/mongo/util/ssl_socket.rb +1 -5
  42. data/lib/mongo/util/support.rb +24 -8
  43. data/lib/mongo/util/tcp_socket.rb +0 -4
  44. data/lib/mongo/util/uri_parser.rb +54 -38
  45. data/lib/mongo/util/write_concern.rb +67 -0
  46. data/mongo.gemspec +21 -32
  47. data/test/auxillary/{1.4_features.rb → 1.4_feature_test.rb} +4 -5
  48. data/test/auxillary/authentication_test.rb +18 -20
  49. data/test/auxillary/autoreconnect_test.rb +3 -5
  50. data/test/auxillary/fork_test.rb +5 -7
  51. data/test/auxillary/repl_set_auth_test.rb +13 -15
  52. data/test/auxillary/slave_connection_test.rb +8 -7
  53. data/test/auxillary/threaded_authentication_test.rb +15 -17
  54. data/test/bson/binary_test.rb +1 -1
  55. data/test/bson/bson_test.rb +60 -36
  56. data/test/bson/byte_buffer_test.rb +1 -1
  57. data/test/bson/hash_with_indifferent_access_test.rb +2 -2
  58. data/test/bson/json_test.rb +1 -2
  59. data/test/bson/object_id_test.rb +1 -2
  60. data/test/bson/ordered_hash_test.rb +1 -1
  61. data/test/bson/timestamp_test.rb +1 -1
  62. data/test/{collection_test.rb → functional/collection_test.rb} +57 -57
  63. data/test/{connection_test.rb → functional/connection_test.rb} +75 -89
  64. data/test/{conversions_test.rb → functional/conversions_test.rb} +1 -1
  65. data/test/{cursor_fail_test.rb → functional/cursor_fail_test.rb} +3 -29
  66. data/test/{cursor_message_test.rb → functional/cursor_message_test.rb} +1 -1
  67. data/test/{cursor_test.rb → functional/cursor_test.rb} +5 -1
  68. data/test/{db_api_test.rb → functional/db_api_test.rb} +8 -9
  69. data/test/{db_connection_test.rb → functional/db_connection_test.rb} +3 -5
  70. data/test/{db_test.rb → functional/db_test.rb} +13 -13
  71. data/test/{grid_file_system_test.rb → functional/grid_file_system_test.rb} +2 -2
  72. data/test/{grid_io_test.rb → functional/grid_io_test.rb} +6 -6
  73. data/test/{grid_test.rb → functional/grid_test.rb} +4 -10
  74. data/test/{pool_test.rb → functional/pool_test.rb} +1 -1
  75. data/test/functional/safe_test.rb +84 -0
  76. data/test/{support_test.rb → functional/support_test.rb} +1 -1
  77. data/test/{threading_test.rb → functional/threading_test.rb} +9 -9
  78. data/test/{timeout_test.rb → functional/timeout_test.rb} +1 -1
  79. data/test/{uri_test.rb → functional/uri_test.rb} +1 -1
  80. data/test/functional/write_concern_test.rb +104 -0
  81. data/test/replica_set/basic_test.rb +139 -0
  82. data/test/replica_set/client_test.rb +255 -0
  83. data/test/replica_set/complex_connect_test.rb +62 -0
  84. data/test/replica_set/connection_test.rb +255 -0
  85. data/test/{replica_sets → replica_set}/count_test.rb +17 -14
  86. data/test/replica_set/cursor_test.rb +75 -0
  87. data/test/{replica_sets → replica_set}/insert_test.rb +19 -16
  88. data/test/replica_set/query_test.rb +64 -0
  89. data/test/replica_set/refresh_test.rb +153 -0
  90. data/test/{replica_sets → replica_set}/replication_ack_test.rb +21 -17
  91. data/test/sharded_cluster/basic_test.rb +31 -50
  92. data/test/support/hash_with_indifferent_access.rb +1 -1
  93. data/test/test_helper.rb +56 -9
  94. data/test/threading/threading_with_large_pool_test.rb +8 -8
  95. data/test/tools/mongo_config.rb +270 -58
  96. data/test/tools/mongo_config_test.rb +146 -0
  97. data/test/unit/client_test.rb +230 -0
  98. data/test/unit/collection_test.rb +45 -32
  99. data/test/unit/connection_test.rb +82 -74
  100. data/test/unit/cursor_test.rb +14 -6
  101. data/test/unit/db_test.rb +8 -8
  102. data/test/unit/grid_test.rb +11 -11
  103. data/test/unit/node_test.rb +24 -24
  104. data/test/unit/pool_manager_test.rb +13 -13
  105. data/test/unit/pool_test.rb +1 -1
  106. data/test/unit/read_test.rb +21 -26
  107. data/test/unit/safe_test.rb +52 -33
  108. data/test/unit/util_test.rb +55 -0
  109. data/test/unit/write_concern_test.rb +161 -0
  110. metadata +158 -171
  111. data/docs/CREDITS.md +0 -123
  112. data/docs/FAQ.md +0 -116
  113. data/docs/GRID_FS.md +0 -158
  114. data/docs/HISTORY.md +0 -392
  115. data/docs/READ_PREFERENCE.md +0 -99
  116. data/docs/RELEASES.md +0 -54
  117. data/docs/REPLICA_SETS.md +0 -113
  118. data/docs/TAILABLE_CURSORS.md +0 -51
  119. data/docs/TUTORIAL.md +0 -356
  120. data/docs/WRITE_CONCERN.md +0 -31
  121. data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
  122. data/lib/mongo/version.rb +0 -3
  123. data/test/bson/test_helper.rb +0 -30
  124. data/test/replica_sets/basic_test.rb +0 -119
  125. data/test/replica_sets/complex_connect_test.rb +0 -57
  126. data/test/replica_sets/complex_read_preference_test.rb +0 -237
  127. data/test/replica_sets/connect_test.rb +0 -156
  128. data/test/replica_sets/cursor_test.rb +0 -70
  129. data/test/replica_sets/pooled_insert_test.rb +0 -57
  130. data/test/replica_sets/query_test.rb +0 -50
  131. data/test/replica_sets/read_preference_test.rb +0 -234
  132. data/test/replica_sets/refresh_test.rb +0 -156
  133. data/test/replica_sets/refresh_with_threads_test.rb +0 -60
  134. data/test/replica_sets/rs_test_helper.rb +0 -39
  135. data/test/safe_test.rb +0 -68
  136. data/test/sharded_cluster/mongo_config_test.rb +0 -126
  137. data/test/sharded_cluster/sc_test_helper.rb +0 -39
  138. data/test/tools/repl_set_manager.rb +0 -418
@@ -1,132 +1,140 @@
1
- require File.expand_path("../../test_helper", __FILE__)
2
- include Mongo
1
+ require 'test_helper'
3
2
 
4
3
  class ConnectionTest < Test::Unit::TestCase
5
- context "Initialization: " do
4
+ context "Mongo::MongoClient intialization " do
6
5
  context "given a single node" do
7
6
  setup do
8
- @conn = Connection.new('localhost', 27017, :connect => false)
7
+ @connection = Mongo::Connection.new('localhost', 27017, :safe => true, :connect => false)
9
8
  TCPSocket.stubs(:new).returns(new_mock_socket)
10
9
 
11
10
  admin_db = new_mock_db
12
11
  admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
13
- @conn.expects(:[]).with('admin').returns(admin_db)
14
- @conn.connect
12
+ @connection.expects(:[]).with('admin').returns(admin_db)
13
+ @connection.connect
14
+ end
15
+
16
+ should "set safe mode true" do
17
+ assert_equal true, @connection.safe
15
18
  end
16
19
 
17
20
  should "set localhost and port to master" do
18
- assert_equal 'localhost', @conn.primary_pool.host
19
- assert_equal 27017, @conn.primary_pool.port
21
+ assert_equal 'localhost', @connection.primary_pool.host
22
+ assert_equal 27017, @connection.primary_pool.port
20
23
  end
21
24
 
22
25
  should "set connection pool to 1" do
23
- assert_equal 1, @conn.primary_pool.size
26
+ assert_equal 1, @connection.primary_pool.size
24
27
  end
25
28
 
26
29
  should "default slave_ok to false" do
27
- assert !@conn.slave_ok?
30
+ assert !@connection.slave_ok?
31
+ end
32
+
33
+ should "raise exception for invalid host or port" do
34
+ assert_raise MongoArgumentError do
35
+ Mongo::Connection.new(:safe => true)
36
+ end
37
+ assert_raise MongoArgumentError do
38
+ Mongo::Connection.new('localhost', :safe => true)
39
+ end
28
40
  end
29
41
 
30
42
  should "warn if invalid options are specified" do
31
- conn = Connection.allocate
43
+ connection = Mongo::Connection.allocate
32
44
  opts = {:connect => false}
33
45
 
34
- ReplSetConnection::REPL_SET_OPTS.each do |opt|
35
- conn.expects(:warn).with("#{opt} is not a valid option for #{conn.class}")
46
+ Mongo::ReplSetConnection::REPL_SET_OPTS.each do |opt|
47
+ connection.expects(:warn).with("#{opt} is not a valid option for #{connection.class}")
36
48
  opts[opt] = true
37
49
  end
38
50
 
39
51
  args = ['localhost', 27017, opts]
40
- conn.send(:initialize, *args)
52
+ connection.send(:initialize, *args)
41
53
  end
42
54
 
43
55
  context "given a replica set" do
44
- #should "enforce a minimum refresh_interval" do
45
- # @conn = ReplSetConnection.new(['localhost:27017'],
46
- # :connect => false, :refresh_mode => :sync, :refresh_interval => 10)
47
- # assert_equal 60, @conn.refresh_interval
48
- #end
49
-
50
- should "warn if invalid options are specified" do
51
- conn = ReplSetConnection.allocate
52
- opts = {:connect => false}
53
-
54
- Connection::CONNECTION_OPTS.each do |opt|
55
- conn.expects(:warn).with("#{opt} is not a valid option for #{conn.class}")
56
- opts[opt] = true
57
- end
58
-
59
- args = [['localhost:27017'], opts]
60
- conn.send(:initialize, *args)
61
- end
56
+
57
+ # should "warn if invalid options are specified" do
58
+ # connection = Mongo::ReplSetConnection.allocate
59
+ # opts = {:connect => false}
60
+
61
+ # # Mongo::Connection::CLIENT_ONLY_OPTS.each do |opt|
62
+ # connection.expects(:warn).with("#{:slave_ok} is not a valid option for #{connection.class}")
63
+ # opts[:slave_ok] = true
64
+ # # end
65
+
66
+ # args = [['localhost:27017'], opts]
67
+ # connection.send(:initialize, *args)
68
+ # end
69
+
62
70
  end
63
71
  end
64
72
 
65
73
  context "initializing with a mongodb uri" do
66
74
  should "parse a simple uri" do
67
- @conn = Connection.from_uri("mongodb://localhost", :connect => false)
68
- assert_equal ['localhost', 27017], @conn.host_to_try
75
+ @connection = Mongo::Connection.from_uri("mongodb://localhost", :connect => false)
76
+ assert_equal ['localhost', 27017], @connection.host_to_try
69
77
  end
70
78
 
71
79
  should "allow a complex host names" do
72
80
  host_name = "foo.bar-12345.org"
73
- @conn = Connection.from_uri("mongodb://#{host_name}", :connect => false)
74
- assert_equal [host_name, 27017], @conn.host_to_try
81
+ @connection = Mongo::Connection.from_uri("mongodb://#{host_name}", :connect => false)
82
+ assert_equal [host_name, 27017], @connection.host_to_try
75
83
  end
76
84
 
77
85
  should "allow db without username and password" do
78
86
  host_name = "foo.bar-12345.org"
79
- @conn = Connection.from_uri("mongodb://#{host_name}/foo", :connect => false)
80
- assert_equal [host_name, 27017], @conn.host_to_try
87
+ @connection = Mongo::Connection.from_uri("mongodb://#{host_name}/foo", :connect => false)
88
+ assert_equal [host_name, 27017], @connection.host_to_try
81
89
  end
82
90
 
83
91
  should "set safe options on connection" do
84
92
  host_name = "localhost"
85
93
  opts = "safe=true&w=2&wtimeoutMS=1000&fsync=true&journal=true"
86
- @conn = Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
87
- assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @conn.safe)
94
+ @connection = Mongo::Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
95
+ assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @connection.write_concern)
88
96
  end
89
97
 
90
98
  should "set timeout options on connection" do
91
99
  host_name = "localhost"
92
100
  opts = "connectTimeoutMS=1000&socketTimeoutMS=5000"
93
- @conn = Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
94
- assert_equal 1, @conn.connect_timeout
95
- assert_equal 5, @conn.op_timeout
101
+ @connection = Mongo::Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
102
+ assert_equal 1, @connection.connect_timeout
103
+ assert_equal 5, @connection.op_timeout
96
104
  end
97
105
 
98
106
  should "parse a uri with a hyphen & underscore in the username or password" do
99
- @conn = Connection.from_uri("mongodb://hyphen-user_name:p-s_s@localhost:27017/db", :connect => false)
100
- assert_equal ['localhost', 27017], @conn.host_to_try
107
+ @connection = Mongo::Connection.from_uri("mongodb://hyphen-user_name:p-s_s@localhost:27017/db", :connect => false)
108
+ assert_equal ['localhost', 27017], @connection.host_to_try
101
109
  auth_hash = { 'db_name' => 'db', 'username' => 'hyphen-user_name', "password" => 'p-s_s' }
102
- assert_equal auth_hash, @conn.auths[0]
110
+ assert_equal auth_hash, @connection.auths[0]
103
111
  end
104
112
 
105
113
  should "attempt to connect" do
106
114
  TCPSocket.stubs(:new).returns(new_mock_socket)
107
- @conn = Connection.from_uri("mongodb://localhost", :connect => false)
115
+ @connection = Mongo::Connection.from_uri("mongodb://localhost", :connect => false)
108
116
 
109
117
  admin_db = new_mock_db
110
118
  admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
111
- @conn.expects(:[]).with('admin').returns(admin_db)
112
- @conn.connect
119
+ @connection.expects(:[]).with('admin').returns(admin_db)
120
+ @connection.connect
113
121
  end
114
122
 
115
123
  should "raise an error on invalid uris" do
116
124
  assert_raise MongoArgumentError do
117
- Connection.from_uri("mongo://localhost", :connect => false)
125
+ Mongo::Connection.from_uri("mongo://localhost", :connect => false)
118
126
  end
119
127
 
120
128
  assert_raise MongoArgumentError do
121
- Connection.from_uri("mongodb://localhost:abc", :connect => false)
129
+ Mongo::Connection.from_uri("mongodb://localhost:abc", :connect => false)
122
130
  end
123
131
  end
124
132
 
125
133
  should "require all of username, if password and db are specified" do
126
- assert Connection.from_uri("mongodb://kyle:jones@localhost/db", :connect => false)
134
+ assert Mongo::Connection.from_uri("mongodb://kyle:jones@localhost/db", :connect => false)
127
135
 
128
136
  assert_raise MongoArgumentError do
129
- Connection.from_uri("mongodb://kyle:password@localhost", :connect => false)
137
+ Mongo::Connection.from_uri("mongodb://kyle:password@localhost", :connect => false)
130
138
  end
131
139
  end
132
140
  end
@@ -142,79 +150,79 @@ class ConnectionTest < Test::Unit::TestCase
142
150
 
143
151
  should "parse a simple uri" do
144
152
  ENV['MONGODB_URI'] = "mongodb://localhost?connect=false"
145
- @conn = Connection.new
146
- assert_equal ['localhost', 27017], @conn.host_to_try
153
+ @connection = Mongo::Connection.new
154
+ assert_equal ['localhost', 27017], @connection.host_to_try
147
155
  end
148
156
 
149
157
  should "allow a complex host names" do
150
158
  host_name = "foo.bar-12345.org"
151
159
  ENV['MONGODB_URI'] = "mongodb://#{host_name}?connect=false"
152
- @conn = Connection.new
153
- assert_equal [host_name, 27017], @conn.host_to_try
160
+ @connection = Mongo::Connection.new
161
+ assert_equal [host_name, 27017], @connection.host_to_try
154
162
  end
155
163
 
156
164
  should "allow db without username and password" do
157
165
  host_name = "foo.bar-12345.org"
158
166
  ENV['MONGODB_URI'] = "mongodb://#{host_name}/foo?connect=false"
159
- @conn = Connection.new
160
- assert_equal [host_name, 27017], @conn.host_to_try
167
+ @connection = Mongo::Connection.new
168
+ assert_equal [host_name, 27017], @connection.host_to_try
161
169
  end
162
170
 
163
171
  should "set safe options on connection" do
164
172
  host_name = "localhost"
165
173
  opts = "safe=true&w=2&wtimeoutMS=1000&fsync=true&journal=true&connect=false"
166
174
  ENV['MONGODB_URI'] = "mongodb://#{host_name}/foo?#{opts}"
167
- @conn = Connection.new
168
- assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @conn.safe)
175
+ @connection = Mongo::Connection.new
176
+ assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @connection.safe)
169
177
  end
170
178
 
171
179
  should "set timeout options on connection" do
172
180
  host_name = "localhost"
173
181
  opts = "connectTimeoutMS=1000&socketTimeoutMS=5000&connect=false"
174
182
  ENV['MONGODB_URI'] = "mongodb://#{host_name}/foo?#{opts}"
175
- @conn = Connection.new
176
- assert_equal 1, @conn.connect_timeout
177
- assert_equal 5, @conn.op_timeout
183
+ @connection = Mongo::Connection.new
184
+ assert_equal 1, @connection.connect_timeout
185
+ assert_equal 5, @connection.op_timeout
178
186
  end
179
187
 
180
188
  should "parse a uri with a hyphen & underscore in the username or password" do
181
189
  ENV['MONGODB_URI'] = "mongodb://hyphen-user_name:p-s_s@localhost:27017/db?connect=false"
182
- @conn = Connection.new
183
- assert_equal ['localhost', 27017], @conn.host_to_try
190
+ @connection = Mongo::Connection.new
191
+ assert_equal ['localhost', 27017], @connection.host_to_try
184
192
  auth_hash = { 'db_name' => 'db', 'username' => 'hyphen-user_name', "password" => 'p-s_s' }
185
- assert_equal auth_hash, @conn.auths[0]
193
+ assert_equal auth_hash, @connection.auths[0]
186
194
  end
187
195
 
188
196
  should "attempt to connect" do
189
197
  TCPSocket.stubs(:new).returns(new_mock_socket)
190
198
  ENV['MONGODB_URI'] = "mongodb://localhost?connect=false" # connect=false ??
191
- @conn = Connection.new
199
+ @connection = Mongo::Connection.new
192
200
 
193
201
  admin_db = new_mock_db
194
202
  admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
195
- @conn.expects(:[]).with('admin').returns(admin_db)
196
- @conn.connect
203
+ @connection.expects(:[]).with('admin').returns(admin_db)
204
+ @connection.connect
197
205
  end
198
206
 
199
207
  should "raise an error on invalid uris" do
200
208
  ENV['MONGODB_URI'] = "mongo://localhost"
201
209
  assert_raise MongoArgumentError do
202
- Connection.new
210
+ Mongo::Connection.new
203
211
  end
204
212
 
205
213
  ENV['MONGODB_URI'] = "mongodb://localhost:abc"
206
214
  assert_raise MongoArgumentError do
207
- Connection.new
215
+ Mongo::Connection.new
208
216
  end
209
217
  end
210
218
 
211
219
  should "require all of username, if password and db are specified" do
212
220
  ENV['MONGODB_URI'] = "mongodb://kyle:jones@localhost/db?connect=false"
213
- assert Connection.new
221
+ assert Mongo::Connection.new
214
222
 
215
223
  ENV['MONGODB_URI'] = "mongodb://kyle:password@localhost"
216
224
  assert_raise MongoArgumentError do
217
- Connection.new
225
+ Mongo::Connection.new
218
226
  end
219
227
  end
220
228
  end
@@ -1,11 +1,11 @@
1
- require File.expand_path("../../test_helper", __FILE__)
1
+ require 'test_helper'
2
2
 
3
3
  class CursorTest < Test::Unit::TestCase
4
4
  context "Cursor options" do
5
5
  setup do
6
6
  @logger = mock()
7
7
  @logger.stubs(:debug)
8
- @connection = stub(:class => Connection, :logger => @logger,
8
+ @connection = stub(:class => MongoClient, :logger => @logger,
9
9
  :slave_ok? => false, :read_preference => :primary, :log_duration => false,
10
10
  :tag_sets => {}, :acceptable_latency => 10)
11
11
  @db = stub(:name => "testing", :slave_ok? => false,
@@ -78,23 +78,31 @@ class CursorTest < Test::Unit::TestCase
78
78
  assert_equal "name", @cursor.query_options_hash[:hint]
79
79
  end
80
80
 
81
+ should "set comment" do
82
+ assert_nil @cursor.comment
83
+
84
+ @cursor = Cursor.new(@collection, :comment => "comment")
85
+ assert_equal "comment", @cursor.comment
86
+ assert_equal "comment", @cursor.query_options_hash[:comment]
87
+ end
88
+
81
89
  should "cache full collection name" do
82
90
  assert_equal "testing.items", @cursor.full_collection_name
83
91
  end
84
-
92
+
85
93
  should "raise error when batch_size is 1" do
86
94
  e = assert_raise ArgumentError do
87
95
  @cursor.batch_size(1)
88
96
  end
89
97
  assert_equal "Invalid value for batch_size 1; must be 0 or > 1.", e.message
90
98
  end
91
-
99
+
92
100
  should "use the limit for batch size when it's smaller than the specified batch_size" do
93
101
  @cursor.limit(99)
94
102
  @cursor.batch_size(100)
95
103
  assert_equal 99, @cursor.batch_size
96
104
  end
97
-
105
+
98
106
  should "use the specified batch_size" do
99
107
  @cursor.batch_size(100)
100
108
  assert_equal 100, @cursor.batch_size
@@ -105,7 +113,7 @@ class CursorTest < Test::Unit::TestCase
105
113
  setup do
106
114
  @logger = mock()
107
115
  @logger.stubs(:debug)
108
- @connection = stub(:class => Connection, :logger => @logger, :slave_ok? => false,
116
+ @connection = stub(:class => MongoClient, :logger => @logger, :slave_ok? => false,
109
117
  :log_duration => false, :tag_sets =>{}, :acceptable_latency => 10)
110
118
  @db = stub(:slave_ok? => true, :name => "testing", :connection => @connection,
111
119
  :tag_sets => {}, :acceptable_latency => 10)
@@ -1,4 +1,4 @@
1
- require File.expand_path("../../test_helper", __FILE__)
1
+ require 'test_helper'
2
2
 
3
3
  def insert_message(db, documents)
4
4
  documents = [documents] unless documents.is_a?(Array)
@@ -13,12 +13,12 @@ class DBTest < Test::Unit::TestCase
13
13
  context "DBTest: " do
14
14
  context "DB commands" do
15
15
  setup do
16
- @conn = stub()
17
- @conn.stubs(:safe)
18
- @conn.stubs(:read_preference)
19
- @conn.stubs(:tag_sets)
20
- @conn.stubs(:acceptable_latency)
21
- @db = DB.new("testing", @conn)
16
+ @client = stub()
17
+ @client.stubs(:write_concern).returns({})
18
+ @client.stubs(:read_preference)
19
+ @client.stubs(:tag_sets)
20
+ @client.stubs(:acceptable_latency)
21
+ @db = DB.new("testing", @client)
22
22
  @db.stubs(:safe)
23
23
  @db.stubs(:read_preference)
24
24
  @db.stubs(:tag_sets)
@@ -61,7 +61,7 @@ class DBTest < Test::Unit::TestCase
61
61
 
62
62
  should "raise an error if logging out fails" do
63
63
  @db.expects(:command).returns({})
64
- @conn.expects(:pool_size).returns(1)
64
+ @client.expects(:pool_size).returns(1)
65
65
  assert_raise Mongo::MongoDBError do
66
66
  @db.logout
67
67
  end
@@ -1,15 +1,15 @@
1
- require File.expand_path("../../test_helper", __FILE__)
1
+ require 'test_helper'
2
2
 
3
3
  class GridTest < Test::Unit::TestCase
4
4
 
5
5
  context "GridFS: " do
6
6
  setup do
7
- @conn = stub()
8
- @conn.stubs(:safe)
9
- @conn.stubs(:read_preference)
10
- @conn.stubs(:tag_sets)
11
- @conn.stubs(:acceptable_latency)
12
- @db = DB.new("testing", @conn)
7
+ @client = stub()
8
+ @client.stubs(:write_concern).returns({})
9
+ @client.stubs(:read_preference)
10
+ @client.stubs(:tag_sets)
11
+ @client.stubs(:acceptable_latency)
12
+ @db = DB.new("testing", @client)
13
13
  @files = mock()
14
14
  @chunks = mock()
15
15
 
@@ -21,8 +21,8 @@ class GridTest < Test::Unit::TestCase
21
21
 
22
22
  context "Grid classe with standard connections" do
23
23
  setup do
24
- @conn.expects(:class).returns(Connection)
25
- @conn.expects(:read_primary?).returns(true)
24
+ @client.expects(:class).returns(MongoClient)
25
+ @client.expects(:read_primary?).returns(true)
26
26
  end
27
27
 
28
28
  should "create indexes for Grid" do
@@ -39,8 +39,8 @@ class GridTest < Test::Unit::TestCase
39
39
 
40
40
  context "Grid classes with slave connection" do
41
41
  setup do
42
- @conn.expects(:class).twice.returns(Connection)
43
- @conn.expects(:read_primary?).returns(false)
42
+ @client.expects(:class).twice.returns(MongoClient)
43
+ @client.expects(:read_primary?).returns(false)
44
44
  end
45
45
 
46
46
  should "not create indexes for Grid" do
@@ -1,74 +1,74 @@
1
- require File.expand_path("../../test_helper", __FILE__)
1
+ require 'test_helper'
2
2
 
3
3
  class NodeTest < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
- @connection = stub()
6
+ @client = stub()
7
7
  end
8
8
 
9
9
  should "refuse to connect to node without 'hosts' key" do
10
10
  tcp = mock()
11
- node = Node.new(@connection, ['localhost', 27017])
11
+ node = Node.new(@client, ['localhost', 27017])
12
12
  tcp.stubs(:new).returns(new_mock_socket)
13
- @connection.stubs(:socket_class).returns(tcp)
13
+ @client.stubs(:socket_class).returns(tcp)
14
14
 
15
15
  admin_db = new_mock_db
16
16
  admin_db.stubs(:command).returns({'ok' => 1, 'ismaster' => 1})
17
- @connection.stubs(:[]).with('admin').returns(admin_db)
18
- @connection.stubs(:op_timeout).returns(nil)
19
- @connection.stubs(:connect_timeout).returns(nil)
20
- @connection.expects(:log)
17
+ @client.stubs(:[]).with('admin').returns(admin_db)
18
+ @client.stubs(:op_timeout).returns(nil)
19
+ @client.stubs(:connect_timeout).returns(nil)
20
+ @client.expects(:log)
21
21
 
22
22
  assert node.connect
23
23
  node.set_config
24
24
  end
25
25
 
26
26
  should "load a node from an array" do
27
- node = Node.new(@connection, ['power.level.com', 9001])
27
+ node = Node.new(@client, ['power.level.com', 9001])
28
28
  assert_equal 'power.level.com', node.host
29
29
  assert_equal 9001, node.port
30
30
  assert_equal 'power.level.com:9001', node.address
31
31
  end
32
32
 
33
33
  should "should default the port for an array" do
34
- node = Node.new(@connection, ['power.level.com'])
34
+ node = Node.new(@client, ['power.level.com'])
35
35
  assert_equal 'power.level.com', node.host
36
- assert_equal Connection::DEFAULT_PORT, node.port
37
- assert_equal "power.level.com:#{Connection::DEFAULT_PORT}", node.address
36
+ assert_equal MongoClient::DEFAULT_PORT, node.port
37
+ assert_equal "power.level.com:#{MongoClient::DEFAULT_PORT}", node.address
38
38
  end
39
39
 
40
40
  should "load a node from a string" do
41
- node = Node.new(@connection, 'localhost:1234')
41
+ node = Node.new(@client, 'localhost:1234')
42
42
  assert_equal 'localhost', node.host
43
43
  assert_equal 1234, node.port
44
44
  assert_equal 'localhost:1234', node.address
45
45
  end
46
46
 
47
47
  should "should default the port for a string" do
48
- node = Node.new(@connection, '192.168.0.1')
48
+ node = Node.new(@client, '192.168.0.1')
49
49
  assert_equal '192.168.0.1', node.host
50
- assert_equal Connection::DEFAULT_PORT, node.port
51
- assert_equal "192.168.0.1:#{Connection::DEFAULT_PORT}", node.address
50
+ assert_equal MongoClient::DEFAULT_PORT, node.port
51
+ assert_equal "192.168.0.1:#{MongoClient::DEFAULT_PORT}", node.address
52
52
  end
53
53
 
54
54
  should "two nodes with the same address should be equal" do
55
- assert_equal Node.new(@connection, '192.168.0.1'),
56
- Node.new(@connection, ['192.168.0.1', Connection::DEFAULT_PORT])
55
+ assert_equal Node.new(@client, '192.168.0.1'),
56
+ Node.new(@client, ['192.168.0.1', MongoClient::DEFAULT_PORT])
57
57
  end
58
58
 
59
59
  should "two nodes with the same address should have the same hash" do
60
- assert_equal Node.new(@connection, '192.168.0.1').hash,
61
- Node.new(@connection, ['192.168.0.1', Connection::DEFAULT_PORT]).hash
60
+ assert_equal Node.new(@client, '192.168.0.1').hash,
61
+ Node.new(@client, ['192.168.0.1', MongoClient::DEFAULT_PORT]).hash
62
62
  end
63
63
 
64
64
  should "two nodes with different addresses should not be equal" do
65
- assert_not_equal Node.new(@connection, '192.168.0.2'),
66
- Node.new(@connection, ['192.168.0.1', Connection::DEFAULT_PORT])
65
+ assert_not_equal Node.new(@client, '192.168.0.2'),
66
+ Node.new(@client, ['192.168.0.1', MongoClient::DEFAULT_PORT])
67
67
  end
68
68
 
69
69
  should "two nodes with the same address should have the same hash negate" do
70
- assert_not_equal Node.new(@connection, '192.168.0.1').hash,
71
- Node.new(@connection, '1239.33.4.2393:29949').hash
70
+ assert_not_equal Node.new(@client, '192.168.0.1').hash,
71
+ Node.new(@client, '1239.33.4.2393:29949').hash
72
72
  end
73
73
 
74
74
  end